Module : rabbitmq
Module overview
'ballerina/rabbitmq' provides the capability to connect with a RabbitMQ server and perform the following
- Point to point communication (Queues)
- Pub/Sub (Topics)
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);
}
}
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. |
SecureSocket | Provides configurations for facilitating secure connections. |
Connection | Public Ballerina API - Interface to an AMQ |
Channel | Public Ballerina API - Ballerina interface to an AMQP |
Message | Public Ballerina API - Ballerina RabbitMQ Message. |
Listener | Public Ballerina API - Ballerina RabbitMQ Message Listener. To provide a listener to consume messages from RabbitMQ. |
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. |
RABBITMQ_ERROR |
ServiceConfig | Service descriptor data generated at compile time. |
AcknowledgementMode | Types of acknowledgement modes supported by the Ballerina RabbitMQ Connector. |
RabbitMQError |