下面显示的是英文原文。
Shutdown
Shutdown marks the connection closed; a publisher handed out earlier reports SqsError::NotConnected instead of sending.
SQS calls complete one by one, and the SDK clients hold nothing to flush. The runtime stops the subscriptions and marks the connection closed, which is the whole teardown. A delivery a handler had not settled returns to its queue when its visibility timeout lapses.
A publisher taken with SqsBroker::publisher shares the broker's connection.
It can be taken before the app starts and handed to code outside the handlers, such as an HTTP endpoint.
It sends once the runtime has connected the broker.
After shutdown it returns SqsError::NotConnected inside the core's PublishError, and never sends over a connection the service has given up.
A publisher of a lifecycle hook or an Out slot behaves the same way.
Example
The service hands a publisher to code outside its handlers.
- Macros
- Manual
/// The service, and a publisher for code outside its handlers, such as an HTTP endpoint that
/// takes orders. The publisher shares the broker's connection, from startup to shutdown.
fn service(broker: SqsBroker, queue: String) -> (impl App<State = ()>, SqsPublisher) {
let intake = broker.publisher();
let app = RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(broker, |b| {
b.include(handle.name(queue).create_if_missing());
});
(app, intake)
}
/// The service, and a publisher for code outside its handlers, such as an HTTP endpoint that
/// takes orders. The publisher shares the broker's connection, from startup to shutdown.
fn service(broker: SqsBroker, queue: String) -> (impl App<State = ()>, SqsPublisher) {
let intake = broker.publisher();
let app = RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(broker, |b| {
b.include(
subscriber(Unnamed::<SqsQueue>::new(), Receive)
.build()
.name(queue)
.create_if_missing(),
);
});
(app, intake)
}