Prelude
One glob, ruststream_sqs_sns::prelude, brings the core prelude, the broker, the queue descriptor, the policies and the publish steps.
use ruststream_sqs_sns::prelude::*; is the one import a routes file writes.
It carries the core's own prelude, so #[subscriber], #[app], RustStream, HandlerOutcome and Out come with it.
It adds SqsBroker, the descriptor SqsQueue with its mount-site steps SqsSubscription, the publish steps SqsPublishSteps with SqsPublishOptions, and the publishers SqsPublisher and, with sns, SnsPublisher.
The queue policy comes under the name every broker crate gives it: Publish is SqsPublish, so a mount site reads the same on every broker.
SnsPublish, with the sns feature, keeps its own name.
Two broker preludes in one file collide on Publish; the prefixed types at the crate root tell them apart.
The constants RECEIVE_COUNT_HEADER and PARTITION_KEY_HEADER and the error type SqsError are imported from the crate root.
A handler file globs the core prelude and names no broker type: an injected publisher is bounded Out<impl Publisher, Marker>.
The one exception is a body that sets a per-message setting: group_id or deduplication_id needs SqsPublishSteps in scope and the slot bounded Out<impl Publisher<Options = SqsPublishOptions>, Marker>, both from this prelude.
Example
The descriptor, the broker and the reply policy all come from the one glob.
- Macros
- Manual
use ruststream_sqs_sns::prelude::*;
#[subscriber(SqsQueue::new("orders").wait(Duration::from_secs(20)), reply)]
async fn accept(order: &Order) -> OrderAccepted {
tracing::info!(order.id, "order accepted");
OrderAccepted { id: order.id }
}
#[app]
fn app() -> impl App {
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(SqsBroker::new(), |b| {
b.include(accept).out_reply(Publish::default());
})
}
use ruststream_sqs_sns::prelude::*;
struct Accept;
impl Handle<Order, OrderAccepted> for Accept {
fn handle(
&self,
order: &Order,
_outs: &(),
_ctx: &mut Context<'_>,
) -> impl Future<Output = Result<OrderAccepted, HandlerOutcome>> {
tracing::info!(order.id, "order accepted");
ready(Ok(OrderAccepted { id: order.id }))
}
}
fn app() -> impl App {
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(SqsBroker::new(), |b| {
b.include(
subscriber(Unnamed::<SqsQueue>::new(), Accept)
.reply()
.build()
.name("orders")
.wait(Duration::from_secs(20)),
)
.out_reply(Publish::default());
})
}