RabbitMQ is one of the most popular open-source enterprise messaging systems modelled on the Advanced Message Queuing Protocol (AMQP) standard. This guide covers the Ballerina RabbitMQ module and its public API. This module contains the functionality to support messaging with the RabbitMQ broker (AMQP 0-9-1). It assumes that the most recent version of Ballerina is used and is built on top of the basics. "> API Docs - Object : Connection

Object - rabbitmq : Connection

Represents a single network connection to the RabbitMQ broker.

Constructor

__init

(ConnectionConfiguration connectionConfiguration)

Methods

Closes the rabbitmq:Connection and all its rabbitmq:Channels.
Aborts the rabbitmq:Connection and all its rabbitmq:Channels.
Checks whether close was already called.

close

(int? closeCode, string? closeMessage, int? timeoutInMillis)

returns Error?

Closes the rabbitmq:Connection and all its rabbitmq:Channels. It waits with a provided timeout for all the close operations to complete. When the timeout is reached, the socket is forced to close.

 rabbitmq:Error? closeResult = newConnection.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 connection

  • timeoutInMillis int? (default ())
  • Timeout (in milliseconds) for completing all the close-related operations. Use -1 for infinity

  • Return Type

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

abortConnection

Aborts the rabbitmq:Connection and all its rabbitmq:Channels. Forces the rabbitmq:Connection to close and waits for all the close operations to complete. When the timeout is reached, the socket is forced to close. Any encountered exceptions in the close operations are discarded silently.

 connection.abortConnection(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 connection

  • timeoutInMillis int? (default ())
  • Timeout (in milliseconds) for completing all the close-related operations. Use -1 for infinity

isClosed

()

returns boolean

Checks whether close was already called.

 boolean closed = newConnection.isClosed();

  • Return Type

    (boolean)
  • The value true if the rabbitmq:Connection is already closed or else false