Struct rocketmq::SimpleConsumer
source · pub struct SimpleConsumer { /* private fields */ }
Expand description
SimpleConsumer
is a lightweight consumer to consume messages from RocketMQ proxy.
If you want to fully control the message consumption operation by yourself, the simple consumer should be your first consideration.
SimpleConsumer
is a thin wrapper of internal client struct that shoulders the actual workloads.
Most of its methods take shared reference so that application developers may use it at will.
SimpleConsumer
is Send
and Sync
by design, so that developers may get started easily.
Implementations§
source§impl SimpleConsumer
impl SimpleConsumer
sourcepub fn new(
option: SimpleConsumerOption,
client_option: ClientOption
) -> Result<Self, ClientError>
pub fn new( option: SimpleConsumerOption, client_option: ClientOption ) -> Result<Self, ClientError>
Create a new simple consumer instance
sourcepub async fn start(&mut self) -> Result<(), ClientError>
pub async fn start(&mut self) -> Result<(), ClientError>
Start the simple consumer
pub async fn shutdown(self) -> Result<(), ClientError>
sourcepub async fn receive(
&self,
topic: impl AsRef<str>,
expression: &FilterExpression
) -> Result<Vec<MessageView>, ClientError>
pub async fn receive( &self, topic: impl AsRef<str>, expression: &FilterExpression ) -> Result<Vec<MessageView>, ClientError>
receive messages from the specified topic
Arguments
topic
- the topic for receiving messagesexpression
- the subscription for the topic
sourcepub async fn receive_with(
&self,
topic: impl AsRef<str>,
expression: &FilterExpression,
batch_size: i32,
invisible_duration: Duration
) -> Result<Vec<MessageView>, ClientError>
pub async fn receive_with( &self, topic: impl AsRef<str>, expression: &FilterExpression, batch_size: i32, invisible_duration: Duration ) -> Result<Vec<MessageView>, ClientError>
receive messages from the specified topic with batch size and invisible duration
Arguments
topic
- the topic for receiving messagesexpression
- the subscription for the topicbatch_size
- max message num of server returnedinvisible_duration
- set the invisible duration of messages that return from the server, these messages will not be visible to other consumers unless timeout
sourcepub async fn ack(
&self,
ack_entry: &(impl AckMessageEntry + 'static)
) -> Result<(), ClientError>
pub async fn ack( &self, ack_entry: &(impl AckMessageEntry + 'static) ) -> Result<(), ClientError>
Ack the specified message
It is important to acknowledge every consumed message, otherwise, they will be received again after the invisible duration
Arguments
ack_entry
- special message view with handle want to ack
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for SimpleConsumer
impl Send for SimpleConsumer
impl Sync for SimpleConsumer
impl Unpin for SimpleConsumer
impl !UnwindSafe for SimpleConsumer
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
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request