oa_gateway_stomp/
config.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::net::SocketAddr;
use std::time::Duration;

use oa_gateway_adapter::tls::ClientTls;
use oa_gateway_adapter::OnPanic;

use crate::codec::DEFAULT_MAX_FRAME_SIZE;
use crate::Secret;

/// Runtime settings for a STOMP client session.
///
/// This is not the host TOML section. `broker` is already a
/// [`SocketAddr`]; the host resolves the hostname before constructing
/// this. There is no `enabled` flag here — spawning is the host's
/// decision.
///
/// [`Self::login`] and [`Self::passcode`] are `None` to omit those
/// CONNECT headers, not to send blanks. [`Self::passcode`] is sent only
/// when [`Self::login`] is set, and is a [`Secret`] so it cannot be
/// printed by a `Debug` of this struct.
#[derive(Debug, Clone)]
pub struct StompConfig {
    pub broker: SocketAddr,
    /// STOMP `host` header. ActiveMQ Classic typically wants `/`.
    pub host: String,
    /// CONNECT `login`. `None` omits the header.
    pub login: Option<String>,
    /// CONNECT `passcode`. Sent only when [`Self::login`] is `Some`.
    pub passcode: Option<Secret>,
    /// Prepended to each topic to form a STOMP destination. A missing
    /// trailing slash is added by [`crate::DestinationMap`].
    pub destination_prefix: String,
    /// Engine topics (and STOMP dest suffixes) to bridge both ways.
    pub topics: Vec<String>,
    /// Peel A-GRA Rx/Tx hex wrappers on inbound MESSAGE frames and
    /// publish wrapper plus inner as two envelopes.
    pub unwrap_ma_payloads: bool,
    /// Retry the broker after a dropped session or a session `Err`.
    pub reconnect: bool,
    /// Sleep between reconnect attempts.
    pub reconnect_delay: Duration,
    /// Budget for TCP connect and for the CONNECTED wait, each.
    pub connect_timeout: Duration,
    /// Skip outbound SEND when the envelope is an echo of this adapter.
    pub suppress_echo: bool,
    /// Panic in a session task: abort `run`, or treat as a failed
    /// session.
    pub on_panic: OnPanic,
    /// Largest frame accepted from the broker. Bounds the read buffer
    /// and the `content-length` a peer can claim.
    pub max_frame_size: usize,
    /// Wrap the broker connection in TLS. `None` dials plaintext, which
    /// is the default.
    pub tls: Option<ClientTls>,
}

impl Default for StompConfig {
    /// Local ActiveMQ defaults: `127.0.0.1:61613`, `host` `/`,
    /// `/topic/` + `demo`, unwrap and reconnect on, echo suppressed,
    /// panic aborts, one-second reconnect delay, five-second
    /// timeouts, [`DEFAULT_MAX_FRAME_SIZE`].
    fn default() -> Self {
        Self {
            broker: "127.0.0.1:61613".parse().expect("static addr"),
            host: "/".into(),
            login: None,
            passcode: None,
            destination_prefix: "/topic/".into(),
            topics: vec!["demo".into()],
            unwrap_ma_payloads: true,
            reconnect: true,
            reconnect_delay: Duration::from_secs(1),
            connect_timeout: Duration::from_secs(5),
            suppress_echo: true,
            on_panic: OnPanic::Abort,
            max_frame_size: DEFAULT_MAX_FRAME_SIZE,
            tls: None,
        }
    }
}