Creating the first microservice using MySQL and RabbitMQ
In this example we will enter the name of the new application, the Stream service type as “RabbitMQ” for event emitting “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 them to accelerate software development
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 inside the Domain folder. After including it, 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 them manually using the MySQL Workbench tool or some DevOps process.
dp export state state1
Creating the Database Structure"
The Devprime CLI offers a command to export and apply the relational database structure as per the example below. It will use the project’s credentials.
dp state apply state1
Starting the “Order” microservice
You can run the application using “dotnet run” or using the script files “.\run.ps1” 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 the log below.
We just completed this journey using Devprime, RabbitMQ, and MySQL.
Last modified November 20, 2024 (61099f59)