namespaces

topic

Publish an event to a topic so every subscriber receives it (publish and subscribe).

The topic namespace publishes an event to a named topic through the configured messaging provider. A topic is publish and subscribe: every subscriber declared with on topic receives a copy of each event.

When to use

Use a topic to broadcast an event so several independent parts of a system can react to it, without the publisher knowing who is listening. When each message should be handled once by a single consumer instead, use queue.

Make it event-driven is a tutorial built on topics.

Operations

topic.publish broadcasts an event. Add as <Schema> to shape it to the event contract before it goes out:

marreta
topic.publish "order_placed" as Order, payload
NameSignatureSummary
topic.publishtopic.publish "<topic>" [as Schema], payloadPublishes an event to every subscriber.

A subscriber is a top-level handler, not a method on this namespace, and a topic can have any number of them:

marreta
on topic "order_placed" take event as Order
    log.info("order #{event.id}")

Notes

  • The messaging provider must be configured and reachable before marreta serve. Run marreta doctor to check the connection.
  • Subscribers share the queue ack/nack rules: a clean run acknowledges, an error or a schema mismatch nacks without requeue. See ack and nack.