name
#[subscriber(GooglePubSub)] fixes the kind of subscription, and name at the mount site leaves its name to the deployment.
A handler written with the bare kind has no subscription yet.
.name("orders-workers") where it is mounted builds the descriptor, as GooglePubSub::new would.
A definition mounted without a name does not compile.
The descriptor built this way keeps every default; a subscription with settings of its own is a descriptor in the attribute.
The same handler serves several deployments that each read a subscription of their own, such as one per region.
The manual form starts from Unnamed::<GooglePubSub>::new() and takes the same .name(..) step.
Example
Each deployment names its subscription in ORDERS_SUBSCRIPTION.
- Macros
- Manual
/// A Pub/Sub subscription whose name the deployment decides.
#[subscriber(GooglePubSub)]
async fn place(order: &Order) -> HandlerOutcome {
tracing::info!(order.id, "order placed");
HandlerOutcome::ack()
}
/// One service per region, each reading the subscription of its region.
fn service(subscription: String) -> impl App<State = ()> {
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(
PubSubBroker::new("my-project"),
|b| {
b.include(place.name(subscription));
},
)
}
/// A Pub/Sub subscription whose name the deployment decides.
struct Place;
impl Handle<Order> for Place {
fn handle(
&self,
order: &Order,
_outs: &(),
_ctx: &mut Context<'_>,
) -> impl Future<Output = Result<(), HandlerOutcome>> {
tracing::info!(order.id, "order placed");
ready(Ok(()))
}
}
/// One service per region, each reading the subscription of its region.
fn service(subscription: String) -> impl App<State = ()> {
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(
PubSubBroker::new("my-project"),
|b| {
b.include(
subscriber(Unnamed::<GooglePubSub>::new(), Place)
.name(subscription)
.build(),
);
},
)
}