-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
40 lines (31 loc) · 976 Bytes
/
app.js
File metadata and controls
40 lines (31 loc) · 976 Bytes
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
'use strict';
const Amqplib = require('./lib/amqplib');
const assert = require('assert');
module.exports = app => {
app.addSingleton('amqplib', createClient);
};
function createClient(config, app) {
assert(
config.url || config.options,
'[egg-amqplib-plugin] url or options configuration is required'
);
const client = new Amqplib(config);
client.on('connect', () => {
app.coreLogger.info('[egg-amqplib-plugin] client connect success');
});
client.on('error', err => {
app.coreLogger.info('[egg-amqplib-plugin] client error: %s', err);
app.coreLogger.error(err);
});
client.on('close', err => {
app.coreLogger.info('[egg-amqplib-plugin] client close: %s', err);
});
client.on('ch_open', () => {
app.coreLogger.info('[egg-amqplib-plugin] channel opened.');
});
app.beforeStart(async () => {
app.coreLogger.info('[egg-amqplib-plugin] status OK, client ready');
await client.init();
});
return client;
}