Skip to main content

Lifecycle

SqsBroker::new records configuration, connect loads the AWS configuration, startup opens a pump per queue, and shutdown closes the connection.

The broker's states as types, and what each transition does on AWSBrokerOn AWSSqsBroker::new()ConnectedSqsBrokerClosed = ()nothing to reportConfiguration only,no I/OAWS configuration,25 s per attempt,SDK clients builtEach subscription:GetQueueUrl orCreateQueue, the redrivepolicy, the visibility,the pump startedA publish resolvesits queue or topiconce, then caches itThe connectionis marked closedA publisher that outlives the connection answersSqsError::NotConnected, never a silent success
The diagram as text
  1. Broker: SqsBroker::new(); ConnectedSqsBroker; Closed = () nothing to report
  2. On AWS: Configuration only, no I/O; AWS configuration, 25 s per attempt, SDK clients built; Each subscription: GetQueueUrl or CreateQueue, the redrive policy, the visibility, the pump started; A publish resolves its queue or topic once, then caches it; The connection is marked closed
  3. SqsBroker::new() → ConnectedSqsBroker: connect(self)
  4. ConnectedSqsBroker → Closed = () nothing to report: shutdown(self)
  5. Configuration only, no I/O → AWS configuration, 25 s per attempt, SDK clients built
  6. AWS configuration, 25 s per attempt, SDK clients built → Each subscription: GetQueueUrl or CreateQueue, the redrive policy, the visibility, the pump started
  7. Each subscription: GetQueueUrl or CreateQueue, the redrive policy, the visibility, the pump started → A publish resolves its queue or topic once, then caches it
  8. A publish resolves its queue or topic once, then caches it → The connection is marked closed
  9. A publisher that outlives the connection answers SqsError::NotConnected, never a silent success

new, endpoint, region, test_credentials and from_config do no I/O, so the service's builder stays synchronous. A clone of the broker shares its connection, which is how a startup hook reaches the connection the runtime opened. The runtime connects the broker when the app starts.

Connect loads the AWS configuration through the SDK's default chain, with the endpoint and region the broker names, and sets a 25-second timeout per attempt, above the 20-second long poll. A broker built with from_config keeps its SdkConfig, timeouts included, except an endpoint or a region the broker names. Then connect builds the SDK clients. The SDK fetches credentials lazily, on the first request. In a service that request is the first subscription's GetQueueUrl, so a bad credential fails the start on subscribe.

Each subscription's SqsQueue is checked first: an empty name, a wait over 20 seconds or a visibility outside one second to 12 hours is SqsError::InvalidQueue before any call to AWS, as Startup shows. Then the subscription resolves the queue URL, or creates the queue under create_if_missing. It writes the redrive policy when the registration declares max_attempts and dead_letter. It reads the queue's own visibility timeout when the descriptor names none. Then it starts the pump.

A receive error reaches the subscription's stream as an item. A queue that no longer exists ends the pump, and any other error makes it wait one second before the next receive.

Shutdown marks the connection closed and returns (): the SDK clients have nothing to close or flush. A publisher created before shutdown answers SqsError::NotConnected afterwards.