Skip to main content

Lifecycle

PulsarBroker::new records configuration, connect builds the client, startup opens a consumer per subscription, and shutdown closes the producers.

The broker's states as types, and what each transition does on PulsarBrokerOn PulsarPulsarBroker::new(url)ConnectedPulsarBrokerClosed: ()Configuration only,no I/OThe client is built:URL, token, retriesEach subscription:a consumer andits driver taskThe first publishto a topic opensits producerMarked closed,producers closedA publisher or a seek that outlives the connectionanswers PulsarError::NotConnected, never a silent success
The diagram as text
  1. Broker: PulsarBroker::new (url); ConnectedPulsarBroker; Closed: ()
  2. On Pulsar: Configuration only, no I/O; The client is built: URL, token, retries; Each subscription: a consumer and its driver task; The first publish to a topic opens its producer; Marked closed, producers closed
  3. PulsarBroker::new (url) → ConnectedPulsarBroker: connect(self)
  4. ConnectedPulsarBroker → Closed: (): shutdown(self)
  5. Configuration only, no I/O → The client is built: URL, token, retries
  6. The client is built: URL, token, retries → Each subscription: a consumer and its driver task
  7. Each subscription: a consumer and its driver task → The first publish to a topic opens its producer
  8. The first publish to a topic opens its producer → Marked closed, producers closed
  9. A publisher or a seek that outlives the connection answers PulsarError::NotConnected, never a silent success

new does no I/O, so the service's builder stays synchronous. The runtime connects the broker when the app starts. Connect builds the client from the URL, the token and the operation retries, and a client that cannot be built fails the start with PulsarError::Connect. A publisher taken from the broker before it connected shares its connection once it has.

Each subscription's descriptor is checked first: a subscription name, valid topic names or a valid pattern, and a retry declaration Pulsar can apply. Then the client consumer opens, on the runtime the broker connected on, and a driver task starts beside it. A refusal from the server fails the start with PulsarError::Subscribe, naming the topic.

A service that only consumes opens no producer. The first publish to a topic opens that topic's.

Shutdown marks the connection closed, then closes every producer. The client has no close of its own, so the closed state carries nothing. A subscription that is dropped stops its driver task. The driver keeps settling until every delivery it handed out has settled or been dropped, then closes the consumer.