Skip to main content

rocketmq_client_rust/
lib.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
15#![allow(dead_code)]
16#![allow(unused_variables)]
17#![allow(clippy::result_large_err)]
18#![recursion_limit = "256"]
19
20extern crate core;
21
22// Define macros at crate root so they're available throughout the crate
23/// Create a client error with optional response code
24#[macro_export]
25macro_rules! mq_client_err {
26    // Handle errors with a custom ResponseCode and formatted string
27    ($response_code:expr, $fmt:expr, $($arg:expr),*) => {{
28        let formatted_msg = format!($fmt, $($arg),*);
29        let error_message = format!("CODE: {}  DESC: {}", $response_code as i32, formatted_msg);
30        let faq_msg = rocketmq_common::common::FAQUrl::attach_default_url(Some(error_message.as_str()));
31        rocketmq_error::RocketMQError::illegal_argument(faq_msg)
32    }};
33
34    ($response_code:expr, $error_message:expr) => {{
35        let error_message = format!("CODE: {}  DESC: {}", $response_code as i32, $error_message);
36        let faq_msg = rocketmq_common::common::FAQUrl::attach_default_url(Some(error_message.as_str()));
37        rocketmq_error::RocketMQError::illegal_argument(faq_msg)
38    }};
39
40    // Handle errors without a ResponseCode, using only the error message (accepts both &str and String)
41    ($error_message:expr) => {{
42        let error_msg: &str = "Body is empty";
43        let faq_msg = rocketmq_common::common::FAQUrl::attach_default_url(Some(error_msg));
44        rocketmq_error::RocketMQError::illegal_argument(faq_msg)
45    }};
46}
47
48/// Create a broker operation error
49#[macro_export]
50macro_rules! client_broker_err {
51    // Handle errors with a custom ResponseCode and formatted string
52    ($response_code:expr, $error_message:expr, $broker_addr:expr) => {{
53        rocketmq_error::RocketMQError::broker_operation_failed(
54            "BROKER_OPERATION",
55            $response_code as i32,
56            $error_message,
57        )
58        .with_broker_addr($broker_addr)
59    }};
60    // Handle errors without a ResponseCode, using only the error message
61    ($response_code:expr, $error_message:expr) => {{
62        rocketmq_error::RocketMQError::broker_operation_failed(
63            "BROKER_OPERATION",
64            $response_code as i32,
65            $error_message,
66        )
67    }};
68}
69
70// Define client_error module
71pub mod client_error;
72
73pub mod admin;
74pub mod base;
75pub mod common;
76pub mod consumer;
77pub mod factory;
78mod hook;
79pub mod implementation;
80mod latency;
81pub mod producer;
82pub mod stat;
83mod trace;
84mod types;
85pub mod utils;
86
87pub use crate::consumer::consumer_impl::pull_request_ext::PullResultExt;
88pub use crate::trace::trace_data_encoder::TraceDataEncoder;