class: RabbitMqChannel
[33:14] (extern: com.lehman.aussom.RabbitMqChannel) extends: object
A RabbitMQ channel: the heart of the AMQP 0-9-1 API. Exchange and queue operations, bindings, publishing, pull consumption, acknowledgements, QoS, publisher confirms, and transactions all happen on a channel. Open one with connection.openChannel(). Channels are not thread safe. Use each channel from one thread only - the same rule as the underlying client. Messages are routed by publishing to an exchange with a routing key; bindings decide which queues receive them. There are no broker-side selectors - routing keys and bindings do that job.
Methods
-
RabbitMqChannel ()
-
exchangeDeclare (
string Name, string Type = "direct", bool Durable = false, bool AutoDelete = false, bool Internal = false, map Args = null)Declares an exchange.
- @p
Nameis a string with the exchange name. - @p
Typeis a string with direct, fanout, topic, or headers (default direct). - @p
Durableis a bool with true to survive broker restart (default false). - @p
AutoDeleteis a bool with true to delete when unused (default false). - @p
Internalis a bool with true to refuse direct publishes (default false). - @p
Argsis a map with exchange arguments (optional). - @r
thisobject
- @p
-
exchangeDeclarePassive (
string Name)Checks that an exchange exists. Errors when it does not.
- @p
Nameis a string with the exchange name. - @r
thisobject
- @p
-
exchangeDelete (
string Name, bool IfUnused = false)Deletes an exchange.
- @p
Nameis a string with the exchange name. - @p
IfUnusedis a bool with true to only delete when unused (default false). - @r
thisobject
- @p
-
exchangeBind (
string Destination, string Source, string RoutingKey, map Args = null)Binds one exchange to another, so messages routed to Source flow on to Destination.
- @p
Destinationis a string with the destination exchange. - @p
Sourceis a string with the source exchange. - @p
RoutingKeyis a string with the binding key. - @p
Argsis a map with binding arguments (optional). - @r
thisobject
- @p
-
exchangeUnbind (
string Destination, string Source, string RoutingKey, map Args = null)Removes an exchange-to-exchange binding.
- @p
Destinationis a string with the destination exchange. - @p
Sourceis a string with the source exchange. - @p
RoutingKeyis a string with the binding key. - @p
Argsis a map with binding arguments (optional). - @r
thisobject
- @p
-
queueDeclare (
string Name = "", bool Durable = false, bool Exclusive = false, bool AutoDelete = false, map Args = null)Declares a queue and returns its name. An empty name asks the broker for a server-named exclusive auto-delete queue (the standard reply-queue idiom). The Args map carries every x- feature: x-message-ttl, x-expires, x-max-length, x-dead-letter-exchange, x-dead-letter-routing-key, x-max-priority, x-queue-type (classic/quorum/stream), and x-single-active-consumer. RabbitMQ 4.2+ denies transient (non-durable) non-exclusive queues by default, so declare named queues durable unless they are exclusive.
- @p
Nameis a string with the queue name (default "" for server-named). - @p
Durableis a bool with true to survive broker restart (default false). - @p
Exclusiveis a bool with true to scope the queue to this connection (default false). - @p
AutoDeleteis a bool with true to delete when the last consumer goes away (default false). - @p
Argsis a map with queue arguments (optional). - @r
Astring with the queue name.
- @p
-
queueDeclarePassive (
string Name)Checks that a queue exists. Errors when it does not.
- @p
Nameis a string with the queue name. - @r
Amap with queue, messageCount, and consumerCount.
- @p
-
queueDelete (
string Name, bool IfUnused = false, bool IfEmpty = false)Deletes a queue.
- @p
Nameis a string with the queue name. - @p
IfUnusedis a bool with true to only delete without consumers (default false). - @p
IfEmptyis a bool with true to only delete when empty (default false). - @r
Anint with the count of messages deleted with the queue.
- @p
-
queuePurge (
string Name)Removes all ready messages from a queue.
- @p
Nameis a string with the queue name. - @r
Anint with the count of messages removed.
- @p
-
queueBind (
string Queue, string Exchange, string RoutingKey, map Args = null)Binds a queue to an exchange with a routing key.
- @p
Queueis a string with the queue name. - @p
Exchangeis a string with the exchange name. - @p
RoutingKeyis a string with the binding key (topic exchanges match * for one word and # for zero or more). - @p
Argsis a map with binding arguments - headers exchanges take the match table here, including x-match all/any (optional). - @r
thisobject
- @p
-
queueUnbind (
string Queue, string Exchange, string RoutingKey, map Args = null)Removes a queue-to-exchange binding.
- @p
Queueis a string with the queue name. - @p
Exchangeis a string with the exchange name. - @p
RoutingKeyis a string with the binding key. - @p
Argsis a map with binding arguments (optional). - @r
thisobject
- @p
-
messageCount (
string Queue)Counts the ready messages on a queue.
- @p
Queueis a string with the queue name. - @r
Anint with the message count.
- @p
-
consumerCount (
string Queue)Counts the consumers on a queue.
- @p
Queueis a string with the queue name. - @r
Anint with the consumer count.
- @p
-
publish (
string Exchange, string RoutingKey, Msg, bool Mandatory = false)Publishes a message. The message is a RabbitMqMessage object, a plain string (text body with no properties), or a map in the message-map shape (body, persistent, correlationId, headers, and so on). An empty exchange name is the default exchange: the routing key is then the destination queue name. Mandatory publishes that no queue could route come back through pollReturned().
- @p
Exchangeis a string with the exchange name ("" for the default exchange). - @p
RoutingKeyis a string with the routing key. - @p
Msgis the message (RabbitMqMessage, string, or map). - @p
Mandatoryis a bool with true to return unroutable messages (default false). - @r
thisobject
- @p
-
pollReturned (
int TimeoutMs = 0)Drains one returned (unroutable mandatory) message.
- @p
TimeoutMsis an int with how long to wait (default 0 = no wait). - @r
ARabbitMqMessage object, or null when none is pending.
- @p
-
get (
string Queue, bool AutoAck = true)Pulls one message from a queue without a consumer.
- @p
Queueis a string with the queue name. - @p
AutoAckis a bool with true to acknowledge on delivery (default true). With false, ack through the message or this channel. - @r
ARabbitMqMessage object, or null when the queue is empty.
- @p
-
ack (
int DeliveryTag, bool Multiple = false)Acknowledges a delivery by tag.
- @p
DeliveryTagis an int with the delivery tag. - @p
Multipleis a bool with true to acknowledge everything up to and including the tag (default false). - @r
thisobject
- @p
-
nack (
int DeliveryTag, bool Requeue = true, bool Multiple = false)Negatively acknowledges a delivery by tag.
- @p
DeliveryTagis an int with the delivery tag. - @p
Requeueis a bool with true to put the message back on the queue, false to drop or dead-letter it (default true). - @p
Multipleis a bool with true to nack everything up to and including the tag (default false). - @r
thisobject
- @p
-
reject (
int DeliveryTag, bool Requeue = true)Rejects a delivery by tag.
- @p
DeliveryTagis an int with the delivery tag. - @p
Requeueis a bool with true to put the message back on the queue (default true). - @r
thisobject
- @p
-
recover (
bool Requeue = true)Asks the broker to redeliver this channel's unacknowledged messages.
- @p
Requeueis a bool with true to allow delivery to other consumers (default true). - @r
thisobject
- @p
-
qos (
int PrefetchCount, bool Global = false)Sets the prefetch window: how many unacknowledged messages the broker sends before waiting for acks. The back-pressure knob for manual-ack consumers.
- @p
PrefetchCountis an int with the window size. - @p
Globalis a bool with true to share the window across the channel's consumers (default false). - @r
thisobject
- @p
-
confirmSelect ()
Puts this channel in publisher-confirm mode, so the broker acknowledges publishes. Mutually exclusive with transactions.
- @r
thisobject
- @r
-
getNextPublishSeqNo ()
Gets the sequence number the next publish will get, for correlating confirms.
- @r
Anint with the next publish sequence number.
- @r
-
waitForConfirms (
int TimeoutMs = 0)Waits until every publish since confirmSelect() was confirmed.
- @p
TimeoutMsis an int with how long to wait (default 0 = forever). - @r
Abool with true when all confirmed, false when the broker nacked any.
- @p
-
waitForConfirmsOrDie (
int TimeoutMs = 0)Like waitForConfirms() but errors on a broker nack or timeout.
- @p
TimeoutMsis an int with how long to wait (default 0 = forever). - @r
thisobject
- @p
-
txSelect ()
Puts this channel in transaction mode: publishes and acks batch until txCommit() or txRollback(). Mutually exclusive with publisher confirms.
- @r
thisobject
- @r
-
txCommit ()
Commits the open transaction.
- @r
thisobject
- @r
-
txRollback ()
Rolls the open transaction back, discarding batched publishes and acks.
- @r
thisobject
- @r
-
consume (
string Queue, bool AutoAck = false, string ConsumerTag = "", bool Exclusive = false, map Args = null)Starts a push consumer on a queue. With AutoAck false (the default), call qos() first so the prefetch window bounds the in-flight messages.
- @p
Queueis a string with the queue name. - @p
AutoAckis a bool with true to acknowledge on delivery (default false). - @p
ConsumerTagis a string with the consumer tag (default "" for broker-assigned). - @p
Exclusiveis a bool with true for an exclusive consumer (default false). - @p
Argsis a map with consumer arguments such as x-priority (optional). - @r
Anew RabbitMqConsumer object.
- @p
-
isOpen ()
Reports whether the channel is open. Protocol errors (for example acking an unknown tag) close the channel.
- @r
Abool with true while open.
- @r
-
getChannelNumber ()
Gets this channel's number on its connection.
- @r
Anint with the channel number.
- @r
-
close ()
Closes the channel. Safe to call more than once.
- @r
thisobject
- @r