pub struct Channel { /* private fields */ }Expand description
Type represents an AMQP Channel.
First, create a new AMQP channel by Connection's method Connection::open_channel.
Second, register callbacks for the channel by Channel::register_callback.
Then, the channel is ready to use.
§Concurrency
It is not recommended to share same Channel object between tasks/threads, because it allows
interleaving the AMQP protocol messages in same channel in concurrent setup.
Applications should be aware of the this limitation in AMQP protocol itself.
See detailed explanation in Java Client, it applies to the library also.
Implementations§
Source§impl Channel
impl Channel
Sourcepub async fn register_callback<F>(&self, callback: F) -> Result<(), Error>where
F: ChannelCallback + Send + 'static,
pub async fn register_callback<F>(&self, callback: F) -> Result<(), Error>where
F: ChannelCallback + Send + 'static,
pub fn channel_id(&self) -> u16
pub fn connection_name(&self) -> &str
pub fn is_connection_open(&self) -> bool
Sourcepub async fn flow(&self, active: bool) -> Result<bool, Error>
pub async fn flow(&self, active: bool) -> Result<bool, Error>
Asks the server to pause or restart the flow of content data.
Ask to start the flow if input active = true, otherwise to pause.
Also see AMQP_0-9-1 Reference.
Returns true means the server will start/continue the flow, otherwise it will not.
§Errors
Returns error if any failure in communication with server.
Sourcepub async fn close(self) -> Result<(), Error>
pub async fn close(self) -> Result<(), Error>
Ask the server to close the channel.
To gracefully shutdown the channel, recommended to close the
channel explicitly instead of relying on drop.
This method consume the channel, so even it may return error, channel will anyway be dropped.
§Errors
Returns error if any failure in communication with server.
Fail to close the channel may result in channel leak in server.
Source§impl Channel
APIs for AMQP basic class.
impl Channel
APIs for AMQP basic class.
Sourcepub async fn basic_consume<F>(
&self,
consumer: F,
args: BasicConsumeArguments,
) -> Result<String, Error>where
F: AsyncConsumer + Send + 'static,
pub async fn basic_consume<F>(
&self,
consumer: F,
args: BasicConsumeArguments,
) -> Result<String, Error>where
F: AsyncConsumer + Send + 'static,
Returns the consumer tag on success.
§Errors
Returns an error if a failure occurs while comunicating with the server.
Sourcepub async fn basic_consume_blocking<F>(
&self,
consumer: F,
args: BasicConsumeArguments,
) -> Result<String, Error>where
F: BlockingConsumer + Send + 'static,
pub async fn basic_consume_blocking<F>(
&self,
consumer: F,
args: BasicConsumeArguments,
) -> Result<String, Error>where
F: BlockingConsumer + Send + 'static,
Similar as basic_consume but run the consumer in a blocking context.
Returns the consumer tag on success.
§Errors
Returns an error if a failure occurs while comunicating with the server.
Sourcepub async fn basic_consume_rx(
&self,
args: BasicConsumeArguments,
) -> Result<(String, UnboundedReceiver<ConsumerMessage>), Error>
pub async fn basic_consume_rx( &self, args: BasicConsumeArguments, ) -> Result<(String, UnboundedReceiver<ConsumerMessage>), Error>
Similar to basic_consume but returns the raw unbounded UnboundedReceiver
Returns the consumer tag and the UnboundedReceiver on success.
If you were to stop consuming before the channel has been closed internally,
you must call basic_cancel to make sure resources are cleaned up properly.
if no-ack is false, basic_qos can be used to throttle the incoming flow from server.
If no-ack is true, the prefetch-size and prefetch-count are ignored, flow control
on application level maybe need to be introduced, othersie it relies on TCP backpresure.
let args = BasicConsumeArguments::new(&queue_name, "basic_consumer")
.manual_ack(false)
.finish();
let (ctag, mut messages_rx) = channel.basic_consume_rx(args).await.unwrap();
// you will need to run this in `tokio::spawn` or `tokio::task::spawn_blocking`
// if you want to do other things in parallel of message consumption.
while let Some(msg) = messages_rx.recv().await {
// do smthing with msg
}
// Only needed when `messages_rx.recv().await` hasn't yet returned `None`
if let Err(e) = channel.basic_cancel(BasicCancelArguments::new(&ctag)).await {
// handle err
};§Errors
Returns an error if a failure occurs while comunicating with the server.
Sourcepub fn basic_ack_blocking(&self, args: BasicAckArguments) -> Result<(), Error>
pub fn basic_ack_blocking(&self, args: BasicAckArguments) -> Result<(), Error>
Sourcepub async fn basic_nack(&self, args: BasicNackArguments) -> Result<(), Error>
pub async fn basic_nack(&self, args: BasicNackArguments) -> Result<(), Error>
Sourcepub fn basic_nack_blocking(&self, args: BasicNackArguments) -> Result<(), Error>
pub fn basic_nack_blocking(&self, args: BasicNackArguments) -> Result<(), Error>
Blocking version of basic_nack, should be invoked in blocking context.
§Panics
Panic if invoked in async context.
§Errors
Returns error if any failure in comunication with server.
Sourcepub async fn basic_reject(
&self,
args: BasicRejectArguments,
) -> Result<(), Error>
pub async fn basic_reject( &self, args: BasicRejectArguments, ) -> Result<(), Error>
Sourcepub fn basic_reject_blocking(
&self,
args: BasicRejectArguments,
) -> Result<(), Error>
pub fn basic_reject_blocking( &self, args: BasicRejectArguments, ) -> Result<(), Error>
Sourcepub async fn basic_cancel(
&self,
args: BasicCancelArguments,
) -> Result<String, Error>
pub async fn basic_cancel( &self, args: BasicCancelArguments, ) -> Result<String, Error>
Sourcepub async fn basic_get(
&self,
args: BasicGetArguments,
) -> Result<Option<(GetOk, BasicProperties, Vec<u8>)>, Error>
pub async fn basic_get( &self, args: BasicGetArguments, ) -> Result<Option<(GetOk, BasicProperties, Vec<u8>)>, Error>
Either returns a tuple GetMessage or None if no message available.
§Errors
Returns error if any failure in comunication with server.
Sourcepub async fn basic_publish(
&self,
basic_properties: BasicProperties,
content: Vec<u8>,
args: BasicPublishArguments,
) -> Result<(), Error>
pub async fn basic_publish( &self, basic_properties: BasicProperties, content: Vec<u8>, args: BasicPublishArguments, ) -> Result<(), Error>
§Errors
Returns error in case of a network I/O failure. For data safety, use publisher confirms.
Source§impl Channel
APIs for AMQP confirm class.
impl Channel
APIs for AMQP confirm class.
Sourcepub async fn confirm_select(
&self,
args: ConfirmSelectArguments,
) -> Result<(), Error>
pub async fn confirm_select( &self, args: ConfirmSelectArguments, ) -> Result<(), Error>
Source§impl Channel
APIs for AMQP exchange class
impl Channel
APIs for AMQP exchange class
Sourcepub async fn exchange_declare(
&self,
args: ExchangeDeclareArguments,
) -> Result<(), Error>
pub async fn exchange_declare( &self, args: ExchangeDeclareArguments, ) -> Result<(), Error>
Sourcepub async fn exchange_delete(
&self,
args: ExchangeDeleteArguments,
) -> Result<(), Error>
pub async fn exchange_delete( &self, args: ExchangeDeleteArguments, ) -> Result<(), Error>
Sourcepub async fn exchange_bind(
&self,
args: ExchangeBindArguments,
) -> Result<(), Error>
pub async fn exchange_bind( &self, args: ExchangeBindArguments, ) -> Result<(), Error>
Sourcepub async fn exchange_unbind(
&self,
args: ExchangeUnbindArguments,
) -> Result<(), Error>
pub async fn exchange_unbind( &self, args: ExchangeUnbindArguments, ) -> Result<(), Error>
Source§impl Channel
APIs for AMQP queue class.
impl Channel
APIs for AMQP queue class.
Sourcepub async fn queue_declare(
&self,
args: QueueDeclareArguments,
) -> Result<Option<(String, u32, u32)>, Error>
pub async fn queue_declare( &self, args: QueueDeclareArguments, ) -> Result<Option<(String, u32, u32)>, Error>
Sourcepub async fn queue_bind(&self, args: QueueBindArguments) -> Result<(), Error>
pub async fn queue_bind(&self, args: QueueBindArguments) -> Result<(), Error>
Sourcepub async fn queue_purge(
&self,
args: QueuePurgeArguments,
) -> Result<Option<u32>, Error>
pub async fn queue_purge( &self, args: QueuePurgeArguments, ) -> Result<Option<u32>, Error>
Sourcepub async fn queue_delete(
&self,
args: QueueDeleteArguments,
) -> Result<Option<u32>, Error>
pub async fn queue_delete( &self, args: QueueDeleteArguments, ) -> Result<Option<u32>, Error>
Sourcepub async fn queue_unbind(
&self,
args: QueueUnbindArguments,
) -> Result<(), Error>
pub async fn queue_unbind( &self, args: QueueUnbindArguments, ) -> Result<(), Error>
Source§impl Channel
APIs for AMQP transaction class.
impl Channel
APIs for AMQP transaction class.
Sourcepub async fn tx_select(&self) -> Result<(), Error>
pub async fn tx_select(&self) -> Result<(), Error>
This method sets the channel to use standard transactions. The client must use this
method at least once on a channel before using the tx_commit or tx_rollback methods.
Also see AMQP_0-9-1 Reference.
§Errors
Returns error if any failure in communication with server.
Sourcepub async fn tx_commit(&self) -> Result<(), Error>
pub async fn tx_commit(&self) -> Result<(), Error>
This method commits all message publications and acknowledgments performed in the current transaction. A new transaction starts immediately after a commit.
Also see AMQP_0-9-1 Reference.
§Errors
Returns error if any failure in communication with server.
Sourcepub async fn tx_rollback(&self) -> Result<(), Error>
pub async fn tx_rollback(&self) -> Result<(), Error>
This method abandons all message publications and acknowledgments performed in the current transaction. A new transaction starts immediately after a rollback. Note that unacked messages will not be automatically redelivered by rollback; if that is required an explicit recover call should be issued.
Also see AMQP_0-9-1 Reference.
§Errors
Returns error if any failure in communication with server.