pub trait SendCallback: Send + Sync {
// Required methods
fn on_success(&self, send_result: &SendResult);
fn on_exception(&self, error: &ClientError);
}Expand description
Callback trait for handling asynchronous message send results.
Implementors of this trait can respond to successful message delivery or send failures. Closures that match the expected signature automatically implement this trait through blanket implementation.
§Examples
Using a closure as callback:
ⓘ
producer.send_with_callback(message, |result, error| {
match (result, error) {
(Some(send_result), None) => {
println!("Sent: {:?}", send_result.msg_id);
}
(None, Some(err)) => {
eprintln!("Failed: {}", err);
}
_ => {}
}
}).await?;Implementing the trait:
ⓘ
struct LoggingCallback;
impl SendCallback for LoggingCallback {
fn on_success(&self, send_result: &SendResult) {
log::info!("Message sent: {:?}", send_result.msg_id);
}
fn on_exception(&self, error: &ClientError) {
log::error!("Send failed: {}", error);
}
}Required Methods§
Sourcefn on_success(&self, send_result: &SendResult)
fn on_success(&self, send_result: &SendResult)
Invoked when a message is successfully sent.
§Arguments
send_result- Contains the message ID, queue information, and send metadata.
Sourcefn on_exception(&self, error: &ClientError)
fn on_exception(&self, error: &ClientError)
Invoked when a message send operation fails.
§Arguments
error- The error that caused the send failure.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".