Clients - rabbitmq : Channel

Public Ballerina API - Ballerina interface to an AMQP Channel. To provide AMQ Channel related functionalities.

queueDeclare

(QueueConfiguration? queueConfig)

returns string | Error | ()

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

Parameters

  • 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-autodelete, non-durable exchange with no extra arguments, If the arguments are specifed, 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 exception, 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? - ()
  • 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 paramters ifUnused or ifEmpty is given, the queue is checked before deleting.

Parameters

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

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

  • ifEmpty boolean? - ()
  • 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.

close

(int? closeCode, string? closeMessage)

returns Error?

Closes the RabbitMQ Channel.

Parameters

  • closeCode int? - ()
  • 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? - ()
  • 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? - ()
  • 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? - ()
  • A message indicating the reason for closing the channel.

  • Return Type

    (Error?)
  • 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.