pub struct MessageContext {
pub ctx: Arc<Context>,
pub message_id: String,
pub topic: String,
pub partition: i32,
pub offset: i64,
pub key: Option<String>,
pub headers: HashMap<String, String>,
pub started_at: Instant,
pub retry_count: u32,
pub metadata: HashMap<String, String>,
}Expand description
消息上下文
包含消息的元数据信息和上下文信息
Fields§
§ctx: Arc<Context>上下文对象(包含 trace_id、user_id 等)
message_id: String消息 ID
topic: String主题
partition: i32分区(可选,某些 MQ 支持)
offset: i64偏移量(可选,某些 MQ 支持)
key: Option<String>消息键(可选,用于分区)
headers: HashMap<String, String>消息头
started_at: Instant开始处理时间
retry_count: u32重试次数
metadata: HashMap<String, String>元数据
Implementations§
Source§impl MessageContext
impl MessageContext
Sourcepub fn elapsed_ms(&self) -> u64
pub fn elapsed_ms(&self) -> u64
获取处理耗时(毫秒)
Sourcepub fn with_key(self, key: String) -> MessageContext
pub fn with_key(self, key: String) -> MessageContext
设置消息键
Sourcepub fn with_header(self, key: String, value: String) -> MessageContext
pub fn with_header(self, key: String, value: String) -> MessageContext
添加消息头
Sourcepub fn with_metadata(self, key: String, value: String) -> MessageContext
pub fn with_metadata(self, key: String, value: String) -> MessageContext
设置元数据
Sourcepub fn increment_retry(&mut self)
pub fn increment_retry(&mut self)
增加重试次数
Trait Implementations§
Source§impl Clone for MessageContext
impl Clone for MessageContext
Source§fn clone(&self) -> MessageContext
fn clone(&self) -> MessageContext
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for MessageContext
impl !UnwindSafe for MessageContext
impl Freeze for MessageContext
impl Send for MessageContext
impl Sync for MessageContext
impl Unpin for MessageContext
impl UnsafeUnpin for MessageContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request