Skip to main content

MessageBuilder

Struct MessageBuilder 

Source
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

Source

pub fn new() -> Self

Creates a new message builder.

Source

pub fn topic(self, topic: impl Into<CheetahString>) -> Self

Sets the topic name (required).

Source

pub fn body(self, body: impl Into<Bytes>) -> Self

Sets the message body from bytes.

Source

pub fn body_slice(self, body: &[u8]) -> Self

Sets the message body from a byte slice.

Source

pub fn empty_body(self) -> Self

Sets an empty body.

Source

pub fn tags(self, tags: impl Into<CheetahString>) -> Self

Sets the message tags.

Source

pub fn keys(self, keys: Vec<String>) -> Self

Sets the message keys from a vector.

Source

pub fn key(self, key: impl Into<CheetahString>) -> Self

Sets a single message key.

Source

pub fn flag(self, flag: MessageFlag) -> Self

Sets the message flag.

Source

pub fn flag_bits(self, bits: i32) -> Self

Sets the message flag from raw bits.

Source

pub fn delay_level(self, level: i32) -> Self

Sets the delay time level (1-18 for predefined levels).

Source

pub fn delay_secs(self, secs: u64) -> Self

Sets the delay time in seconds.

Source

pub fn delay_millis(self, millis: u64) -> Self

Sets the delay time in milliseconds.

Source

pub fn deliver_time_ms(self, time_ms: u64) -> Self

Sets the delivery time in milliseconds.

Source

pub fn wait_store_msg_ok(self, wait: bool) -> Self

Sets whether to wait for store confirmation.

Source

pub fn transaction_id(self, id: impl Into<CheetahString>) -> Self

Sets the transaction ID.

Source

pub fn buyer_id(self, buyer_id: impl Into<CheetahString>) -> Self

Sets the buyer ID.

Source

pub fn instance_id(self, instance_id: impl Into<CheetahString>) -> Self

Sets the instance ID.

Source

pub fn correlation_id(self, correlation_id: impl Into<CheetahString>) -> Self

Sets the correlation ID.

Source

pub fn sharding_key(self, sharding_key: impl Into<CheetahString>) -> Self

Sets the sharding key.

Source

pub fn trace_switch(self, enabled: bool) -> Self

Sets the trace switch.

Source

pub fn property( self, key: MessagePropertyKey, value: impl Into<CheetahString>, ) -> Self

Sets a custom property directly using MessagePropertyKey.

Source

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.

Source

pub fn build(self) -> RocketMQResult<Message>

Builds the message.

§Errors

Returns an error if required fields (topic) are not set.

Source

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.

Trait Implementations§

Source§

impl Default for MessageBuilder

Source§

fn default() -> MessageBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more