rabbitmq-tutorials/javascript-nodejs-stream/send.js
icappello bfe6dd09fd
Hello World for nodejs stream client (#403)
* add: simple publish/receive examples for the nodejs stream client
2024-05-09 07:23:05 +02:00

35 lines
995 B
JavaScript

const rabbit = require("rabbitmq-stream-js-client");
async function main() {
const streamName = "hello-nodejs-stream";
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 streamSizeRetention = 5 * 1e9
await client.createStream({ stream: streamName, arguments: { "max-length-bytes": streamSizeRetention } });
console.log("Creating the publisher...");
const publisher = await client.declarePublisher({ stream: streamName });
console.log("Sending a message...");
await publisher.send(Buffer.from("Test message"));
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);
});