Skip to content

schahriar/pubmq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PubMQ

PubMQ is a lightweight message queue and pub/sub library that uses a custom protocol implemented as a small layer on top of the UDP protocol. It is idea for real-time communication where asynchronous messages are broadcasted within channels.

Note that PubMQ is connectionless and unreliable (UDP) by design and thus ideal for time critical applications.


Build Status Test Coverage

Installation

Client:

npm install --save pubmq

Server:

Install PubMQ package globally:

npm install -g pubmq

Install PubMQ server on port 14850:

pubmq install -p=14850

Create startup script to launch PubMQ on restart: (Checkout PM2 startup script for more info)

pubmq startup <distribution>

Usage

Subscriber

const PubMQClient = require("pubmq").Client;
let client = new PubMQClient();

// Connect to a PubMQ Server
client.connect("localhost:14850", (error) => {
  if (error) throw error;
  
  // Subscribe to the test channel (channels are automatically created)
  client.subscribe("test");
  
  // Listen for messages (note the semi-colon prefix)
  client.on(":test", (message) => {
    // Message is a buffer, convert to string
    let strMessage = message.toString("utf8");
    console.log(strMessage);
  });
});

// Output after pub: Hello World

Publisher

const PubMQClient = require("pubmq").Client;
let client = new PubMQClient();

// Connect to a PubMQ Server
client.connect("localhost:14850", (error) => {
  if (error) throw error;
  
  // Publish a message to test channel
  client.publish("test", "Hello World");
});

Features & Limitations

Features

  • Lightweight code and protocol
  • Pub/Sub
  • Unsub
  • Message Queue
  • TTL for Messages
  • Direct messaging (upcoming)

Limitations

  • Message size is limited to max UDP packet size (about 64kb)
  • Messages are only stored in memory (since messages are short lived this shouldn't be an issue)
  • Deliveries aren't guaranteed
  • No congestion avoidance/control (planned fix)

License

MIT

Releases

No releases published

Packages

No packages published