pub struct MessageBuilder { /* private fields */ }Expand description
Builder for constructing messages.
§Examples
use rocketmq_common::common::message::message_builder::MessageBuilder;
let msg = MessageBuilder::new()
.topic("test-topic")
.body_slice(b"hello world")
.tags("important")
.keys(vec!["key1".to_string(), "key2".to_string()])
.build();Implementations§
Source§impl MessageBuilder
impl MessageBuilder
Sourcepub fn topic(self, topic: impl Into<CheetahString>) -> Self
pub fn topic(self, topic: impl Into<CheetahString>) -> Self
Sets the topic name (required).
Sourcepub fn body_slice(self, body: &[u8]) -> Self
pub fn body_slice(self, body: &[u8]) -> Self
Sets the message body from a byte slice.
Sourcepub fn empty_body(self) -> Self
pub fn empty_body(self) -> Self
Sets an empty body.
Sets the message tags.
Sourcepub fn key(self, key: impl Into<CheetahString>) -> Self
pub fn key(self, key: impl Into<CheetahString>) -> Self
Sets a single message key.
Sourcepub fn flag(self, flag: MessageFlag) -> Self
pub fn flag(self, flag: MessageFlag) -> Self
Sets the message flag.
Sourcepub fn delay_level(self, level: i32) -> Self
pub fn delay_level(self, level: i32) -> Self
Sets the delay time level (1-18 for predefined levels).
Sourcepub fn delay_secs(self, secs: u64) -> Self
pub fn delay_secs(self, secs: u64) -> Self
Sets the delay time in seconds.
Sourcepub fn delay_millis(self, millis: u64) -> Self
pub fn delay_millis(self, millis: u64) -> Self
Sets the delay time in milliseconds.
Sourcepub fn deliver_time_ms(self, time_ms: u64) -> Self
pub fn deliver_time_ms(self, time_ms: u64) -> Self
Sets the delivery time in milliseconds.
Sourcepub fn wait_store_msg_ok(self, wait: bool) -> Self
pub fn wait_store_msg_ok(self, wait: bool) -> Self
Sets whether to wait for store confirmation.
Sourcepub fn transaction_id(self, id: impl Into<CheetahString>) -> Self
pub fn transaction_id(self, id: impl Into<CheetahString>) -> Self
Sets the transaction ID.
Sourcepub fn buyer_id(self, buyer_id: impl Into<CheetahString>) -> Self
pub fn buyer_id(self, buyer_id: impl Into<CheetahString>) -> Self
Sets the buyer ID.
Sourcepub fn instance_id(self, instance_id: impl Into<CheetahString>) -> Self
pub fn instance_id(self, instance_id: impl Into<CheetahString>) -> Self
Sets the instance ID.
Sourcepub fn correlation_id(self, correlation_id: impl Into<CheetahString>) -> Self
pub fn correlation_id(self, correlation_id: impl Into<CheetahString>) -> Self
Sets the correlation ID.
Sourcepub fn sharding_key(self, sharding_key: impl Into<CheetahString>) -> Self
pub fn sharding_key(self, sharding_key: impl Into<CheetahString>) -> Self
Sets the sharding key.
Sourcepub fn trace_switch(self, enabled: bool) -> Self
pub fn trace_switch(self, enabled: bool) -> Self
Sets the trace switch.
Sourcepub fn property(
self,
key: MessagePropertyKey,
value: impl Into<CheetahString>,
) -> Self
pub fn property( self, key: MessagePropertyKey, value: impl Into<CheetahString>, ) -> Self
Sets a custom property directly using MessagePropertyKey.
Sourcepub fn raw_property(
self,
key: impl Into<CheetahString>,
value: impl Into<CheetahString>,
) -> RocketMQResult<Self>
pub fn raw_property( self, key: impl Into<CheetahString>, value: impl Into<CheetahString>, ) -> RocketMQResult<Self>
Sets a raw property with string key (for advanced use).
§Errors
Returns an error if the property name is reserved by the system.
Sourcepub fn build(self) -> RocketMQResult<Message>
pub fn build(self) -> RocketMQResult<Message>
Sourcepub fn build_unchecked(self) -> Message
pub fn build_unchecked(self) -> Message
Builds the message, panicking if validation fails.
This is convenient for test code where you know the message is valid.