little_stomper/
destinations.rs1use std::ops::Deref;
2
3use crate::error::StomperError;
4
5string_id_class!(SubscriptionId);
6
7string_id_class!(DestinationId);
8
9string_id_class!(MessageId);
10
11pub struct InboundMessage {
12 pub sender_message_id: Option<MessageId>,
13 pub body: Vec<u8>,
14}
15
16#[derive(Clone, Debug)]
17pub struct OutboundMessage {
18 pub destination: DestinationId,
19 pub message_id: MessageId,
20 pub body: Vec<u8>,
21}
22
23pub trait Subscriber: Send + Sync + std::fmt::Debug {
24 fn subscribe_callback(
25 &self,
26 destination: DestinationId,
27 suscriber_sub_id: Option<SubscriptionId>,
28 result: Result<SubscriptionId, StomperError>,
29 );
30
31 fn unsubscribe_callback(
32 &self,
33 subscriber_sub_id: Option<SubscriptionId>,
34 result: Result<SubscriptionId, StomperError>,
35 );
36
37 fn send(
38 &self,
39 subscription: SubscriptionId,
40 suscriber_sub_id: Option<SubscriptionId>,
41 message: OutboundMessage,
42 ) -> Result<(), StomperError>;
43}
44
45pub trait Sender: Send + Sync + std::fmt::Debug {
46 fn send_callback(
47 &self,
48 sender_message_id: Option<MessageId>,
49 result: Result<MessageId, StomperError>,
50 );
51}
52
53pub trait Destination: Send + Clone {
55 type Client: crate::client::Client;
56
57 fn subscribe<S: Subscriber + 'static, D: Deref<Target = S> + Send + Clone + 'static>(
58 &self,
59 sender_subscription_id: Option<SubscriptionId>,
60 subscriber: D,
61 client: &Self::Client,
62 );
63
64 fn unsubscribe<S: Subscriber + 'static, D: Deref<Target = S> + Send + Clone + 'static>(
65 &self,
66 sub_id: SubscriptionId,
67 subscriber: D,
68 client: &Self::Client,
69 );
70
71 fn send<S: Sender + 'static, D: Deref<Target = S> + Send + Clone + 'static>(
72 &self,
73 message: InboundMessage,
74 sender: D,
75 client: &Self::Client,
76 );
77
78 fn close(&self);
79}
80
81pub trait Destinations: Send + Clone {
82 type Client: crate::client::Client;
83
84 fn subscribe<S: Subscriber + 'static, D: Deref<Target = S> + Clone + Send + 'static>(
85 &self,
86 destination: DestinationId,
87 sender_subscription_id: Option<SubscriptionId>,
88 subscriber: D,
89 client: &Self::Client,
90 );
91
92 fn unsubscribe<S: Subscriber + 'static, D: Deref<Target = S> + Clone + Send + 'static>(
93 &self,
94 destination: DestinationId,
95 destination_subscription_id: SubscriptionId,
96 subscriber: D,
97 client: &Self::Client,
98 );
99
100 fn send<S: Sender + 'static, D: Deref<Target = S> + Clone + Send + 'static>(
102 &self,
103 destination: DestinationId,
104 message: InboundMessage,
105 sender: D,
106 client: &Self::Client,
107 );
108}