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 - Listener : Listener

Listener - rabbitmq : Listener

Ballerina RabbitMQ Message Listener. Provides a listener to consume messages from the RabbitMQ server.

Constructor

__init

(ConnectionConfiguration | Connection connectionOrConnectionConfig, int? prefetchCount, int? prefetchSize)

  • prefetchCount int? ()
  • Maximum number of messages that the server will deliver. Give the value as 0 if unlimited. Unless explicitly given, this value is 10 by default.

  • prefetchSize int? ()
  • Maximum amount of content (measured in octets) that the server will deliver and 0 if unlimited

Methods

Stops consuming messages and detaches the service from the rabbitmq:Listener endpoint.
Stops consuming messages through all consumer services by terminating the connection and all its channels.
Stops consuming messages through all the consumer services and terminates the connection with the server.
Retrieve the rabbitmq:Channel, which initializes this rabbitmq:Listener.

LifeCycle Methods

Attaches the service to the rabbitmq:Listener endpoint.
Starts consuming the messages on all the attached services.

Methods

__detach

(service s)

returns error?

Stops consuming messages and detaches the service from the rabbitmq:Listener endpoint.

Parameters

  • s service
  • Type descriptor of the service

  • Return Type

    (error?)
  • () or else a rabbitmq:Error upon failure to detach the service

__gracefulStop

()

returns error?

Stops consuming messages through all consumer services by terminating the connection and all its channels.

  • Return Type

    (error?)
  • () or else a rabbitmq:Error upon failure to close the ChannelListener

__immediateStop

()

returns error?

Stops consuming messages through all the consumer services and terminates the connection with the server.

  • Return Type

    (error?)
  • () or else a rabbitmq:Error upon failure to close ChannelListener.

getChannel

()

returns Channel

Retrieve the rabbitmq:Channel, which initializes this rabbitmq:Listener.

  • Return Type

    (Channel)
  • A rabbitmq:Channel object or else a rabbitmq:Error if an I/O problem is encountered.

LifeCycle Methods

__attach

(service s, string? name)

returns error?

Attaches the service to the rabbitmq:Listener endpoint.

Parameters

  • s service
  • Type descriptor of the service

  • name string? (default ())
  • Name of the service

  • Return Type

    (error?)
  • () or else a rabbitmq:Error upon failure to register the service

__start

()

returns error?

Starts consuming the messages on all the attached services.

  • Return Type

    (error?)
  • () or else a rabbitmq:Error upon failure to start