-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathproducer.js
52 lines (43 loc) · 1.2 KB
/
producer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* XadillaX created at 2015-12-19 23:37:40 With ♥
*
* Copyright (c) 2017 Souche.com, all rights
* reserved.
*/
"use strict";
var Scarlet = require("scarlet-task");
var config = require("../test/_config");
var Producer = require("../lib/producer");
var producer = new Producer(
config.producerId,
config.accessKey,
config.secretKey, {
onsAddr: "http://onsaddr-internet.aliyun.com:80/rocketmq/nsaddr4client-internet"
});
function send() {
var scarlet = new Scarlet(10);
function p(taskObject) {
var i = taskObject.task.i;
producer.send(config.topic, "tagA", "Hello " + i + "!", 1000, function(err, messageId) {
console.log(err, messageId);
taskObject.done();
});
producer.send(config.topic, "tagA", "单向 " + i);
}
for(var i = 0; i < 10; i++) {
scarlet.push({ i: i }, p);
}
scarlet.afterFinish(10, function() {
setTimeout(send, 100);
}, false);
}
console.log("Connecting to Aliyun ONS...");
producer.start(function() {
console.log("Started.");
setTimeout(send, 100);
});
process.on("SIGINT", function() {
producer.stop(function() {
process.exit(0);
});
});