tmqp-client
An open source npm package of a client to make connections to TurtleMQ server for Node.js.
Features
Turtle Message Queue Protocol (TMQP) is based on TCP (Transimssion Control Protocol) which is a communication protocol of the transport level in OSI tower.
Supports produce messages
Supprots consume messages
Supports delete queue
Supports cluster mode
Quick Start
Install
npm install tmqp-client
Basic Usage
Producer
const Tmqp = require('tmqp-client');
(async () => {
const tmqp = new Tmqp({ host: 'localhost', port: 5566 });
const queue = 'my-queue';
await tmqp.produce(queue, 'message')
})();
The default queue size is 1000. You can pass the configuration to the command.
await tmqp.produce(queue, 'message', { maxLength: 2000 })
Consumer
const Tmqp = require('tmqp-client');
(async () => {
const tmqp = new Tmqp({ host: 'localhost', port: 5566 });
const queue = 'my-queue'
const messages = await tmqp.consume(queue, 1);
console.log(messages);
})();
Delete queue
await tmqp.delete('my-queue');
Cluster
Create connection to Turtle Finder to get the TurtleMQ master server configuration.
// Connect to the Turtle Finder server
const tmqp = new Tmqp({ host: 'localhost', port: 25566, cluster: true });
Connection
If you choose to use cluster mode, you have to start a Turtle Finder server first.
The cluster mode will ask for master IP and port from the Turtle Finder, and directly connect to the TurtleMQ master server.
When the TurtleMQ master server crushed or lost connection, the tmqp-client will automatically ask the Turtle Finder again for the new master IP and reconnect to the TurtleMQ server.
Contact
Thank you for using tmqp-client :-)
Email: c.kelvin.wu@gmail.com