Skip to content

kevinmartinjos/siq

Repository files navigation

Update

Not all test cases pass now. Recent commits break the test.

ChangeLog:

If a buffered queue is full, producers are now no longer throttled. SIQ creates a new instance of the queue in memory. When flushing, messages from all full instances of a queue are sent to each consumer

SIQ

Simple Queue

A simple websocket queueing service written in javascript

To Run

  1. Clone this repo
  2. cd into the directory and do npm install. Wait till dependencies are installed
  3. npm test will run the tests
  4. npm start will run the SIQ server

Examples are in /examples directory

Buffered Queue

Queues flush messages to subscribers ONLY when queue is full. Default queue size is 5. This can be changed at serverConfig.development.json. The createQueue API provides method to create queues with custom length

Persistence

All queues and messages are persisted to a sqlite database. Messages corresponding to a queue are deleted from the db when the queue flushes.

APIs

Creating a connection

var Siq = require('../src/client/siq');

//change port as required. Siq.connect returns a javascript promise
var siqConnection = Siq.connect('ws://localhost:8888');

siqConnection.then((siq) => {
	//access siq APIs	
});

Queueing messages

var Siq = require('../src/client/siq');
var siqConnection = Siq.connect('ws://localhost:8888');
siqConnection.then((siq) => {
	var producer = siq.createProducer();
	
	producer.produce('queueName', 'message', (id) => {
		//id is a uuid generated by siq for the enqueued message
		//
	}, (error) => {
		//calls this function with an error if message could not be enqueued
		//Could happen if the queue is full
	});
	
});

Consuming messages

var Siq = require('../src/client/siq');
var siqConnection = Siq.connect('ws://localhost:8888');
siqConnection.then((siq) => {
	
	var callback = function(messageList){
		/*
			Gets invoked when queue is full
			messageList is an array of all messages that was in the queue
		*/
		
	};

	/*consumerTest is the name of the queue*/
	var consumerConnection = siq.createConsumer('consumerTest', callback);
	
});

Creating a queue

If you want to create a queue with a buffer size different from that of the default one, use the createQueue API

var Siq = require('../src/client/siq');
var siqConnection = Siq.connect('ws://localhost:8888');
siqConnection.then((siq) => {
	var bufferSize = 20;
	siq.createQueue('customQueue', bufferSize, (name) => {
		/*
			If queue creation was successfull, name will contain the name of the queue. In this case, 'customQueue'
		*/
	});
});


About

Simple queue broker written in javascript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published