-
-
Notifications
You must be signed in to change notification settings - Fork 588
/
Copy pathissue-1100-receiver.js
54 lines (48 loc) · 1.17 KB
/
issue-1100-receiver.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use strict";
const ServiceBroker = require("../src/service-broker");
const TransitLogger = require("../src/middlewares/debugging/transit-logger");
const TransmitCompression = require("../src/middlewares/transmit/compression");
const Stream = require("stream");
const broker = new ServiceBroker({
nodeID: "receiver",
transporter: "NATS",
serializer: "JSON",
requestTimeout: 10 * 1000,
middlewares: [
TransmitCompression({ method: "gzip" })
/*TransitLogger({
folder: "logs/transit"
})*/
]
});
broker.createService({
name: "receiver",
/**
* Actions
*/
actions: {
receive: {
async handler(ctx) {
// ! called two times if meta is "large"
this.logger.info("call receive handler", ctx.params, ctx.meta);
if (ctx.params) {
const participants = [];
ctx.params.on("data", d => participants.push(d));
ctx.params.on("end", () =>
this.logger.info(
"received stream data",
participants.length,
ctx.meta,
participants
)
);
return "OK";
} else {
this.logger.error("No stream", ctx.params, ctx.meta);
return "no stream";
}
}
}
}
});
broker.start().then(() => broker.repl());