mirror of
https://github.com/spacebarchat/spacebarchat.git
synced 2024-11-22 10:22:32 +01:00
30 lines
631 B
JavaScript
30 lines
631 B
JavaScript
var amqp = require("amqplib");
|
|
var queue = "hellotes53";
|
|
var send_at;
|
|
|
|
async function main() {
|
|
const conn = await amqp.connect("amqp://localhost");
|
|
const recv_ch = await conn.createChannel();
|
|
await recv_ch.assertQueue(queue);
|
|
|
|
recv_ch.consume(
|
|
queue,
|
|
function (msg) {
|
|
if (msg !== null) {
|
|
console.log(`received ${msg.content.toString()} with latency of ${Date.now() - send_at}ms`);
|
|
}
|
|
},
|
|
{ noAck: true }
|
|
);
|
|
|
|
const send_ch = await conn.createChannel();
|
|
// await send_ch.assertQueue(queue);
|
|
|
|
setInterval(() => {
|
|
send_at = Date.now();
|
|
send_ch.sendToQueue(queue, Buffer.from("hello"));
|
|
}, 100);
|
|
}
|
|
|
|
main();
|