pub struct Consumer<'a> { /* fields omitted */ }
Expand description
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(())
}
Implementations
The server-assigned consumer tag.
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.
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.
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.
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.
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.
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.