shimo-rocketmq
Aliyun Open Notification Service Client
Last updated 3 years ago by luoyjx .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install shimo-rocketmq 
SYNC missed versions from official npm registry.

shimo-rocketmq

NPM version build status David deps node version

Aliyun Open Notification Service Client (base on opensource project RocketMQ)

Sub module of ali-sdk.

Install

npm install shimo-rocketmq --save

Usage

consumer

'use strict';

const httpclient = require('urllib');
const Consumer = require('ali-ons').Consumer;
const consumer = new Consumer({
  httpclient,
  accessKey: 'your-accesskey',
  secretKey: 'your-secretkey',
  consumerGroup: 'your-consumer-group',
  // isBroadcast: true,
});

consumer.subscribe(config.topic, '*', function*(msg) {
  console.log(`receive message, msgId: ${msg.msgId}, body: ${msg.body.toString()}`)
});

consumer.on('error', err => console.log(err));

producer

'use strict';

const co = require('co');
const httpclient = require('urllib');
const Producer = require('ali-ons').Producer;
const Message = require('ali-ons').Message;

const producer = new Producer({
  httpclient,
  accessKey: 'your-accesskey',
  secretKey: 'your-secretkey',
  producerGroup: 'your-producer-group',
});

producer.ready(() => {
  console.log('producer ready');
  const msg = new Message('your-topic', // topic
    'TagA', // tag
    'Hello ONS !!! ' // body
  );

  // Might be an order id or other key you want
  const shardingKey = 'your sharding key goes here'

  co(function *() {
    // Send normal message, message will delivery averagely into topic queues
    let sendResult = yield * producer.send(msg);

    // Send sharding message
    // Messages will be delivered into queues which depends on sharding key,
    // that means the messages with same sharding key will always be deliveried
    // into same queue, but you should handle the situation when consumers scaling yourself. 
    sendResult = yield * producer.send(msg, shardingKey);
  });
});

Rocketmq

implemention from yeliex/rocketmq

consumer

const consumer = new Consumer({
  namesrvAddr: 'localhost:9876', // for rocket mq
  accessKey: 'your-accesskey',  // for aliyun-ons
  secretKey: 'your-secretkey',  // for aliyun-ons
  onsAddr: '',                   // for aliyun-ons
  consumerGroup: 'your-consumer-group',  // for aliyun-ons
  
  isBroadcast: false, // default is false, that mean messages will be pushed to consumer cluster only once.
});

producer

const producer = new Producer({
  namesrvAddr: 'localhost:9876', // for rocket mq
  accessKey: 'your-accesskey',   // for aliyun-ons
  secretKey: 'your-secretkey',    // for aliyun-ons
  producerGroup: 'your-producer-group',  // for aliyun-ons
});

License

MIT

Current Tags

  • 2.3.2                                ...           latest (3 years ago)

4 Versions

  • 2.3.2                                ...           3 years ago
  • 2.3.1                                ...           3 years ago
  • 2.3.0                                ...           3 years ago
  • 2.2.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 2
Last Month 5
Dependencies (19)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |