This API documentation is for Ballerina 1.2.0. View API documentation for the latest release.

Clients - rabbitmq : Channel

The Ballerina interface to provide AMQP Channel related functionality.

Constructor

__init

(ConnectionConfiguration | Connection connectionOrConnectionConfig)

Remote Methods

queueDeclare

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

exchangeDeclare

Declares a non-auto-delete, non-durable exchange with no extra arguments.

queueBind

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

basicPublish

Publishes a message.

queueDelete

Deletes the queue with the given name although it is in use or has messages in it.

exchangeDelete

Deletes the exchange with the given name.

queuePurge

Purges the content of the given queue.

basicGet

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

Methods

Retrieves the connection, which carries this channel.

Closes the rabbitmq:Channel.

Aborts the RabbitMQ rabbitmq:Channel.

queueDeclare

(QueueConfiguration? queueConfig)

returns string | Error | ()

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

 string|rabbitmq:Error? queueResult = newChannel->queueDeclare();

Parameters

  • Return Type

    (string | Error | ())
  • The name of the queue if autogenerated, () if the queue was successfully generated with the given parameters, or else a rabbitmq:Error if an I/O error is encountered

exchangeDeclare

(ExchangeConfiguration exchangeConfig)

returns Error?

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

 rabbitmq:Error? exchangeResult = newChannel->exchangeDeclare({
                                               exchangeName: "MyExchange",
                                               exchangeType: rabbitmq:DIRECT_EXCHANGE,
                                               durable: true,
                                               autoDelete: true });

Parameters

  • Return Type

    (Error?)
  • A rabbitmq:Error if an I/O error is encountered or else ()

queueBind

(string queueName, string exchangeName, string bindingKey)

returns Error?

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

 rabbitmq:Error? bindResult = newChannel.queueBind("MyQueue", "MyExchange", "routing-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?)
  • A rabbitmq:Error if an I/O error is encountered or else ()

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.

 rabbitmq:Error? sendResult = newChannel->basicPublish("Hello from Ballerina", "MyQueue");

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?)
  • A rabbitmq:Error if an I/O error is encountered or else ()

queueDelete

(string queueName, boolean ifUnused, boolean ifEmpty)

returns Error?

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

 rabbitmq:Error? deleteResult = newChannel->queueDelete("MyQueue");

Parameters

  • queueName string
  • Name of the queue to be deleted

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

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

  • Return Type

    (Error?)
  • A rabbitmq:Error if an I/O error is encountered or else ()

exchangeDelete

(string exchangeName)

returns Error?

Deletes the exchange with the given name.

 rabbitmq:Error? deleteResult = newChannel->exchangeDelete("MyExchange");

Parameters

  • exchangeName string
  • The name of the exchange

  • Return Type

    (Error?)
  • A rabbitmq:Error if an I/O error is encountered or else ()

queuePurge

(string queueName)

returns Error?

Purges the content of the given queue.

 rabbitmq:Error? purgeResult = newChannel->queuePurge("MyQueue");

Parameters

  • queueName string
  • The name of the queue

  • Return Type

    (Error?)
  • A rabbitmq:Error if an I/O error is encountered or else ()

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.

 rabbitmq:Message|rabbitmq:Error getResult = newChannel->basicGet("MyQueue", rabbitmq:AUTO_ACK);

Parameters

  • queueName string
  • The name of the queue

  • Return Type

    (Message | Error)
  • A rabbitmq:Message object containing the retrieved message data or else arabbitmq:Error if an I/O error is encountered

getConnection

()

returns Connection | Error

Retrieves the connection, which carries this channel.

 rabbitmq:Connection|rabbitmq:Error connResult = newChannel.getConnection();
  • Return Type

    (Connection | Error)
  • A rabbitmq:Connection object or else a rabbitmq:Error if an I/O error is encountered

close

(int? closeCode, string? closeMessage)

returns Error?

Closes the rabbitmq:Channel.

 rabbitmq:Error? closeResult = newChannel.close();

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?)
  • A rabbitmq:Error if an I/O error is encountered or else ()

abortChannel

(int? closeCode, string? closeMessage)

returns Error?

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

 rabbitmq:Error? abortResult = newChannel.abortChannel(320, "Channel Aborted");

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?)
  • A rabbitmq:Error if an I/O error is encountered or else ()