pub struct EventEnvelope {
pub event_id: String,
pub event_type: String,
pub partition_key: String,
pub seq: u64,
pub payload: Vec<u8>,
pub timestamp_ms: Option<u64>,
pub source: Option<String>,
}Expand description
统一事件信封:事件总线上的标准载荷(与具体业务解耦)
Fields§
§event_id: String全局唯一事件 ID
event_type: String事件类型(业务自定义,如 “message.created”、“order.shipped”)
partition_key: String分区键:用于 Kafka 等按 key 分区与过滤,同 key 内有序(IM 可为 conversation_id,订单可为 order_id)
seq: u64流内序号:用于同分区内的顺序与去重
payload: Vec<u8>业务载荷(protobuf / JSON 等,由业务解析)
timestamp_ms: Option<u64>可选:事件发生时间戳(毫秒)
source: Option<String>可选:来源服务标识
Implementations§
Source§impl EventEnvelope
impl EventEnvelope
Sourcepub fn new(
event_type: impl Into<String>,
partition_key: impl Into<String>,
seq: u64,
payload: Vec<u8>,
) -> EventEnvelope
pub fn new( event_type: impl Into<String>, partition_key: impl Into<String>, seq: u64, payload: Vec<u8>, ) -> EventEnvelope
构造信封。partition_key 由业务定义(如会话 ID、订单 ID、租户 ID)。
Sourcepub fn with_timestamp_ms(self, ms: u64) -> EventEnvelope
pub fn with_timestamp_ms(self, ms: u64) -> EventEnvelope
设置时间戳(毫秒)
Sourcepub fn with_source(self, source: impl Into<String>) -> EventEnvelope
pub fn with_source(self, source: impl Into<String>) -> EventEnvelope
设置来源服务
Sourcepub fn partition_key(&self) -> &str
pub fn partition_key(&self) -> &str
分区键引用(Kafka 等后端用于分区与顺序)
Sourcepub fn to_json_bytes(&self) -> Result<Vec<u8>, FlareError>
pub fn to_json_bytes(&self) -> Result<Vec<u8>, FlareError>
JSON 编码整封信封(历史兼容;不建议用于 MQ 热路径)。
Sourcepub fn to_proto_bytes(&self) -> Result<Vec<u8>, FlareError>
pub fn to_proto_bytes(&self) -> Result<Vec<u8>, FlareError>
protobuf 编码整封信封(推荐:低开销、体积小)。
需要启用 flare-server-core 的 proto feature。
Sourcepub fn from_proto_bytes(bytes: &[u8]) -> Result<EventEnvelope, FlareError>
pub fn from_proto_bytes(bytes: &[u8]) -> Result<EventEnvelope, FlareError>
从 protobuf bytes 解码信封。
需要启用 flare-server-core 的 proto feature。
Sourcepub fn is_operation(&self) -> bool
pub fn is_operation(&self) -> bool
可选约定:event_type 以 “operation.” 开头时视为操作类(可由业务自行约定或忽略)
Trait Implementations§
Source§impl Clone for EventEnvelope
impl Clone for EventEnvelope
Source§fn clone(&self) -> EventEnvelope
fn clone(&self) -> EventEnvelope
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 moreSource§impl Debug for EventEnvelope
impl Debug for EventEnvelope
Source§impl<'de> Deserialize<'de> for EventEnvelope
impl<'de> Deserialize<'de> for EventEnvelope
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<EventEnvelope, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<EventEnvelope, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for EventEnvelope
impl Display for EventEnvelope
Source§impl Serialize for EventEnvelope
impl Serialize for EventEnvelope
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for EventEnvelope
impl RefUnwindSafe for EventEnvelope
impl Send for EventEnvelope
impl Sync for EventEnvelope
impl Unpin for EventEnvelope
impl UnsafeUnpin for EventEnvelope
impl UnwindSafe for EventEnvelope
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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