Clients - rabbitmq : Channel

Ballerina interface to provide AMQP Channel related functionality.

Constructor

__init

(ConnectionConfiguration | Connection connectionOrConnectionConfig)

Remote Methods

queueDeclare

Actively declare a non-exclusive, auto-delete, non-durable queue, or queue with the given configurations.

exchangeDeclare

Actively declare a non-auto-delete, non-durable exchange with no extra arguments, If the arguments are specified, then the exchange is declared accordingly.

queueBind

Binds a queue to an exchange with the given binding key.

basicPublish

Publishes a message. Publishing to a non-existent exchange will result in a channel-level protocol error, which closes the channel.

queueDelete

Deletes the queue with the given name although it is in use or has messages on it. If the parameters ifUnused or ifEmpty is given, the queue is checked before deleting.

exchangeDelete

Deletes the exchange with the given name.

queuePurge

Purges the contents of the given queue.

basicGet

Retrieves a message synchronously from the given queue, providing direct access to the messages in the queue.

Methods

queueDeclare

(QueueConfiguration? queueConfig)

returns string | Error | ()

Actively declare a non-exclusive, auto-delete, non-durable queue, or queue with the given configurations.

Parameters

  • queueConfig QueueConfiguration? (default ())
  • Holds the parameters required to declare a queue.

  • Return Type

    (string | Error | ())
  • The name of the queue if autogenerated or nil if the queue was successfully generated with the given parameters. An error is returned if an I/O error is encountered.

exchangeDeclare

(ExchangeConfiguration exchangeConfig)

returns Error?

Actively declare a non-auto-delete, non-durable exchange with no extra arguments, If the arguments are specified, then the exchange is declared accordingly.

Parameters

  • Return Type

    (Error?)
  • An error if an I/O error is encountered or nil if successful.

queueBind

(string queueName, string exchangeName, string bindingKey)

returns Error?

Binds a queue to an exchange with the given binding key.

Parameters

  • queueName string
  • Name of the queue.

  • exchangeName string
  • Name of the exchange.

  • bindingKey string
  • Binding key used to bind the queue to the exchange.

  • Return Type

    (Error?)
  • An error if an I/O error is encountered or nil if successful.

basicPublish

(MessageContent messageContent, string routingKey, string exchangeName, BasicProperties? properties)

returns Error?

Publishes a message. Publishing to a non-existent exchange will result in a channel-level protocol error, which closes the channel.

Parameters

  • routingKey string
  • The routing key.

  • exchangeName string
  • The name of the exchange to which the message is published.

  • properties BasicProperties? (default ())
  • Other properties for the message - routing headers etc.

  • Return Type

    (Error?)
  • An error if an I/O error is encountered or nil if successful.

queueDelete

(string queueName, boolean ifUnused, boolean ifEmpty)

returns Error?

Deletes the queue with the given name although it is in use or has messages on it. If the parameters ifUnused or ifEmpty is given, the queue is checked before deleting.

Parameters

  • queueName string
  • Name of the queue to be deleted.

  • ifUnused boolean (default false)
  • True if the queue should be deleted only if not in use.

  • ifEmpty boolean (default false)
  • True if the queue should be deleted only if empty.

  • Return Type

    (Error?)
  • An error if an I/O error is encountered or nil if successful.

exchangeDelete

(string exchangeName)

returns Error?

Deletes the exchange with the given name.

Parameters

  • exchangeName string
  • The name of the exchange.

  • Return Type

    (Error?)
  • An I/O error if an error is encountered or nil otherwise.

queuePurge

(string queueName)

returns Error?

Purges the contents of the given queue.

Parameters

  • queueName string
  • The name of the queue.

  • Return Type

    (Error?)
  • An error if an I/O error is encountered or nil if successful.

basicGet

(string queueName, AcknowledgementMode ackMode)

returns Message | Error

Retrieves a message synchronously from the given queue, providing direct access to the messages in the queue.

Parameters

  • queueName string
  • The name of the queue.

  • Return Type

    (Message | Error)
  • Message object containing the retrieved message data or an Error if an I/O problem is encountered.

getConnection

()

returns Connection | Error

Retrieve the Connection which carries this channel.

  • Return Type

    (Connection | Error)
  • RabbitMQ Connection object or error if an I/O problem is encountered.

close

(int? closeCode, string? closeMessage)

returns Error?

Closes the RabbitMQ Channel.

Parameters

  • closeCode int? (default ())
  • The close code (For information, go to the "Reply Codes" section in the [AMQP 0-9-1 specification] (#https://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf)).

  • closeMessage string? (default ())
  • A message indicating the reason for closing the channel.

  • Return Type

    (Error?)
  • An error if an I/O problem is encountered.

abortChannel

(int? closeCode, string? closeMessage)

returns Error?

Aborts the RabbitMQ Channel. Forces the Channel to close and waits for all the close operations to complete. Any encountered exceptions in the close operations are silently discarded.

Parameters

  • closeCode int? (default ())
  • The close code (For information, go to the "Reply Codes" section in the [AMQP 0-9-1 specification] (#https://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf)).

  • closeMessage string? (default ())
  • A message indicating the reason for closing the channel.

  • Return Type

    (Error?)
  • An error if an I/O problem is encountered.