-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (35 loc) · 1.02 KB
/
index.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
/**
* Created by maple on 2017/6/13.
*/
"use strict";
const ONS = require("ons");
const Consumer = ONS.Consumer;
const Producer = ONS.Producer;
exports.create = function(config) {
const consumerId = config.consumerId;
const producerId = config.producerId;
const topic = config.topic;
const tags = config.tags;
const accessKey = config.accessKey;
const secretKey = config.secretKey;
const options = config.options;
const ons = {};
const consumer = ons.consumer = new Consumer(consumerId, topic, tags, accessKey, secretKey, options);
const producer = ons.producer = new Producer(producerId, accessKey, secretKey, options);
ons.logger = ONS.logger;
if(!config.notStartConsumer) {
consumer.init(function(err) {
if(err) {
console.error(err);
}
});
}
if(!config.notStartProducer) {
producer.start(function(err) {
if(err) {
console.error(err);
}
});
}
return ons;
};