Skip to main content

rustack_sqs_http/
dispatch.rs

1//! SQS handler trait and operation dispatch.
2
3use std::{future::Future, pin::Pin};
4
5use bytes::Bytes;
6use rustack_sqs_model::{error::SqsError, operations::SqsOperation};
7
8use crate::body::SqsResponseBody;
9
10/// Trait that the SQS business logic provider must implement.
11///
12/// The handler receives a parsed operation enum and the raw JSON body bytes,
13/// and returns a complete HTTP response. This trait serves as the boundary
14/// between the HTTP transport layer and the business logic layer.
15pub trait SqsHandler: Send + Sync + 'static {
16    /// Handle an SQS operation and produce an HTTP response.
17    fn handle_operation(
18        &self,
19        op: SqsOperation,
20        body: Bytes,
21    ) -> Pin<Box<dyn Future<Output = Result<http::Response<SqsResponseBody>, SqsError>> + Send>>;
22}
23
24/// Dispatch an SQS operation to the handler.
25pub async fn dispatch_operation<H: SqsHandler>(
26    handler: &H,
27    op: SqsOperation,
28    body: Bytes,
29) -> Result<http::Response<SqsResponseBody>, SqsError> {
30    tracing::debug!(operation = %op, "dispatching SQS operation");
31    handler.handle_operation(op, body).await
32}