pub struct StompAdapter {
id: AdapterId,
config: StompConfig,
}Expand description
STOMP client that bridges configured topics both ways.
Inbound MESSAGE frames are stamped with oag.origin_adapter so
outbound SEND can refuse the echo when
StompConfig::suppress_echo is on. Engine::drop_adapter runs
at session start and end so a reconnect does not keep stale
subscriptions.
Fields§
§id: AdapterId§config: StompConfigImplementations§
Source§impl StompAdapter
impl StompAdapter
Sourcepub fn new(id: impl Into<AdapterId>, config: StompConfig) -> Self
pub fn new(id: impl Into<AdapterId>, config: StompConfig) -> Self
Builds an adapter that is not yet connected.
pub fn id(&self) -> &AdapterId
pub fn config(&self) -> &StompConfig
Sourcepub async fn serve(
self: Arc<Self>,
engine: Arc<Engine>,
shutdown: CancellationToken,
) -> Result<(), AdapterError>
pub async fn serve( self: Arc<Self>, engine: Arc<Engine>, shutdown: CancellationToken, ) -> Result<(), AdapterError>
Connects, subscribes, and bridges until shutdown or a fatal
session error with reconnect off.
§Errors
Returns AdapterError::Failed if connect, SUBSCRIBE, or the
session fails and StompConfig::reconnect is false; if a
session panics and StompConfig::on_panic is abort; or if
shutdown has already fired.
Sourcepub async fn serve_ready(
self: Arc<Self>,
engine: Arc<Engine>,
shutdown: CancellationToken,
ready: Sender<()>,
) -> Result<(), AdapterError>
pub async fn serve_ready( self: Arc<Self>, engine: Arc<Engine>, shutdown: CancellationToken, ready: Sender<()>, ) -> Result<(), AdapterError>
Same as Self::serve, then signals ready after the first
CONNECTED and engine subscriptions.
Used by tests that must not publish before the bridge is up. Later reconnects do not signal again.
§Errors
Same as Self::serve.
Sourceasync fn serve_inner(
self: Arc<Self>,
engine: Arc<Engine>,
shutdown: CancellationToken,
ready: Option<Sender<()>>,
) -> Result<(), AdapterError>
async fn serve_inner( self: Arc<Self>, engine: Arc<Engine>, shutdown: CancellationToken, ready: Option<Sender<()>>, ) -> Result<(), AdapterError>
Retry loop. Delay comes from StompConfig::reconnect_delay.
ready is taken on the first session only.
Sourceasync fn session(
&self,
engine: &Arc<Engine>,
shutdown: &CancellationToken,
ready: Option<Sender<()>>,
) -> Result<(), AdapterError>
async fn session( &self, engine: &Arc<Engine>, shutdown: &CancellationToken, ready: Option<Sender<()>>, ) -> Result<(), AdapterError>
One CONNECT through DISCONNECT.
Drops this adapter’s engine subscriptions before SUBSCRIBE so a
previous session cannot leave keys behind. Engine subscribe uses
RouteKey::topic (wildcard) for each configured topic.
§Errors
Returns AdapterError::Failed if the broker cannot be reached,
SUBSCRIBE fails, or Self::drive_session fails.
Sourceasync fn drive_session(
&self,
reader: &mut FrameReader,
writer: &mut FrameWriter,
engine: &Arc<Engine>,
shutdown: &CancellationToken,
map: &DestinationMap,
eng_rx: &mut Receiver<Delivery>,
) -> Result<(), AdapterError>
async fn drive_session( &self, reader: &mut FrameReader, writer: &mut FrameWriter, engine: &Arc<Engine>, shutdown: &CancellationToken, map: &DestinationMap, eng_rx: &mut Receiver<Delivery>, ) -> Result<(), AdapterError>
Reads broker frames and engine deliveries until shutdown or a broken connection.
A clean broker close is an error so reconnect can fire. A
dropped engine channel is Ok.
§Errors
Returns AdapterError::Failed if the broker closes, a read
fails, or an outbound SEND cannot be written.
Sourceasync fn handle_frame(
&self,
engine: &Arc<Engine>,
map: &DestinationMap,
frame: Frame,
) -> Result<(), String>
async fn handle_frame( &self, engine: &Arc<Engine>, map: &DestinationMap, frame: Frame, ) -> Result<(), String>
Handles one inbound frame. MESSAGE is published; ERROR fails the session; RECEIPT is ignored.
§Errors
Returns a message for a broker ERROR or a MESSAGE that cannot be mapped onto an envelope.