Creating the first microservice using MySQL and RabbitMQ

Developing a microservice using MySQL and RabbitMQ.

In this example we will tell you the name of the new application, the type of Stream service as “Rabbitmq” for issuing events enabling “Event-Driven architecture” and 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

DevPrime CLI will create a new production-ready microservice. New applications created receive a complete and functional software architecture foundation allowing to accelerate software development

DevPrime mysql microservice

Enter the project folder and follow the next steps.

Adding a business rule

The created project is already ready to receive the business rules in the Domain Driven Design (DDD) standard. The code must be written within the Domain folder. After including it is possible to use the “dp init” accelerator to analyze the domain and create the code needed to display the API’s further simplifying the development journey and maintaining the best development practices.

To facilitate our example we will use the domain “Order” using a service marketplace 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

DevPrime CLI provides a command to export scripts and you can manually apply using the MySQL Workbench tool or some DevOps process.
dp export state state1

Creating the database structure"

DevPrime CLI provides a command to export and apply the relational bank structure as the example below. It will use the project credentials.
dp state apply state1

DevPrime mysql microservice

Starting the microservice “Order”

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 you start the application you will be able to track in the log below.

DevPrime mysql microservice

We just completed this journey using DevPrime, RabbitMQ, and MySQL.

Last modified March 10, 2022 (615ec2b)