Skip to content

Commit 73fa7d1

Browse files
committed
[ISSUE #1657]🚀Add AckCallback trait🔥
1 parent 32b095a commit 73fa7d1

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

rocketmq-client/src/consumer.rs

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

0 commit comments

Comments
 (0)