/building-an-application-with-a-rabbitmq-acorn-service
Building an Application with a RabbitMQ Acorn Service – Part 2
The Service feature introduced in Acorn 0.7.0 allows developers to easily provision cloud components such as databases or message queues so applications can utilize them. In previous articles we illustrated Acorn Services with MongoDB Atlas and NGS / NATS.
Also, as we used the Voting App as a sample application in this series of Acorn dedicated articles we will go one step further in the current article and show how Acorn Services can bring Exoscale managed databases to the Voting App.
As a reminder the Voting App is a microservices oriented application coming from Docker (and now living unofficially in https://gitlab.com/voting-application). The overall architecture of the application is the following one:
It basically exposes 2 web front ends allowing a user to vote between 2 items and then to see the results of the votes. This application replies on 2 databases:
When launched with the default options, both databases are deployed in containers alongside the other microservices. In the next part we will see how, using Acorn Service, this application can use hosted databases instead.
Exoscale, a well known european cloud provider has a DB-as-a-Service offering which is powered by Aiven, one of the leading European companies for managing open source data infrastructure in the cloud. Among the technologies offered we can find redis, postgres, mysql and a couple of others.
Following the same structure of code we used for the MongoDB Atlas and NGS / NATS Services we created an Acorn Service allowing us to provision an Exoscale managed database, this new Service is available as an image in the Docker Hub
Note: this Service is currently for testing purposes only and will be enhanced soon.
The Service is available and ready to be consumed, but Before we can use it in the Voting App we need to make a couple of little changes to the application.
When the Exoscale DBaaS Acorn Service is triggered, it returns the following information regarding the database created:
For the Voting App to use the database we create a connection string out of the above information and provide this connection string to the calling microservices. Thus the Voting Application needed to be modified a bit to ensure:
Next we needed to change the application’s Acornfile adding the Service definitions and a couple of arguments. These new args can be used at launch time to specify the Voting App should use hosted databases instead of the local ones. The new version of the Acornfile is available here.
Once those changes were done, the Voting App was packaged in an Acorn image and pushed to the Docker Hub.
With those changes in place the Voting App can now be run using local databases or with hosted databases. In the following parts we will test the 2 configurations.
First we run the latest version of the application (at time of writing) without any arguments as follows:
After a few tens of seconds we can see the application is up and running, it returns http endpoints as follows:
Using the http endpoints we can access the application, vote for our favorite pet and see the result.
The application is this running fine using local databases (the changes didn’t break anything 🙂 ).
We can now delete the application.
First we create a secret containing our Exoscale’s api keys, this step is required as the Acorn Service needs to connect to Exoscale in order to create hosted databases.
Next we run the Voting App providing both –hosted-redis –hosted-postgres and –hosted-redis –hosted-postgres flags:
After a few tens of seconds the Exoscale console shows both redis and postgres databases were created
Listing all the objects we can see there are no redis nor db containers, this indicates the application now relies on the external databases.
Using the http endpoints we can verify the application is running fine in this configuration too.
We can now remove the application
This simple example shows how we can use the Acorn Service feature to bring Exoscale managed databases to the Voting App. The code used to create this Service is available on GitHub.
Want to know more about Acorn ? Feel free to follow this introductory workshop locally at your own pace https://gitlab.com/lucj/acorn-workshop (as always, all kinds of feedback are welcome).
Luc Juggery is a software engineer with 18+ years of experience and co-founder of 2 startups located in Sophia-Antipolis, southern France. You can chat with him on Twitter, read more of his work on Medium, find his tutorials on YouTube, or take one of his Docker or Kubernetes training courses on Udemy.