pub mod runtime;
pub use runtime::ConsumerRuntime;
use futures::future::BoxFuture;
use crate::core::engine::FrozenDiContainer;
use crate::observability::propagation::TraceContext;
#[derive(Clone, Debug)]
pub struct InboundMessage {
pub topic: String,
pub payload: serde_json::Value,
pub idempotency_key: String,
pub tenant: Option<String>,
pub traceparent: Option<String>,
}
pub trait MessageTransport: Send + Sync + 'static {
fn poll(&self, max: usize) -> BoxFuture<'_, Result<Vec<InboundMessage>, String>>;
fn ack<'a>(&'a self, msg: &'a InboundMessage) -> BoxFuture<'a, Result<(), String>>;
fn nack<'a>(&'a self, msg: &'a InboundMessage) -> BoxFuture<'a, Result<(), String>>;
fn dead_letter<'a>(
&'a self,
msg: &'a InboundMessage,
reason: &'a str,
) -> BoxFuture<'a, Result<(), String>>;
}
pub struct EventContext {
pub message: InboundMessage,
pub container: &'static FrozenDiContainer,
pub trace: TraceContext,
}
impl EventContext {
#[inline]
pub fn inject<T: Send + Sync + 'static>(&self) -> &'static T {
self.container.get::<T>()
}
#[inline]
pub fn try_inject<T: Send + Sync + 'static>(&self) -> Option<&'static T> {
self.container.try_get::<T>()
}
pub fn payload<T: serde::de::DeserializeOwned>(&self) -> Result<T, String> {
serde_json::from_value(self.message.payload.clone())
.map_err(|e| format!("payload decode failed: {e}"))
}
pub fn traceparent(&self) -> String {
self.trace.to_traceparent()
}
}
pub struct EventHandlerDescriptor {
pub topic: &'static str,
pub consumer: &'static str,
pub handler: fn(EventContext) -> BoxFuture<'static, Result<(), String>>,
}
inventory::collect!(&'static EventHandlerDescriptor);