1use async_trait::async_trait;
2use futures_lite::Stream;
3use thiserror::Error;
4
5#[derive(Debug, Clone, Copy)]
6pub struct AmqpQueueInformation<'a> {
7 pub queue_name: &'a str,
8 pub exchange: &'a str,
9 pub routing_key: &'a str,
10}
11
12pub struct AmqpQueueDeclaration<'a, T, DError> {
13 pub information: AmqpQueueInformation<'a>,
14 pub serializer: fn(T) -> Vec<u8>,
15 pub deserializer: fn(Vec<u8>) -> Result<T, DError>,
16}
17
18#[derive(Debug, Error)]
19pub enum AmqpConsumerError<CError, DError> {
20 #[error("Consumer error: {0}")]
21 ConsumerError(CError),
22 #[error("Deserialization error: {0}")]
23 DeserializationError(DError),
24}
25
26#[cfg(feature = "lapin")]
27pub mod lapin;
28
29#[async_trait]
30pub trait Producer<T> {
31 type Error;
32
33 async fn publish(&self, value: T) -> Result<(), Self::Error>;
34}
35
36pub trait Consumer<'a, T, DError> {
37 type Error;
38 type Stream: Stream<Item = Result<T, AmqpConsumerError<Self::Error, DError>>> + 'a
39 where
40 Self: 'a;
41
42 fn to_stream(&'a mut self) -> Self::Stream;
43}