Over a million developers have joined DZone.

Integration With Ballerina (Part 1)

DZone 's Guide to

Integration With Ballerina (Part 1)

This article will focus on a scenario from a high level to a simplified way of how Ballerina can be used to provide a solution to an integration scenario.

· Integration Zone ·
Free Resource


Integration is about connecting services together for communication, execution, monitoring, and operations. Initially, the monolithic three-tier architecture was followed and then to solve the issue of spaghetti dilemma, Service Oriented Architecture came into play. But when all of this started to look heavy and highly coupled, the integration world started to move towards latest, cloud-based, micro-services architecture.

Ballerina comes into action as a cloud-native programming language specifically providing integration solutions by making easier to write micro-services along with providing desirable support to integrate APIs. In-depth details on Ballerina from its philosophy to architecture can be found at ballerina.io. All the required instructions on setting up Ballerina, samples and guides can be found in the link. Go through the few samples given and understand and familiarize Ballerina by running those examples.

This article will be focused on explaining an end-to-end scenario from a high level to a simplified way on how Ballerina and its features can be used to provide a solution to an integration scenario. The upcoming articles will be on the step-by-step development of the entire scenario.


I have taken a scenario to come up with an integration solution with the use of Ballerina. It is an event management scenario with an availability of fifty seats for the event. Consider a user receives an invitation to attend an event of an organization. The user can either accept or decline the invitation. Also, the user can update the response already provided. Once the user accepts/declines an invitation, the message will go to a queue, and then there will be a database call to insert or update data. Upon the status of the database call, the user will be notified via email. The diagram of the entire scenario is shown below.

High Level Diagram of Event Management Scenario High-Level Diagram of Event Management Scenario

Let's break down the diagram into low-level designs, which will make the development easy.

Use Case 1: Working With Ballerina Message Broker

  • Once the user accepts/declines the invitation via an API call, the message will go into a queue, which runs on the Ballerina message broker. The user will then get a response to notify the request is a success. Then, the message will be consumed by a queue listener. That’s the working with Ballerina Message Broker part, and we can call it Use Case 1.

Use-case-1 — Working with Ballerina Message Broker

Use Case 1 — Working With Ballerina Message Broker

Use Case 2: Database Interaction With Ballerina

Once the message is consumed by the queue listener or the consumer based on the message content,

  • If its an accepted invitation — database call to get the count of users who have accepted the invitation. If the count is less than 50 (available number of seats), the user details will be inserted/updated to the database.
  • If its a declined invitation — database call to insert/update user details to the database.
Use-case-2 — Database Interaction with Ballerina Use-case-2 — Database Interaction with Ballerina

Use Case 3: Working With Ballerina Gmail Connector

Once the required details are updated in the database upon the status from the database calls, the user will be notified via email whether a seat for the user is reserved or not for the event along with other basic information about the event. For this purpose, we are going to use the Ballerina Gmail connector.

Use-case-3 — Sending Email through Ballerina Gmail Connector
Use-case-3 — Sending Email through Ballerina Gmail Connector

The goal of development of this scenario is to get more familiarized with Ballerina and especially on the following parts:

  • Working with Ballerina Message Broker
  • Database interaction through Ballerina
  • Working with Ballerina Gmail Connector
  • Handling requests, responses, and error scenarios appropriately

I hope you understood the scenario we are about to work on. Get yourself ready by setting up Ballerina and trying out a few examples.

The next article will be on Use Case 1 — working with Ballerina Message Broker, which is the initial part of the development of this scenario.

integration ,microservice ,message broker ,database ,api ,ballerina ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}