Skip to main content

rocketmq_client_rust/implementation/mq_client_api_impl/
transaction.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 super::*;
16
17pub struct TransactionClient<'a> {
18    api: &'a MQClientAPIImpl,
19}
20
21impl TransactionClient<'_> {
22    pub async fn end_transaction(
23        &self,
24        addr: &CheetahString,
25        request_header: EndTransactionRequestHeader,
26        remark: CheetahString,
27        timeout_millis: u64,
28    ) -> crate::ClientResult<()> {
29        self.api
30            .end_transaction_oneway(addr, request_header, remark, timeout_millis)
31            .await
32    }
33}
34
35impl MQClientAPIImpl {
36    #[must_use]
37    pub fn transaction_client(&self) -> TransactionClient<'_> {
38        TransactionClient { api: self }
39    }
40}
41
42impl MQClientAPIImpl {
43    pub async fn end_transaction_oneway(
44        &self,
45        addr: &CheetahString,
46        request_header: EndTransactionRequestHeader,
47        remark: CheetahString,
48        timeout_millis: u64,
49    ) -> crate::ClientResult<()> {
50        let request = self
51            .create_request_command(RequestCode::EndTransaction, request_header)
52            .set_remark(remark);
53
54        self.remoting_client
55            .invoke_request_oneway(addr, request, timeout_millis)
56            .await
57            .map_err(crate::ClientError::from)
58    }
59}