msqe
v1.0.3
Published
MSQE (Message Queue Events) – A lightweight, real-time message queue and pub/sub system built with WebSocket and Node.js.
Downloads
20
Maintainers
Readme
MSQE – Message Queue Events
MSQE (Message Queue Events) is a lightweight, real-time WebSocket-based message queue and pub/sub system for Node.js and TypeScript.
It supports multi-topic publishing, replay, subscriber acknowledgment, and secure admin API.
Developed by: Sayyed Mohammad Adil
Table of Contents
Features
| Feature | Description |
|---------|-------------|
| Multi-topic Publish | Publish messages to multiple topics simultaneously |
| Subscriber Acknowledgment | Reliable message delivery with ack & retry |
| Replay Messages | Request replay of past messages from timestamp |
| Admin API | Monitor status and replay messages securely |
| JWT Auth | Secure Admin API with user authentication |
| Logging | Logs all events, retries, and ack failures |
| TypeScript Support | Fully typed and modular |
Installation
Install MSQE from NPM
npm install msqe
Or using yarn
yarn add msqe
Quick Start Settings
import { Settings } from "msqe";
Settings.configure({
topicRetention: {
orderCreated: 7*24*60*60*1000,
paymentReceived: 7*24*60*60*1000,
shipmentDispatched: 7*24*60*60*1000
},
retryLimit: 5,
ackTimeout: 5000,
logDir: "./logs",
authUsers: { admin: "1234" },
jwtSecret: "your-secret-key"
});
CommonJS version:
const { Settings } = require("msqe");
Settings.configure({
topicRetention: {
orderCreated: 7*24*60*60*1000,
paymentReceived: 7*24*60*60*1000,
shipmentDispatched: 7*24*60*60*1000
},
retryLimit: 5,
ackTimeout: 5000,
logDir: "./logs",
authUsers: { admin: "1234" },
jwtSecret: "your-secret-key"
});
Publisher
import { Publisher } from "msqe";
const pub = new Publisher({ port: 9090 });
pub.publish("orderCreated", { orderId: 101, customer: "Alice" });
// Get status
console.log(pub.getStatus());
CommonJS version:
const { Publisher } = require("msqe");
const pub = new Publisher({ port: 9090 });
pub.publish("orderCreated", { orderId: 101, customer: "Alice" });
console.log(pub.getStatus());
Subscriber
import { Subscriber } from "msqe";
const sub1 = new Subscriber({ url: "ws://localhost:9090", events: ["orderCreated"] });
sub1.on("orderCreated", data => console.log("[Sub1] Order Created:", data));
// Request replay of last 1 hour
sub1.requestReplay({ fromTimestamp: Date.now() - 1000*60*60 });
CommonJS version:
const { Subscriber } = require("msqe");
const sub1 = new Subscriber({ url: "ws://localhost:9090", events: ["orderCreated"] });
sub1.on("orderCreated", data => console.log("[Sub1] Order Created:", data));
sub1.requestReplay({ fromTimestamp: Date.now() - 1000*60*60 });Admin API
import { startAdminApiServer } from "msqe";
// Starts admin API server on port 8081
startAdminApiServer(pub, 8081);
Endpoints:
GET /status – Returns current publisher status
GET /replay – Replay messages with optional filters: topic, from, ack
Authentication: Use authUsers + jwtSecret for secure access.
Full Example
import { Settings, Publisher, Subscriber, startAdminApiServer } from "msqe";
Settings.configure({
topicRetention: {
orderCreated: 7*24*60*60*1000,
paymentReceived: 7*24*60*60*1000,
shipmentDispatched: 7*24*60*60*1000
},
retryLimit: 5,
ackTimeout: 5000,
logDir: "./logs",
authUsers: { admin: "1234" },
jwtSecret: "your-secret-key"
});
const pub = new Publisher({ port: 9090 });
startAdminApiServer(pub, 8081);
const sub1 = new Subscriber({ url: "ws://localhost:9090", events: ["orderCreated", "paymentReceived"] });
sub1.on("orderCreated", data => console.log("[Sub1] Order Created:", data));
sub1.on("paymentReceived", data => console.log("[Sub1] Payment Received:", data));
const sub2 = new Subscriber({ url: "ws://localhost:9090", events: ["orderCreated", "shipmentDispatched"] });
sub2.on("orderCreated", data => console.log("[Sub2] Order Created:", data));
sub2.on("shipmentDispatched", data => console.log("[Sub2] Shipment Dispatched:", data));
setTimeout(() => {
pub.publish("orderCreated", { orderId: 101, customer: "Alice" });
pub.publish("paymentReceived", { orderId: 101, amount: 250 });
pub.publish("shipmentDispatched", { orderId: 101, carrier: "DHL" });
}, 1000);
setTimeout(() => {
sub1.requestReplay({ fromTimestamp: Date.now() - 1000*60*60 });
sub2.requestReplay({ fromTimestamp: Date.now() - 1000*60*60 });
}, 2000);
CommonJS version:
const { Settings, Publisher, Subscriber, startAdminApiServer } = require("msqe");
Settings.configure({
topicRetention: {
orderCreated: 7*24*60*60*1000,
paymentReceived: 7*24*60*60*1000,
shipmentDispatched: 7*24*60*60*1000
},
retryLimit: 5,
ackTimeout: 5000,
logDir: "./logs",
authUsers: { admin: "1234" },
jwtSecret: "your-secret-key"
});
const pub = new Publisher({ port: 9090 });
startAdminApiServer(pub, 8081);
const sub1 = new Subscriber({ url: "ws://localhost:9090", events: ["orderCreated", "paymentReceived"] });
sub1.on("orderCreated", data => console.log("[Sub1] Order Created:", data));
sub1.on("paymentReceived", data => console.log("[Sub1] Payment Received:", data));
const sub2 = new Subscriber({ url: "ws://localhost:9090", events: ["orderCreated", "shipmentDispatched"] });
sub2.on("orderCreated", data => console.log("[Sub2] Order Created:", data));
sub2.on("shipmentDispatched", data => console.log("[Sub2] Shipment Dispatched:", data));
setTimeout(() => {
pub.publish("orderCreated", { orderId: 101, customer: "Alice" });
pub.publish("paymentReceived", { orderId: 101, amount: 250 });
pub.publish("shipmentDispatched", { orderId: 101, carrier: "DHL" });
}, 1000);
setTimeout(() => {
sub1.requestReplay({ fromTimestamp: Date.now() - 1000*60*60 });
sub2.requestReplay({ fromTimestamp: Date.now() - 1000*60*60 });
}, 2000);
Contributing Developed by Sayyed Mohammad Adil. Feel free to submit issues or pull requests on GitHub.
