Skip to main content

MQPushConsumer

Trait MQPushConsumer 

Source
pub trait MQPushConsumer: MQConsumer {
    // Required methods
    async fn start(&mut self) -> ClientResult<()>;
    async fn shutdown(&mut self);
    fn register_message_listener_concurrently<ML>(
        &mut self,
        message_listener: ML,
    )
       where ML: MessageListenerConcurrently + Send + Sync + 'static;
    fn register_message_listener_orderly<ML>(&mut self, message_listener: ML)
       where ML: MessageListenerOrderly + Send + Sync + 'static;
    async fn subscribe(
        &mut self,
        topic: impl Into<CheetahString>,
        sub_expression: impl Into<CheetahString>,
    ) -> ClientResult<()>;
    async fn subscribe_with_selector(
        &mut self,
        topic: &str,
        selector: Option<MessageSelector>,
    ) -> ClientResult<()>;
    async fn unsubscribe(&mut self, topic: &str);
    async fn suspend(&self);
    async fn resume(&self);

    // Provided method
    fn update_core_pool_size(&self, _core_pool_size: usize) -> ClientResult<()> { ... }
}
Expand description

Defines the push-consumer interface for RocketMQ.

Implementations receive messages from brokers and dispatch them to the registered concurrent or orderly listener.

Required Methods§

Source

async fn start(&mut self) -> ClientResult<()>

Asynchronously starts the consumer instance.

This method does not block the calling thread.

§Returns

Returns Ok(()) when startup succeeds, or an error when initialization fails.

Source

async fn shutdown(&mut self)

Asynchronously shuts down the consumer instance.

This method does not block the calling thread.

Source

fn register_message_listener_concurrently<ML>(&mut self, message_listener: ML)
where ML: MessageListenerConcurrently + Send + Sync + 'static,

Registers a message listener for concurrent message consumption.

§Parameters
  • message_listener - A closure that processes a batch of messages and returns a status.
§Type Parameters
  • ML - The listener type.
Source

fn register_message_listener_orderly<ML>(&mut self, message_listener: ML)
where ML: MessageListenerOrderly + Send + Sync + 'static,

Registers a message listener for orderly message consumption.

§Parameters
  • message_listener - A closure that processes a batch of messages and returns a status.
§Type Parameters
  • ML - The listener type.
Source

async fn subscribe( &mut self, topic: impl Into<CheetahString>, sub_expression: impl Into<CheetahString>, ) -> ClientResult<()>

Asynchronously subscribes to a topic with a subscription expression.

This method does not block the calling thread.

§Parameters
  • topic - The topic to subscribe to. Can be &str, String, or CheetahString.
  • sub_expression - The subscription expression. Can be &str, String, or CheetahString.
§Returns

Returns Ok(()) when the subscription is accepted, or an error when the subscription request is invalid or cannot be applied.

§Examples
ⓘ
// Using &str
consumer.subscribe("TopicTest", "*").await?;

// Using String
let topic = String::from("TopicTest");
consumer.subscribe(topic, "*").await?;

// Using CheetahString
let topic = CheetahString::from_slice("TopicTest");
consumer.subscribe(topic, "*").await?;
Source

async fn subscribe_with_selector( &mut self, topic: &str, selector: Option<MessageSelector>, ) -> ClientResult<()>

Asynchronously subscribes to a topic with an optional selector.

This method does not block the calling thread.

§Parameters
  • topic - The topic to subscribe to.
  • selector - An optional message selector.
§Returns

Returns Ok(()) when the subscription is accepted, or an error when the selector is invalid or cannot be applied.

Source

async fn unsubscribe(&mut self, topic: &str)

Asynchronously unsubscribes from a topic.

This method does not block the calling thread.

§Parameters
  • topic - The topic to unsubscribe from.
Source

async fn suspend(&self)

Asynchronously suspends message consumption.

This method does not block the calling thread.

Source

async fn resume(&self)

Asynchronously resumes message consumption.

This method does not block the calling thread.

Provided Methods§

Source

fn update_core_pool_size(&self, _core_pool_size: usize) -> ClientResult<()>

Updates the core size used by the concurrent consume worker pool.

Orderly consumers and implementations without a resizable worker pool may ignore this request.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§