Module : rabbitmq

Module overview

'ballerina/rabbitmq' provides the capability to connect with a RabbitMQ server and perform the following

Samples

RabbitMQ Producer

Following program will produce a message to a RabbitMQ server

import ballerina/rabbitmq;
import ballerina/log;

public function main() {
     rabbitmq:Channel chann = new({ host: "localhost", port: 5672 });
     var sendResult = chann->basicPublish("Hello from ballerina", "testingDemo", exchange = "");
     if (sendResult is error) {
          log:printError("An error occurred while sending the message");
     } else {
          log:printInfo("The message was sent successfully");
     }
}

RabbitMQ Subscriber

Following program will consume a message from a RabbitMQ server

import ballerina/rabbitmq;
import ballerina/log;

listener rabbitmq:ChannelListener chann = new({ host: "localhost", port: 5672 });

@rabbitmq:ServiceConfig {
        queueName: "testingDemo"
}
service testSimpleConsumer on chann {
    resource function onMessage(string message) {
            log:printInfo("The message received: " + message);
    }
}

Records

BasicProperties Holds other properties of the message - routing headers etc.
ConnectionConfiguration Holds the parameters used to create a RabbitMQ `Connection`.
ExchangeConfiguration Holds the parameters used to declare an exchange.
QueueConfiguration Holds the parameters used to declare a queue.
RabbitMQServiceConfig Represents the list of parameters required to create a subscription.

Objects

Connection

Public Ballerina API - Interface to an AMQ Connection.

Clients

Channel

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

Message

Public Ballerina API - Ballerina RabbitMQ Message.

Listeners

Listener

Public Ballerina API - Ballerina RabbitMQ Message Listener. To provide a listener to consume messages from RabbitMQ.

Constants

DIRECT_EXCHANGE

Constant for the RabbitMQ Direct Exchange type.

FANOUT_EXCHANGE

Constant for the RabbitMQ Fanout Exchange type.

TOPIC_EXCHANGE

Constant for the RabbitMQ Topic Exchange type.

AUTO_ACK

Constant for the RabbitMQ auto acknowledgement mode.

CLIENT_ACK

Constant for the RabbitMQ client acknowledgement mode.

RABBITMQ_ERROR_CODE

RabbitMQ Error code.

Annotations

ServiceConfig

Service descriptor data generated at compile time.

Types

AcknowledgementMode

Types of acknowledgement modes supported by the Ballerina RabbitMQ Connector.