[][src]Struct amiquip::Consumer

pub struct Consumer<'a> { /* fields omitted */ }

A message consumer associated with an AMQP queue.

Example

use amiquip::{Consumer, ConsumerMessage, Result};

// Receive (at least) n messages on the consumer, then cancel it.
fn consume_n_messages(consumer: Consumer, n: usize) -> Result<()> {
    for (i, message) in consumer.receiver().iter().enumerate() {
        match message {
            ConsumerMessage::Delivery(delivery) => handle_delivery(delivery),
            ConsumerMessage::ServerClosedChannel(err)
            | ConsumerMessage::ServerClosedConnection(err) => return Err(err)?,
            ConsumerMessage::ClientCancelled
            | ConsumerMessage::ServerCancelled
            | ConsumerMessage::ClientClosedChannel
            | ConsumerMessage::ClientClosedConnection => break,
        }
        if i >= n {
            consumer.cancel()?;
        }
    }
    Ok(())
}

Methods

impl<'_> Consumer<'_>[src]

pub fn consumer_tag(&self) -> &str[src]

The server-assigned consumer tag.

pub fn receiver(&self) -> &Receiver<ConsumerMessage>[src]

The crossbeam_channel::Receiver on which messages will be delivered. Once a consumer message of any variant other than ConsumerMessage has been received, no more messages will be sent and the sending side of the channel (held by the connection's I/O thread) will be dropped.

Note on Cloning

Crossbeam channels implement Clone. Be careful cloning this receiver, as the sending side (held by the connection's I/O thread) will be dropped when self is cancelled, which will happen when cancel is called or self is dropped.

pub fn cancel(&self) -> Result<()>[src]

Cancel this consumer.

When the cancellation is acknowledged by the server, the channel returned by receiver will receive a ConsumerMessage::ClientCancelled message. This method does not consume self because this method is inherently racy; the server may be sending us additional messages as we are attempting to cancel.

Calling this method a second or later time will always return Ok; if you care about cancellation errors, you must capture the Err value on the first call.

pub fn ack(&self, delivery: Delivery) -> Result<()>[src]

Calls Delivery::ack on delivery using the channel that contains this consumer. See the note on that method about taking care not to ack deliveries across channels.

pub fn ack_multiple(&self, delivery: Delivery) -> Result<()>[src]

Calls Delivery::ack_multiple on delivery using the channel that contains this consumer. See the note on that method about taking care not to ack deliveries across channels.

pub fn nack(&self, delivery: Delivery, requeue: bool) -> Result<()>[src]

Calls Delivery::nack on delivery using the channel that contains this consumer. See the note on that method about taking care not to nack deliveries across channels.

pub fn nack_multiple(&self, delivery: Delivery, requeue: bool) -> Result<()>[src]

Calls Delivery::nack_multiple on delivery using the channel that contains this consumer. See the note on that method about taking care not to nack deliveries across channels.

pub fn reject(&self, delivery: Delivery, requeue: bool) -> Result<()>[src]

Calls Delivery::reject on delivery using the channel that contains this consumer. See the note on that method about taking care not to reject deliveries across channels.

Trait Implementations

impl<'_> Drop for Consumer<'_>[src]

Auto Trait Implementations

impl<'a> !Send for Consumer<'a>

impl<'a> !Sync for Consumer<'a>

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.