@wbenxin/amqplib-rpc

1.1.0 • Public • Published

amqplib-rpc

基于amqplib实现的RPC服务. 具有以下特点:

  • 基于replyTocorrelationId机制
  • 服务端断线自动重连
  • 客户端调用支持超时
  • RabbitMQ

安装

npm i @wbenxin/amqplib-rpc

使用

Server

const {Server} = require('@wbenxin/amqplib-rpc');

const server = new Server(config);
server.on('calc', async (a, b)=>{
  return a+b;
});

config的内容如下:

{
  url: 'string'
}

Client

const {Client} = require('@wbenxin/amqplib-rpc');

const client = new Client(config);
client.call('calc', [1,2]).then(sum => {
  console.log(sum);
}).catch(e => {
  console.error(e);
});

config的内容如下:

{
  url: 'string',
  timeout: int,   // 可选. 默认30秒
}

Package Sidebar

Install

npm i @wbenxin/amqplib-rpc

Weekly Downloads

1

Version

1.1.0

License

ISC

Unpacked Size

7.83 kB

Total Files

9

Last publish

Collaborators

  • wbenxin