GooglePubSub
GooglePubSub names one subscription by short id or full resource name and carries its settings: topology, flow control, leases and batches.
GooglePubSub::new takes the subscription's name, and builder steps add the rest.
create_with_topic creates the subscription and its topic at startup.
max_outstanding caps the deliveries that may be unsettled at once.
ack_extension and max_lease shape how the client keeps a delivery leased.
batch_wait bounds how long a partial batch waits for the rest.
A setting the descriptor leaves out keeps the client library's default.
The descriptor is plain data and holds no connection. It opens against the connected broker at startup, so the declaration a service ships is the one its tests run.
Example
The subscription orders-workers on the topic orders, with at most 100 orders unsettled at once.
- Macros
- Manual
/// The subscription `orders-workers` on the topic `orders`, with at most 100 orders unsettled.
#[subscriber(
GooglePubSub::new("orders-workers")
.create_with_topic("orders")
.max_outstanding(100)
)]
async fn place(order: &Order) -> HandlerOutcome {
tracing::info!(order.id, "order placed");
HandlerOutcome::ack()
}
/// The subscription `orders-workers` on the topic `orders`, with at most 100 orders unsettled.
fn orders() -> GooglePubSub {
GooglePubSub::new("orders-workers")
.create_with_topic("orders")
.max_outstanding(100)
}