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 crate::consumer::ack_result::AckResult;
16use crate::ClientError;
17
18/// Trait representing an acknowledgment callback.
19/// This trait defines two methods: `on_success` and `on_exception`.
20pub trait AckCallback {
21    /// Called when the acknowledgment is successful.
22    ///
23    /// # Arguments
24    ///
25    /// * `ack_result` - The result of the acknowledgment.
26    fn on_success(&self, ack_result: AckResult);
27
28    /// Called when there is an exception during acknowledgment.
29    ///
30    /// # Arguments
31    ///
32    /// * `e` - The error that occurred.
33    fn on_exception(&self, e: ClientError);
34}
35
36/// Type alias for a function that acts as an acknowledgment callback.
37/// The function takes two optional arguments: an `AckResult` and an error.
38///
39/// This type alias is used to define a callback function that can be passed
40/// around and invoked when an acknowledgment operation completes.
41///
42/// The function must be `Send` and `Sync` to ensure it can be safely used
43/// across threads.
44pub type AckCallbackFn = Box<dyn Fn(AckResult) -> Result<(), ClientError> + Send + Sync>;