-
Notifications
You must be signed in to change notification settings - Fork 0
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 });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.
Effective TTL for a durably queued message, in priority order:
-
ttlin the produce options - the producer's
default_ttl - the storage backend's
default_ttl(24 h out of the box)
Expired messages are purged without delivery. See Persistence and Durable 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.
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.
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.
- Producer names are scoped to the realm —
weather-stationin realmacmeand in realmbetaare 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.
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.
tyo-mq · README · Improvement Plan · Clustering Guide · Apache-2.0
Basics
Security
- Authentication and Realms
- Ephemeral Realms
- Roles and Connection Authorization
- Authorization Requests
Delivery
Routing
Operations
Reference