#[non_exhaustive]pub enum Handler {
AtLeastOnce(AtLeastOnce),
ExactlyOnce(ExactlyOnce),
}Expand description
A handler for acknowledging or rejecting messages.
§Example
use google_cloud_pubsub::model::Message;
fn on_message(m: Message, h: Handler) {
match process(m) {
Ok(_) => h.ack(),
Err(e) => {
println!("failed to process message: {e:?}");
drop(h);
}
}
}
fn process(m: Message) -> anyhow::Result<()> {
// some business logic here...
}To acknowledge (ack) a message, you call Handler::ack().
To reject (nack) a message, you drop() the handler. The
service will redeliver the message.
§Exactly-once delivery
If your subscription has exactly-once delivery enabled, you should
destructure this enum into its Handler::ExactlyOnce branch.
Only when ExactlyOnce::confirmed_ack() returns Ok can you be certain
that the message will not be redelivered.
use google_cloud_pubsub::model::Message;
async fn on_message(m: Message, h: Handler) {
let Handler::ExactlyOnce(h) = h else {
panic!("Oops, my subscription does not have exactly-once delivery enabled.")
};
match h.confirmed_ack().await {
Ok(()) => println!("Confirmed ack for message={m:?}. The message will not be redelivered."),
Err(e) => println!("Failed to confirm ack for message={m:?} with error={e:?}"),
}
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
AtLeastOnce(AtLeastOnce)
ExactlyOnce(ExactlyOnce)
Implementations§
Source§impl Handler
impl Handler
Sourcepub fn ack(self)
pub fn ack(self)
Acknowledge the message associated with this handler.
§Example
use google_cloud_pubsub::model::Message;
fn on_message(m: Message, h: Handler) {
println!("Received message: {m:?}");
h.ack();
}Note that the acknowledgement is best effort. The message may still be redelivered to this client, or another client, even if exactly-once delivery is enabled on the subscription.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Handler
impl !RefUnwindSafe for Handler
impl Send for Handler
impl Sync for Handler
impl Unpin for Handler
impl UnsafeUnpin for Handler
impl !UnwindSafe for Handler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request