Spring boot application with Cellery

Hasitha Athukorala
wso2-cellery
Published in
3 min readAug 20, 2019

Here, I am going to explain how to deploy a Spring boot application with Cellery. To understand the below procedure, it is better if you have a basic knowledge about Spring boot application development and Cellery. Before begin, I’ll give you a brief explanation about Cellery since it is an really interesting solution to run and manage composite applications on Kubernetes.

Cellery is a code-first approach to building, integrating, running and managing composite applications (cells) on Kubernetes.

If you are interested and want to know more about Cellery follow this document here or you can have a visit to their web site here.

Lets begin with the sample Spring boot application

Spring boot application with Cellery

In above sketch you can see that I am going to build three cells. Basically this sample application contains a simple UI, information about authors in the authors cell and the information about articles about in the articles cell. ui cell communicate with other two cells and show those information to the user. Basically the three micro services are deployed in three cells.

You can visit and download the source code of the application here in GitHub.

Project Structure

Here is the structure of the application. each service has a Docker file. Open terminal and go to the root directory of the project and execute these commands. ( make sure you have installed maven. otherwise you should install it first)

cd article-servicemvn cleanmvn install

Then you will see a target directory is made there. This folder will contain the .jar file.

Lets build the Docker images

docker build -t <ORGANIZATION>/spring-art .docker push <ORGANIZATION>/spring-art

( Please replace <ORGANIZATION> with your organization name )

Do this for all the three services

cd ..cd author-servicemvn cleanmvn installdocker build -t <ORGANIZATION>/spring-auth .docker push <ORGANIZATION>/spring-authcd ..cd front-end-servicemvn cleanmvn installdocker build -t <ORGANIZATION>/spring-ui .docker push <ORGANIZATION>/spring-ui

Lets build the Cellery images

Then we should build the Cellery images to deploy these services. We should install Cellery SDK and download Cellery runtime to do this. please follow this link to download and configure Cellery runtime.

Now please go to the root folder of the project and open each ballerina file and replace the docker image with your docker image. Otherwise you can just use the docker images I have built. As an example I’ll show you the sprint-art.bal file and how to change that. Please open the spring-art.bal file. There you can see the below code segment,

source: {
image: "athukorala/spring-art"
},

There you can see that there is my docker image “athukorala/spring-art” under the source. please replace that with your docker image that you built in the previous steps.

Then run these commands to build the Cellery images

cellery build spring-art.bal <ORGANIZATION>/spring-art:latestcd ..cd spring-authcellery build spring-auth.bal <ORGANIZATION>/spring-auth:latestcd ..cd spring-uicellery build spring-ui.bal <ORGANIZATION>/spring-ui:latest

So, now you have built all the Cellery images successfully.

Lets run the Cellery images

please execute this command and this will execute all the three images.

cellery run <ORGANIZATION>/spring-ui:latest -d

Congratulations! now your Spring boot application is running successfully in the Cellery runtime.

Lets browse

Now please execute these commands to add the host address to the etc/hosts file

sudo gedit /etc/hosts

This will open the hosts file in gedit. Now please add this line to the hosts file

192.168.56.10 cellery-demo.com

Now please visit this url to see the contents

http://cellery-demo.com

There you can see that ui cell is fetching information from both articles cell and the authors cell. So that’s it and Thank you.

--

--