Introduction to BusMQ
BusMQ is a high-performance message queue implemented in Node.js. It allows for reliable and scalable communication between various parts of an application, or even different applications. By using BusMQ, developers can ensure that messages are delivered in a timely and efficient manner.
Creating a Queue
const busmq = require('busmq');
const bus = busmq.create();
bus.on('online', () => {
const queue = bus.queue('my-queue');
queue.on('attached', () => {
console.log('Queue attached and ready to use.');
});
queue.attach();
});
bus.connect();
Sending a Message to a Queue
const queue = bus.queue('my-queue');
queue.on('attached', () => {
queue.push('Hello, BusMQ!');
console.log('Message sent.');
});
queue.attach();
Receiving Messages from a Queue
const queue = bus.queue('my-queue');
queue.on('attached', () => {
queue.on('message', (msg) => {
console.log('Received message: ' + msg);
});
});
queue.attach();
Deleting a Queue
const queue = bus.queue('my-queue');
queue.on('attached', () => {
queue.del(() => {
console.log('Queue deleted.');
});
});
queue.attach();
Implementing BusMQ in an Application
Server
const express = require('express');
const busmq = require('busmq');
const app = express();
const bus = busmq.create();
bus.on('online', () => {
const queue = bus.queue('my-queue');
queue.on('attached', () => {
app.post('/send-message', (req, res) => {
queue.push(req.body.message);
res.send('Message sent.');
});
});
queue.attach();
});
bus.connect();
app.listen(3000, () => {
console.log('Server is listening on port 3000.');
});
Client
BusMQ Client
Hash: 2b2ae00a8dbc7e19e6cd594d6064455f50ae59ae55210cd01aa1a1df68521487