Channel

Struct Channel 

Source
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

Source

pub async fn register_callback<F>(&self, callback: F) -> Result<(), Error>
where F: ChannelCallback + Send + 'static,

Register callbacks for asynchronous message for the channel.

User should always register callbacks. See callbacks documentation.

§Errors

Returns error if fail to send registration command. If returns Err, user can try again until registration succeed.

Source

pub fn channel_id(&self) -> u16

Source

pub fn connection_name(&self) -> &str

Source

pub fn is_connection_open(&self) -> bool

Source

pub fn is_open(&self) -> bool

Returns true if channel is open.

Source

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.

Source

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.

Source

pub async fn basic_qos(&self, args: BasicQosArguments) -> Result<(), Error>

See AMQP_0-9-1 Reference

§Errors

Returns error if any failure in comunication with server.

Source

pub async fn basic_consume<F>( &self, consumer: F, args: BasicConsumeArguments, ) -> Result<String, Error>
where F: AsyncConsumer + Send + 'static,

See AMQP_0-9-1 Reference

Returns the consumer tag on success.

§Errors

Returns an error if a failure occurs while comunicating with the server.

Source

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.

Source

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.

Source

pub async fn basic_ack(&self, args: BasicAckArguments) -> Result<(), Error>

See AMQP_0-9-1 Reference

§Errors

Returns error if any failure in comunication with server.

Source

pub fn basic_ack_blocking(&self, args: BasicAckArguments) -> Result<(), Error>

Blocking version of basic_ack, should be invoked in blocking context.

§Panics

Panic if invoked in async context.

§Errors

Returns error if any failure in comunication with server.

Source

pub async fn basic_nack(&self, args: BasicNackArguments) -> Result<(), Error>

See AMQP_0-9-1 Reference

§Errors

Returns error if any failure in comunication with server.

Source

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.

Source

pub async fn basic_reject( &self, args: BasicRejectArguments, ) -> Result<(), Error>

See AMQP_0-9-1 Reference

§Errors

Returns error if any failure in comunication with server.

Source

pub fn basic_reject_blocking( &self, args: BasicRejectArguments, ) -> Result<(), Error>

Blocking version of basic_reject

§Errors

Returns error if any failure in comunication with server.

Source

pub async fn basic_cancel( &self, args: BasicCancelArguments, ) -> Result<String, Error>

See AMQP_0-9-1 Reference

Returns consumer tag if succeed.

§Errors

Returns error if any failure in comunication with server.

Source

pub async fn basic_get( &self, args: BasicGetArguments, ) -> Result<Option<(GetOk, BasicProperties, Vec<u8>)>, Error>

See AMQP_0-9-1 Reference

Either returns a tuple GetMessage or None if no message available.

§Errors

Returns error if any failure in comunication with server.

Source

pub async fn basic_recover(&self, requeue: bool) -> Result<(), Error>

See AMQP_0-9-1 Reference

§Errors

Returns error if any failure in comunication with server.

Source

pub async fn basic_publish( &self, basic_properties: BasicProperties, content: Vec<u8>, args: BasicPublishArguments, ) -> Result<(), Error>

See AMQP_0-9-1 Reference

§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.

Source

pub async fn confirm_select( &self, args: ConfirmSelectArguments, ) -> Result<(), Error>

See AMQP_0-9-1 Reference.

§Errors

Returns error if any failure in comunication with server.

Source§

impl Channel

APIs for AMQP exchange class

Source

pub async fn exchange_declare( &self, args: ExchangeDeclareArguments, ) -> Result<(), Error>

See AMQP_0-9-1 Reference

§Errors

Returns error if any failure in comunication with server.

Source

pub async fn exchange_delete( &self, args: ExchangeDeleteArguments, ) -> Result<(), Error>

See AMQP_0-9-1 Reference

§Errors

Returns error if any failure in comunication with server.

Source

pub async fn exchange_bind( &self, args: ExchangeBindArguments, ) -> Result<(), Error>

See AMQP_0-9-1 Reference

§Errors

Returns error if any failure in comunication with server.

Source

pub async fn exchange_unbind( &self, args: ExchangeUnbindArguments, ) -> Result<(), Error>

See AMQP_0-9-1 Reference

§Errors

Returns error if any failure in comunication with server.

Source§

impl Channel

APIs for AMQP queue class.

Source

pub async fn queue_declare( &self, args: QueueDeclareArguments, ) -> Result<Option<(String, u32, u32)>, Error>

See AMQP_0-9-1 Reference

If succeed, returns Ok with a optional tuple.

Returns a tuple (queue_name, message_count, consumer_count) if no_wait argument is false, otherwise returns None.

§Errors

Returns error if any failure in comunication with server.

Source

pub async fn queue_bind(&self, args: QueueBindArguments) -> Result<(), Error>

See AMQP_0-9-1 Reference

§Errors

Returns error if any failure in comunication with server.

Source

pub async fn queue_purge( &self, args: QueuePurgeArguments, ) -> Result<Option<u32>, Error>

See AMQP_0-9-1 Reference

If succeed, returns Ok with a optional message count.

Returns message count if no_wait argument is false, otherwise returns None.

§Errors

Returns error if any failure in comunication with server.

Source

pub async fn queue_delete( &self, args: QueueDeleteArguments, ) -> Result<Option<u32>, Error>

See AMQP_0-9-1 Reference

If succeed, returns Ok with a optional message count.

Returns message count if no_wait argument is false, otherwise returns None.

§Errors

Returns error if any failure in comunication with server.

Source

pub async fn queue_unbind( &self, args: QueueUnbindArguments, ) -> Result<(), Error>

See AMQP_0-9-1 Reference

§Errors

Returns error if any failure in comunication with server.

Source§

impl Channel

APIs for AMQP transaction class.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Channel

Source§

fn clone(&self) -> Channel

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Display for Channel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.