Skip to content

A higher-level RabbitMQ library for making asynchronous RPC calls.

Notifications You must be signed in to change notification settings

paveldz/rabbitmq-rpcbus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rabbitmq-rpcbus

A higher-level node.js library for RPC over RabbitMQ.

Examples

Server (endpoints configuration):

const connStr = "amqp://localhost";
const exchangeName = "AsyncMessagingConsole_Rpc";
const rpcServerQueueName = "AsyncMessagingConsole_RpcQueue";

const bus = await Bus.create(connStr, exchangeName, rpcConfig => {
    rpcConfig.rpcServerQueueName = rpcServerQueueName;

    rpcConfig.setupRpcEndpoint("service/sayHello", command => {
        console.log(`Received message: ${JSON.stringify(command)}`);
        return { response: "Hi! Nice to see you!" };
    });

    rpcConfig.setupRpcEndpoint("service/sayBye", command => {
        console.log(`Received message: ${JSON.stringify(command)}`);
        return { response: "Bye! See you later!" };
    });
});

Client:

const connStr = "amqp://localhost";
const exchangeName = "AsyncMessagingConsole_Rpc";

const bus = await Bus.create(connStr, exchangeName);

let response0 = await bus.rpcClient.sendCommand("service/sayHello", { message: "Hello! (the first time)" });
console.log(`Received response: ${JSON.stringify(response0)}\n`);

let response1 = await bus.rpcClient.sendCommand("service/sayHello", { message: "Hi! (the second time)" });
console.log(`Received response: ${JSON.stringify(response1)}\n`);

let response2 = await bus.rpcClient.sendCommand("service/sayBye", { message: "Bye!" });
console.log(`Received response: ${JSON.stringify(response2)}\n`);

About

A higher-level RabbitMQ library for making asynchronous RPC calls.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published