rocketmq_remoting/clients/
blocking_client.rs

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
18pub struct BlockingClient {
19    /// A `current_thread` runtime for executing operations on the asynchronous
20    /// client in a blocking manner.
21    rt: tokio::runtime::Runtime,
22}
23
24#[allow(clippy::needless_doctest_main)]
25impl BlockingClient {
26    /// Establish a connection with the rocketmq remoting_server located at `addr`.
27    ///
28    /// `addr` may be any type that can be asynchronously converted to a
29    /// `SocketAddr`. This includes `SocketAddr` and strings. The `ToSocketAddrs`
30    /// trait is the Tokio version and not the `std` version.
31    ///
32    /// # Examples
33    ///
34    /// ```no_run
35    /// use rocketmq_remoting::clients::BlockingClient;
36    ///
37    /// fn main() {
38    ///     let client = match BlockingClient::connect("localhost:6379") {
39    ///         Ok(client) => client,
40    ///         Err(_) => panic!("failed to establish connection"),
41    ///     };
42    /// # drop(client);
43    /// }
44    /// ```
45    pub fn connect<T: tokio::net::ToSocketAddrs>(_addr: T) -> anyhow::Result<BlockingClient> {
46        /*let rt = tokio::runtime::Builder::new_current_thread()
47            .enable_all()
48            .build()?;
49        let inner = rt.block_on(crate::clients::Client::connect(addr))?;
50        Ok(BlockingClient { inner, rt })*/
51        unimplemented!("BlockingClient::connect")
52    }
53
54    /*    pub fn invoke_oneway(
55        &mut self,
56        request: RemotingCommand,
57        timeout: Duration,
58    ) -> crate::Result<()> {
59        match self
60            .rt
61            .block_on(tokio::time::timeout(timeout, self.inner.send(request)))
62        {
63            Ok(value) => value,
64            Err(err) => Err(crate::error::Error::Elapsed(err)),
65        }
66    }*/
67}