Skip to main content

rocketmq_client_rust/implementation/mq_client_api_impl/
producer_client.rs

1// Copyright 2026 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 ProducerClient<'a> {
18    api: &'a MQClientAPIImpl,
19}
20
21impl ProducerClient<'_> {
22    pub async fn send_heartbeat(
23        &self,
24        addr: &CheetahString,
25        heartbeat_data: &HeartbeatData,
26        timeout_millis: u64,
27    ) -> crate::ClientResult<(i32, Option<RemotingCommand>)> {
28        self.api.send_heartbeat(addr, heartbeat_data, timeout_millis).await
29    }
30}
31
32impl MQClientAPIImpl {
33    #[must_use]
34    pub fn producer_client(&self) -> ProducerClient<'_> {
35        ProducerClient { api: self }
36    }
37
38    pub async fn send_heartbeat_async(
39        &self,
40        addr: &CheetahString,
41        heartbeat_data: &HeartbeatData,
42        timeout_millis: u64,
43    ) -> crate::ClientResult<i32> {
44        self.send_heartbeat(addr, heartbeat_data, timeout_millis)
45            .await
46            .map(|(version, _)| version)
47    }
48}