-
Notifications
You must be signed in to change notification settings - Fork 0
/
hmr-service.js
39 lines (35 loc) · 1.03 KB
/
hmr-service.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
/**
* @name hmr-service
* @summary Message Relay Service
* @description Hydra Message Relay - a simple microservice which replies to WebSocket messages received via Hydra-router.
*/
'use strict';
const hydra = require('hydra');
let config = hydra.getConfigHelper();
/**
* Load configuration file and initialize hydraExpress app
*/
let main = async () => {
try
{
await config.init('./config/config.json');
let newConfig = await hydra.init(config.getObject(), false);
config = newConfig;
let serviceInfo = await hydra.registerService();
let logEntry = `Started ${hydra.getServiceName()} (v.${hydra.getInstanceVersion()})`;
console.log(logEntry);
console.log(serviceInfo);
hydra.on('message', (message) => {
hydra.sendReplyMessage(message, {
bdy: {
message: `Message reply to mid (${message.mid}) by ${config.hydra.serviceName} instance ${hydra.getInstanceID()}`
}
});
});
} catch (e) {
console.log('err', err);
hydra.shutdown();
process.exit(-1);
}
}
main();