Skip to main content
Version: 5.1

Build an Event-Driven Integration

TimeUnder 10 minutes
What you'll buildAn event-driven integration that consumes messages from Orders queue in RabbitMQ broker and processes them.

Event integrations are designed for reactive workflows triggered by messages from a broker. This quick start demonstrates the complete flow: creating a RabbitMQ message listener, adding an event handler to process messages, and implementing the integration logic executed when a message is received.

Prerequisites​

A working WSO2 Integrator environment.

Local setup

Install and launch WSO2 Integrator on your machine.

WSO2 Cloud Account

For AI assisted development and WSO2 Cloud deployments.

Also required, a running RabbitMQ instance. To start one with Docker, run:

docker run -d -p 5672:5672 -p 15672:15672 rabbitmq:4.2-management

Step 1: Create the integration​

Note

If you're using the cloud editor, a project is already open, so you can skip this step and go directly to Step 2: Add a RabbitMQ event listener.

  1. Open WSO2 Integrator.

  2. Click Create in the Create a Project card.

    WSO2 Integrator home screen with the Create a Project cardWSO2 Integrator home screen with the Create a Project card
  3. Set Project name to event-integration.

  4. Set Integration name to OrderProcessor.

  5. Click Create.

    Create a Project form with Project name set to event-integration and Integration name set to OrderProcessorCreate a Project form with Project name set to event-integration and Integration name set to OrderProcessor

Step 2: Add a RabbitMQ event listener​

  1. Select your integration from the project overview canvas.

  2. In the design view, click Add Artifact manually.

    Integration design view with the Add Artifact manually button highlightedIntegration design view with the Add Artifact manually button highlighted
  3. Select RabbitMQ under Event Integration.

    Artifacts page with RabbitMQ highlighted under Event IntegrationArtifacts page with RabbitMQ highlighted under Event Integration
  4. Set Host to localhost and Port to 5672 (update these if your RabbitMQ instance runs elsewhere).

  5. Set Queue Name to Orders.

  6. Click Create.

    Create RabbitMQ Event Integration form with Host, Port, and Queue Name setCreate RabbitMQ Event Integration form with Host, Port, and Queue Name set

Step 3: Add onMessage event handler​

  1. In the RabbitMQ service design view, click + Add Handler.

  2. Set Format to On Message.

  3. Click Save.

    Configure On Message Handler panel with Format set to On MessageConfigure On Message Handler panel with Format set to On Message

Step 4: Add message processing logic​

  1. Click + inside the onMessage flow.

  2. Select Call Function under Statement.

    Node panel with Call Function highlighted under StatementNode panel with Call Function highlighted under Statement
  3. Select printInfo under log.

    Functions list with printInfo highlighted under logFunctions list with printInfo highlighted under log
  4. Set Msg to Received order.

  5. Click Save.

    log:printInfo panel with Msg set to Received orderlog:printInfo panel with Msg set to Received order

Step 5: Run and test the integration​

  1. Click Run.

  2. The integration starts and listens for messages on the Orders queue.

  3. Open the RabbitMQ Management UI at http://localhost:15672 (default credentials: guest/guest).

    • Go to Queues and Streams → Orders → Publish message, enter any text as the payload, and click Publish message.
    • Confirm the integration log displays Received order.
    Running the integration and the Received order log in the terminalRunning the integration and the Received order log in the terminal

Step 6: Deploy to WSO2 Cloud​

Before you deploy, set Host and Port to a RabbitMQ broker that WSO2 Cloud can reach; localhost doesn't resolve to your local broker there.

Deploy your integration to WSO2 Cloud - Integration Platform in any of the following ways:

Skip ahead: deploy a ready-made sample

Rather not build it yourself? One-click deploy the OrderProcessor sample straight to WSO2 Cloud.

Deploy to WSO2 Cloud

Source code​

View the generated Ballerina code

The steps above generate the following complete, runnable Ballerina program:

import ballerina/log;
import ballerinax/rabbitmq;

listener rabbitmq:Listener rabbitmqListener = new ("localhost", 5672);

service "Orders" on rabbitmqListener {
remote function onMessage(rabbitmq:AnydataMessage message, rabbitmq:Caller caller) returns error? {
do {
log:printInfo("Received order");
} on fail error err {
// handle error
return error("unhandled error", err);
}
}
}

Supported event sources​

BrokerBallerina Package
Apache Kafkaballerinax/kafka
RabbitMQballerinax/rabbitmq
MQTTballerina/mqtt
Azure Service Busballerinax/asb
Salesforceballerinax/salesforce
GitHub Webhooksballerinax/trigger.github

What's next​

  • Kafka — Consume and produce Kafka messages
  • Azure Service Bus — Integrate with Azure Service Bus queues and topics
  • RabbitMQ — Full RabbitMQ listener and publisher reference
  • MQTT — Handle MQTT messages from IoT and messaging devices
  • CDC for PostgreSQL — React to database changes with change data capture