Creating the first microservice using MySQL and RabbitMQ

Developing a microservice using MySQL and RabbitMQ.

In this example, we’ll enter the name of the new application, the Stream service type as “RabbitMQ” for emitting events enabling “Event-Driven architecture” and the State as “MySQL” for data persistence.

Before starting development, it is necessary to configure containers in docker with RabbitMQ and MySQL. Create the “orderevents” queue in RabbitMQ.

dp new Order --stream rabbitmq --state mysql

The Devprime CLI will create a new production-ready microservice. The new applications created receive a complete and functional software architecture foundation allowing to accelerate the development of the software

Devprime mysql microservice

Enter the project folder and follow the next steps.

Adding a Business Rule

The created project is now ready to receive the business rules in the Domain Driven Design (DDD) pattern. The code should be written inside the Domain folder. After including, it is possible to use the “dp init” accelerator to analyze the domain and create the necessary code for API exposure, further simplifying the development journey, in addition to maintaining the best development practices.

To facilitate our example, we will use the “Order” domain using a marketplace service of the Devprime platform. Use the command below and check the result in the Domain src/Core/Domain/Aggregates folder.

dp marketplace order
dp init

The new microservice is ready !!

Exporting the Data Structure

The Devprime CLI offers a command to export the scripts and you can apply it manually using the ‘MySQL Workbench’ tool or some DevOps process.
dp export state state1

Creating the Database Structure"

The Devprime CLI provides a command to export and apply the relational database structure as shown in the example below. It will use the project’s credentials.
dp state apply state1

Devprime mysql microservice

Starting the “Order” microservice

You can run the application using “dotnet run” or using the “.\run.ps1” script files if you are using powershell (Windows, Linux, macOS) or “./run.sh” in bash (Linux and macOS).
chmod +x run.sh

When starting the application it will be possible to follow in the log below.

Devprime mysql microservice

We’ve just completed this journey using Devprime, RabbitMQ, and MySQL.

Last modified April 11, 2024 (cc33f7e6)