strut_rabbitmq/repr/ingress.rs
1use strut_factory::Deserialize as StrutDeserialize;
2
3pub mod exchange;
4pub mod header;
5pub mod queue;
6
7/// Defines how the consumed messages are acknowledged: explicitly or implicitly.
8///
9/// If transactional message handling is required, it is highly recommended to
10/// use the [manual](AckingBehavior::Manual) mode, as otherwise it is quite
11/// possible to lose messages.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, StrutDeserialize)]
13#[strut(eq_fn = strut_deserialize::Slug::eq_as_slugs)]
14pub enum AckingBehavior {
15 /// Messages must be explicitly acknowledged by the application logic.
16 ///
17 /// This is the recommended mode for transactional message handling: a
18 /// message will not be removed from the queue until its [`Envelope`] is
19 /// explicitly finalized. This, however, means that some messages may end up
20 /// being processed more than once. Thus, this mode provides the
21 /// at-least-once message processing semantics.
22 Manual,
23
24 /// Messages are implicitly pre-acknowledged by the server on delivery,
25 /// before even reaching the application logic.
26 ///
27 /// **This mode will cause missed messages** on consumption! Some messages
28 /// may occasionally fall through the cracks before being handed to the
29 /// consuming logic, and since the messages are implicitly pre-acknowledged
30 /// — such messages will not be re-delivered or seen again.
31 ///
32 /// If it is important to process each message no more than once, but
33 /// occasional message loss is acceptable — this is the mode of choice.
34 ///
35 /// For transactional handling with at-least-once semantics, use the
36 /// [manual](AckingBehavior::Manual) mode.
37 ///
38 /// This mode effectively disables the [prefetch](Ingress::prefetch_count).
39 /// The prefetch count refers to the count of **unacknowledged** messages
40 /// pre-delivered to a consumer, and with implicit auto-acking there are no
41 /// unacknowledged messages at all.
42 Auto,
43}
44
45/// Defines the matching behavior for the
46/// [`Headers`](ExchangeKind::Headers) kind of exchange. Irrelevant for
47/// all other kinds of exchanges.
48#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, StrutDeserialize)]
49#[strut(eq_fn = strut_deserialize::Slug::eq_as_slugs)]
50pub enum HeadersMatchingBehavior {
51 /// All headers must match (`x-match: all`).
52 All,
53
54 /// At least one header must match (`x-match: any`).
55 Any,
56}
57
58impl HeadersMatchingBehavior {
59 /// Returns the appropriate string header value recognized by RabbitMQ.
60 pub const fn rabbitmq_value(&self) -> &str {
61 match self {
62 HeadersMatchingBehavior::All => "all",
63 HeadersMatchingBehavior::Any => "any",
64 }
65 }
66}