Skip to content

Producers

eric edited this page Jun 12, 2026 · 1 revision

Producers

A producer is a named publisher. Create one through the Factory:

const producer = await mq.createProducer('weather-station');

// optional: a default event name and per-producer default TTL
const producer2 = await mq.createProducer('tasks', { default_ttl: 3600 });

Producing

producer.produce('temperature', { celsius: 21.5 });

// with options
producer.produce('command', payload, {
    ttl: 3600,                 // seconds this message may wait in a durable queue
    guaranteed: true,          // enqueue for offline subscribers even if their
                               // subscription is not durable
    broadcast: 'realm',        // see [[Broadcast]]
    // broadcast: 'group', group: 'workers'
});

// legacy positional form: produce(event, data, lifespanSeconds)

If a default event name was configured, produce(data) works too.

TTL

Effective TTL for a durably queued message, in priority order:

  1. ttl in the produce options
  2. the producer's default_ttl
  3. the storage backend's default_ttl (24 h out of the box)

Expired messages are purged without delivery. See Persistence and Durable Delivery.

Guaranteed delivery

guaranteed: true (aliases: guaranteed_delivery, delivery: 'guaranteed') makes the broker enqueue the message for any matching subscriber that is currently offline — even subscribers that did not opt into durable subscriptions. Use it for messages that must not be lost regardless of how the consumer subscribed.

Subscription awareness

Producers are told who listens to them:

producer.setOnSubscriptionListener((subscriber) => {
    // { name, id, socket, events: [...], online: true }
});

The server also notifies producers when their subscribers connect, disconnect, and reconnect.

Large messages

produce() transparently splits payloads larger than 256 KB into ordered PRODUCE_CHUNK frames; the server reassembles before routing, and does the same on the way out to consumers. Nothing to configure.

Names and identity

  • Producer names are scoped to the realm — weather-station in realm acme and in realm beta are unrelated.
  • If a second connection registers an existing producer name, the previous holder receives an error notice and subscription state is re-sent — intentional for producer fail-over, but avoid running two live producers with one name.

Authentication

With auth enabled, the producing socket must hold the producer, both, manager, or admin role; see Roles and Connection Authorization for how producers are accepted into a realm.

Clone this wiki locally