-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathoffset_tracking_send.js
More file actions
36 lines (30 loc) · 1018 Bytes
/
offset_tracking_send.js
File metadata and controls
36 lines (30 loc) · 1018 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
36
const rabbit = require("rabbitmq-stream-js-client");
async function main() {
console.log("Connecting...");
const client = await rabbit.connect({
vhost: "/",
port: 5552,
hostname: "localhost",
username: "guest",
password: "guest",
});
console.log("Making sure the stream exists...");
const streamName = "stream-offset-tracking-javascript";
await client.createStream({ stream: streamName, arguments: {} });
console.log("Creating the publisher...");
const publisher = await client.declarePublisher({ stream: streamName });
const messageCount = 100;
console.log(`Publishing ${messageCount} messages`);
for (let i = 0; i < messageCount; i++) {
const body = i === messageCount - 1 ? "marker" : `hello ${i}`;
await publisher.send(Buffer.from(body));
}
console.log("Closing the connection...");
await client.close();
}
main()
.then(() => console.log("done!"))
.catch((res) => {
console.log("Error in publishing message!", res);
process.exit(-1);
});