Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including rocketmq with all npm packages installed. Try it out:

var rocketmq = require("rocketmq")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

rocketmq v2.0.1

Rocket MQ SDK support Aliyun Open Notification Service Client

rocketmq

NPM version build status David deps node version

Rocket MQ SDK support Aliyun Open Notification Service Client (base on opensource project RocketMQ)

Forked from ali-ons

Install

npm install rocketmq --save

Usage

consumer

'use strict';

const Consumer = require('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.
});

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 Producer = require('rocketmq').Producer;
const Message = require('rocketmq').Message;

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
});

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

  producer.send(msg, (err, sendResult) => console.log(err, sendResult));
});

License

MIT

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free