Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

cw-rabbitmq

3.2.1 • Public • Published

rabbitmq 组件

NPM version build status Test coverage David deps Known Vulnerabilities npm download

消息队列组件,推荐Node版本 8LTS 以上

安装

npm install --save cw-rabbitmq

使用方法

const connConfig = {
  host: '',
  port: 5672,
  login: '',
  password: '',
  vhost: '',
  reconnect: true,
  reconnectBackoffTime: 10000, // 10秒尝试连接一次
};
const options = {
  exchangeName: 'exTest',
  exchangeOption: {
    // ke选
    type: 'direct',
    autoDelete: false,
    confirm: true,
  },
  queueName: 'test',
  queueOption: {
    // 可选
    durable: true,
    autoDelete: false,
  },
};
 
const mq = new MQ(connConfig, options);
 
mq.publishMsg('heartbeat-test')
  .then(result => {
    console.info(`MQ心跳监测正常,result:${result}`);
  })
  .catch(err => {
    console.info(`MQ心跳监测异常${err.toString()}`);
  });
 
mq.subscribeAsync().then(result => {
  result.ack.acknowledge(true);
});
 
mq.subscribe((message, headers, deliveryInfo, ack) => {
  ack.acknowledge(true);
});

Keywords

Install

npm i cw-rabbitmq

DownloadsWeekly Downloads

2

Version

3.2.1

License

MIT

Unpacked Size

176 kB

Total Files

17

Last publish

Collaborators

  • avatar