False if the channel is closed
Readonly
idAcknowledge one or more messages.
Optional
deliveryThe server-assigned and channel-specific delivery tag
Optional
multiple?: booleanIf set to 1, the delivery tag is treated as "up to and including", so that multiple messages can be acknowledged with a single method. If set to zero, the delivery tag refers to a single message. If the multiple field is 1, and the delivery tag is zero, this indicates acknowledgement of all outstanding messages.
Stop a consumer.
This is a low-level method; consider using Connection#createConsumer() instead.
Begin consuming messages from a queue. Consumers last as long as the
channel they were declared on, or until the client cancels them. The
callback cb(msg)
is called for each incoming message. You must call
basicAck to complete the delivery, usually after you've
finished some task.
Optional
arguments?: { Optional
x-Optional
x-Optional
consumerSpecifies the identifier for the consumer. The consumer tag is local to a channel, so two clients can use the same consumer tags. If this field is empty the server will generate a unique tag.
Optional
exclusive?: booleanRequest exclusive consumer access, meaning only this consumer can access the queue.
Optional
noIf this field is set the server does not expect acknowledgements for messages. That is, when a message is delivered to the client the server assumes the delivery will succeed and immediately dequeues it. This functionality may increase performance but at the cost of reliability. Messages can get lost if a client dies before they are delivered to the application.
Optional
noIf the no-local field is set the server will not send messages to the connection that published them.
Optional
queue?: stringSpecifies the name of the queue to consume from. If blank then the last declared queue (on the channel) will be used.
Request a single message from a queue
Optional
noIf this field is set the server does not expect acknowledgements for messages. That is, when a message is delivered to the client the server assumes the delivery will succeed and immediately dequeues it. This functionality may increase performance but at the cost of reliability. Messages can get lost if a client dies before they are delivered to the application.
Optional
queue?: stringSpecifies the name of the queue to consume from.
Reject one or more incoming messages.
Optional
deliveryOptional
multiple?: booleanIf set to 1, the delivery tag is treated as "up to and including", so that multiple messages can be rejected with a single method. If set to zero, the delivery tag refers to a single message. If the multiple field is 1, and the delivery tag is zero, this indicates rejection of all outstanding messages.
Optional
requeue?: booleanIf requeue is true, the server will attempt to requeue the message. If requeue is false or the requeue attempt fails the messages are discarded or dead-lettered. The default should be TRUE, according to the AMQP specification, however this can lead to an endless retry-loop if you're not careful. Messages consumed from a quorum queue will have the "x-delivery-count" header, allowing you to discard a message after too many attempted deliveries. For classic mirrored queues, or non-mirrored queues, you will need to construct your own mechanism for discarding poison messages.
true
This method publishes a message to a specific exchange. The message will be routed to queues as defined by the exchange configuration.
If the body is a string then it will be serialized with contentType='text/plain'. If body is an object then it will be serialized with contentType='application/json'. Buffer objects are unchanged.
If publisher-confirms are enabled, then this will resolve when the acknowledgement is received. Otherwise this will resolve after writing to the TCP socket, which is usually immediate. Note that if you keep publishing while the connection is blocked (see Connection#on('connection.blocked')) then the TCP socket buffer will eventually fill and this method will no longer resolve immediately.
Send directly to a queue. Same as basicPublish({routingKey: queue}, body)
Specify quality of service.
Optional
global?: booleanRabbitMQ has reinterpreted this field. The original specification said: "By default the QoS settings apply to the current channel only. If this field is set, they are applied to the entire connection." Instead, RabbitMQ takes global=false to mean that the QoS settings should apply per-consumer (for new consumers on the channel; existing ones being unaffected) and global=true to mean that the QoS settings should apply per-channel.
Optional
prefetchSpecifies a prefetch window in terms of whole messages. This field may be used in combination with the prefetch-size field; a message will only be sent in advance if both prefetch windows (and those at the channel and connection level) allow it. The prefetch-count is ignored if the no-ack option is set.
Optional
prefetchThe client can request that messages be sent in advance so that when the client finishes processing a message, the following message is already held locally, rather than needing to be sent down the channel. Prefetching gives a performance improvement. This field specifies the prefetch window size in octets. The server will send a message in advance if it is equal to or smaller in size than the available prefetch size (and also falls into other prefetch limits). May be set to zero, meaning "no specific limit", although other prefetch limits may still apply. The prefetch-size is ignored if the no-ack option is set.
This method asks the server to redeliver all unacknowledged messages on a specified channel. Zero or more messages may be redelivered.
Optional
requeue?: booleanIf this field is zero, the message will be redelivered to the original recipient. If this bit is 1, the server will attempt to requeue the message, potentially then delivering it to an alternative subscriber.
This method sets the channel to use publisher acknowledgements. https://www.rabbitmq.com/confirms.html#publisher-confirms
Bind exchange to an exchange.
Optional
arguments?: Record<string, any>A set of arguments for the binding. The syntax and semantics of these arguments depends on the exchange class.
Specifies the name of the destination exchange to bind.
Optional
routingSpecifies the routing key for the binding. The routing key is used for routing messages depending on the exchange configuration. Not all exchanges use a routing key - refer to the specific exchange documentation.
Specifies the name of the source exchange to bind.
Verify exchange exists, create if needed.
Optional
arguments?: { Optional
alternate-Optional
autoIf set, the exchange is deleted when all queues have finished using it.
Optional
durable?: booleanIf set when creating a new exchange, the exchange will be marked as durable. Durable exchanges remain active when a server restarts. Non-durable exchanges (transient exchanges) are purged if/when a server restarts.
Exchange names starting with "amq." are reserved for pre-declared and standardised exchanges. The exchange name consists of a non-empty sequence of these characters: letters, digits, hyphen, underscore, period, or colon.
Optional
internal?: booleanIf set, the exchange may not be used directly by publishers, but only when bound to other exchanges. Internal exchanges are used to construct wiring that is not visible to applications.
Optional
passive?: booleanIf set, the server will reply with Declare-Ok if the exchange already exists with the same name, and raise an error if not. The client can use this to check whether an exchange exists without modifying the server state. When set, all other method fields except name and no-wait are ignored. A declare with both passive and no-wait has no effect. Arguments are compared for semantic equivalence.
Optional
type?: stringdirect, topic, fanout, or headers: Each exchange belongs to one of a set of exchange types implemented by the server. The exchange types define the functionality of the exchange - i.e. how messages are routed through it.
"direct"
Delete an exchange.
Name of the exchange
Optional
ifIf set, the server will only delete the exchange if it has no queue bindings. If the exchange has queue bindings the server does not delete it but raises a channel exception instead.
Unbind an exchange from an exchange.
Optional
arguments?: Record<string, any>Specifies the name of the destination exchange to unbind.
Optional
routingSpecifies the routing key of the binding to unbind.
Specifies the name of the source exchange to unbind.
The specified consumer was stopped by the server. The error param describes the reason for the cancellation.
An undeliverable message was published with the "immediate" flag set, or an unroutable message published with the "mandatory" flag set. The reply code and text provide information about the reason that the message was undeliverable.
The channel was closed, because you closed it, or due to some error
This method binds a queue to an exchange. Until a queue is bound it will not receive any messages. In a classic messaging model, store-and-forward queues are bound to a direct exchange and subscription queues are bound to a topic exchange.
Optional
arguments?: Record<string, any>Name of the exchange to bind to.
Optional
queue?: stringSpecifies the name of the queue to bind. If blank, then the last declared queue on the channel will be used.
Optional
routingSpecifies the routing key for the binding. The routing key is used for routing messages depending on the exchange configuration. Not all exchanges use a routing key - refer to the specific exchange documentation. If the queue name is empty, the server uses the last queue declared on the channel. If the routing key is also empty, the server uses this queue name for the routing key as well. If the queue name is provided but the routing key is empty, the server does the binding with that empty routing key. The meaning of empty routing keys depends on the exchange implementation.
Declare queue, create if needed. If queue
empty or undefined then a
random queue name is generated (see the return value).
Optional
arguments?: { Optional
x-Optional
x-Optional
x-Queue Expiry https://www.rabbitmq.com/ttl.html#queue-ttl
Optional
x-Optional
x-Optional
x-Per-Queue Message TTL https://www.rabbitmq.com/ttl.html#per-queue-message-ttl
Optional
x-Optional
x-Optional
autoIf set, the queue is deleted when all consumers have finished using it. The last consumer can be cancelled either explicitly or because its channel is closed. If there was no consumer ever on the queue, it won't be deleted. Applications can explicitly delete auto-delete queues using the Delete method as normal.
Optional
durable?: booleanIf set when creating a new queue, the queue will be marked as durable. Durable queues remain active when a server restarts. Non-durable queues (transient queues) are purged if/when a server restarts. Note that durable queues do not necessarily hold persistent messages, although it does not make sense to send persistent messages to a transient queue.
Optional
exclusive?: booleanExclusive queues may only be accessed by the current connection, and are deleted when that connection closes. Passive declaration of an exclusive queue by other connections are not allowed.
Optional
passive?: booleanIf set, the server will reply with Declare-Ok if the queue already exists with the same name, and raise an error if not. The client can use this to check whether a queue exists without modifying the server state. When set, all other method fields except name and no-wait are ignored. A declare with both passive and no-wait has no effect.
Optional
queue?: stringThe queue name MAY be empty, in which case the server MUST create a new queue with a unique generated name and return this to the client in the Declare-Ok method. Queue names starting with "amq." are reserved for pre-declared and standardised queues. The queue name can be empty, or a sequence of these characters: letters, digits, hyphen, underscore, period, or colon.
Optional
queue: stringThis method deletes a queue. When a queue is deleted any pending messages
are sent to a dead-letter queue if this is defined in the server
configuration, and all consumers on the queue are cancelled. If queue
is
empty or undefined then the last declared queue on the channel is used.
Optional
ifIf set, the server will only delete the queue if it has no messages.
Optional
ifIf set, the server will only delete the queue if it has no consumers. If the queue has consumers the server does does not delete it but raises a channel exception instead.
Optional
queue?: stringSpecifies the name of the queue to delete.
Optional
queue: stringRemove all messages from a queue which are not awaiting acknowledgment.
If queue
is empty or undefined then the last declared queue on the
channel is used.
Optional
queue: stringOptional
queue?: stringUnbind a queue from an exchange.
Optional
arguments?: Record<string, any>The name of the exchange to unbind from.
Optional
queue?: stringSpecifies the name of the queue to unbind.
Optional
routingSpecifies the routing key of the binding to unbind.
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.
Don't use this unless you know what you're doing. This method is provided
for the sake of completeness, but you should use confirmSelect()
instead.
Sets the channel to use standard transactions. The client must use this method at least once on a channel before using the Commit or Rollback methods. Mutually exclusive with confirm mode.
Generated using TypeDoc
See
A raw Channel can be acquired from your Connection, but please consider using a higher level abstraction like a Consumer or Publisher for most cases.
AMQP is a multi-channelled protocol. Channels provide a way to multiplex a heavyweight TCP/IP connection into several light weight connections. This makes the protocol more “firewall friendly” since port usage is predictable. It also means that traffic shaping and other network QoS features can be easily employed. Channels are independent of each other and can perform different functions simultaneously with other channels, the available bandwidth being shared between the concurrent activities.
Example