-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathMQService.js
More file actions
37 lines (33 loc) · 1.03 KB
/
MQService.js
File metadata and controls
37 lines (33 loc) · 1.03 KB
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
const Broker = require('rascal').BrokerAsPromised;
const config = require("./MQConfig").config;
const HttpError = require("../utils/HttpError");
const log = require("loglevel");
class MQService{
constructor(session){
this._settsion = session;
}
sendMessage(payload){
return new Promise((resolve, reject) => {
const broker = Broker.create(config);
// TODO
Promise.resolve(broker)
.then(broker => {
broker.publish("raw-capture-created", payload, "field-data.capture.creation")
.then(publication => {
publication
.on("success", () => resolve(true))
.on("error", (err, messageId)=> {
const error = `Error with id ${messageId} ${err.message}`;
log.error(error);
reject(new HttpError(500, error));
});
})
.catch(err => {
log.error(err);
reject(new HttpError(500, `Error publishing message ${err}`));
})
});
});
}
}
module.exports = MQService;