1 | const mq = require('./RabbitMessageCenter'),
|
2 | __ = require('underscore');
|
3 |
|
4 | const startup = (config) => {
|
5 | return mq.start(config)
|
6 | .then(() => {
|
7 | __.each(config.exchanges, (ex, exName) => {
|
8 | if (ex.publishes && ex.publishes.length > 0) {
|
9 | let exPublishes = {}
|
10 | ex.publishes.forEach((p) => {
|
11 | exPublishes[p] = (msg) => {
|
12 | return mq.publish(exName, p, msg)
|
13 | }
|
14 | })
|
15 | if (ex.isDefault) {
|
16 | Object.assign(MC, exPublishes)
|
17 | } else {
|
18 | MC[ex] = exPublishes
|
19 | }
|
20 | }
|
21 | })
|
22 | })
|
23 | }
|
24 |
|
25 | const MC = {
|
26 | start: startup,
|
27 | }
|
28 |
|
29 | module.exports = MC |
\ | No newline at end of file |