-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathreceive.js
33 lines (27 loc) · 973 Bytes
/
receive.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
const rabbit = require("rabbitmq-stream-js-client")
async function main() {
const streamName = "hello-nodejs-stream"
console.log("Connecting...");
const client = await rabbit.connect({
hostname: "localhost",
port: 5552,
username: "guest",
password: "guest",
vhost: "/",
})
console.log("Making sure the stream exists...");
const streamSizeRetention = 5 * 1e9
await client.createStream({ stream: streamName, arguments: { "max-length-bytes": streamSizeRetention } });
console.log("Declaring the consumer with offset...");
await client.declareConsumer({ stream: streamName, offset: rabbit.Offset.first() }, (message) => {
console.log(`Received message ${message.content.toString()}`)
})
}
main()
.then(async () => {
await new Promise(function () { })
})
.catch((res) => {
console.log("Error while receiving message!", res)
process.exit(-1)
})