-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.js
More file actions
35 lines (31 loc) · 760 Bytes
/
Copy pathexample.js
File metadata and controls
35 lines (31 loc) · 760 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
const hydra = require('hydra');
const HydraRPC = require('./src/index.js');
const Promise = require('bluebird');
hydra.use(new HydraRPC());
hydra.init({
hydra: {
serviceName: 'hydra-plugin-rpc-example',
serviceIP: '',
servicePort: 0,
serviceType: 'router',
serviceDescription: 'example for hydra-plugin-rpc plulgin',
redis: {
host: 'localhost',
db: 15
},
plugins: {
'hydra-plugin-rpc': {}
}
}
}).then(() => {
console.log('Hydra Inialized');
hydra.methods({
ping: (...args) => Promise.resolve('pong ' + hydra.getInstanceID()).delay(200)
});
});
setInterval(() => {
const start = Date.now();
hydra.call('ping')
.then(result => console.log({result, time: Date.now() - start}))
.catch(err => console.log(err));
}, 2000);