Skip to content

Getting Started

eric edited this page Jun 12, 2026 · 1 revision

Getting Started

Install

npm install tyo-mq

Requires Node.js. The browser client ships pre-bundled (see Browser Client).

Run a server

The quickest way — the packaged entry point:

npm start            # from a clone of the repo; listens on port 17352

Or embed it in your own process:

const Server = require('tyo-mq').Server;

const server = new Server({
    // any socket.io options are accepted here too
});
server.start();          // default port 17352
// server.start(9000);   // or pick a port

Everything beyond plain pub/sub (auth, persistence, clustering, the HTTP API) is off by default and enabled through options or a settings file — see Server Configuration.

Create a producer

const Factory = require('tyo-mq').Factory;

const mq = new Factory({ host: 'localhost', port: 17352, protocol: 'http' });

const producer = await mq.createProducer('weather-station');
producer.produce('temperature', { celsius: 21.5 });

produce(event, data) is fire-and-forget by default. Options for TTL, guaranteed delivery, and broadcast are covered in Producers.

Create a consumer

const consumer = await mq.createConsumer('dashboard');

consumer.subscribe('weather-station', 'temperature', (data, from) => {
    console.log('from', from, ':', data);
});

Subscriptions survive reconnects automatically: if either side drops and comes back, the subscription is re-established and both sides are notified of each other's online state.

Consumer names must be unique per realm — a second live connection registering the same consumer name is rejected (it almost always means two instances share one app_id).

Both roles in one client

A single process can be producer and consumer at once:

const worker = await mq.createProducer('worker-1');
const feed = await mq.createConsumer('worker-1-feed');

Large messages

Messages bigger than 256 KB are automatically split into ordered chunks and reassembled on the receiving side — multi-megabyte payloads work without any configuration (the server defaults to a 50 MB socket.io frame ceiling).

Next steps

Clone this wiki locally