RpcClient

RpcClient

RPC client. Init example:

    const iamqp              = require('iamqp');
    const amqpUri            = 'amqp://localhost';
    const rpcChannel         = 'rpc-channel-a';
    let rpcClient            = new iamqp.RPCClient(amqpUri, rpcChannel);

    // This needs to be done or the errors will bubble up.
    rpcClient.getEventer().on('error', (err) => {
      console.log('RPC client error:' + err.message);
    });

    // For when the connection is established.
    rpcClient.getEventer().on('connected', () => {
      console.log('RPC client connected');
    });

    rpcClient.getEventer().on('reply', (reply, correlationId) => {
      console.log('RPC client got a reply (' + correlationId + '): ' + reply);
    });

    // Open the connection - this takes some time and is not sync
    rpcClient.openConnection();

    // ...

    // Call the RPC server with some data.
    // The correlation ID strings are to be used to distinguish replies to answers.
    let correlationIdA = rpcClient.callRemote({'a': 5});
    let correlationIdB = rpcClient.callRemote({'b': 5});
    if (correlationIdA === false) {
      console.log('call not performed on A');
    } else {
      console.log('correlationID on A: ' + correlationIdA);
    }

    if (correlationIdB === false) {
      console.log('call not performed on B');
    } else {
      console.log('correlationID on B: ' + correlationIdB);
    }

    // ...

    // Close the connection
    if (rpcClient.closeConnection()) {
      console.log('RPC client connection closing ...');
    }

...

Constructor

new RpcClient(amqpUri, channelName, configurationopt)

Source:
Parameters:
Name Type Attributes Description
amqpUri AmqpURI
channelName ChannelName
configuration Configuration <optional>

Methods

callRemote(contentToPublish) → {boolean|string}

Perform the "server" call with some data.

Source:
Parameters:
Name Type Description
contentToPublish number | string | boolean | Object | Array
Returns:
Type:
boolean | string

the correlation ID of the call. The user can use this as to distinguish between multiple answers. If something went wrong, false will be returned.