Skip to main content

rocketmq_client_rust/consumer/
ack_callback.rs

1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::error::Error;
16
17use crate::consumer::ack_result::AckResult;
18
19/// Trait representing an acknowledgment callback.
20/// This trait defines two methods: `on_success` and `on_exception`.
21pub trait AckCallback {
22    /// Called when the acknowledgment is successful.
23    ///
24    /// # Arguments
25    ///
26    /// * `ack_result` - The result of the acknowledgment.
27    fn on_success(&self, ack_result: AckResult);
28
29    /// Called when there is an exception during acknowledgment.
30    ///
31    /// # Arguments
32    ///
33    /// * `e` - The error that occurred.
34    fn on_exception(&self, e: Box<dyn Error>);
35}
36
37/// Type alias for a function that acts as an acknowledgment callback.
38/// The function takes two optional arguments: an `AckResult` and an error.
39///
40/// This type alias is used to define a callback function that can be passed
41/// around and invoked when an acknowledgment operation completes.
42///
43/// The function must be `Send` and `Sync` to ensure it can be safely used
44/// across threads.
45pub type AckCallbackFn = Box<dyn Fn(AckResult) -> Result<(), Box<dyn Error>> + Send + Sync>;