RpcServer

RpcServer

RPC server. Init example:

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

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

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

    // An event gets emitted on each call.
    // Handling of the pCorrelationId is optional and should be done only if you expect a single RPC server instance
    // to handle multiple RPC clients.
    // For example if the RPC server interacts with a DB on the behalf of the client and the calls are just
    // coming in.
    // This means that you can parameters pCorrelationId in both receiving the call and responding.
    rpcServer.getEventer().on('call', (callData, pCorrelationId) => {
      console.log('RPC server got a call: ' + callData);

      // ...

      let isServerResponding = rpcServer.respond({
        'a': 3
      }, pCorrelationId);
    });

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

    // ...

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

...

Constructor

new RpcServer(amqpUri, channelName, configurationopt)

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

Methods

respond(contentToPublish, correlationId) → {boolean}

Respond to the last call/message.

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

correlation ID (as gotten from the call) parameter to use when the server is to process multiple calls at once

Returns:
Type:
boolean