This application sends and consumes messages using Message Broker Rabbitmq, along with the power that Golang gives us to deal with situations that we need high performance.
- Rabbitmq to Produce and Consume Messages
- Concurrency using Goroutines
- Channels
- SQLite Database
- HTTP Server
- Workers
- Docker + Docker Compose
Setup Application
$ go mod tidyThe database is already created and available at internal/order/infra/database/sqlite.db, but if you want to create it from scratch, just follow these steps:
$ cd internal/order/infra/database
$ touch sqlite.dbNow you need to access the database and create the orders table:
CREATE TABLE orders (
id VARCHAR(255) PRIMARY KEY NOT NULL,
price FLOAT NOT NULL,
tax FLOAT NULL,
final_price FLOAT NOT NULL
)- Go to http://localhost:15672 and log in to the Rabbitmq Management using guest credentials, by default the user is
guestand the password isguest. - Choose the
Queuestab. - Expand the
Add a new queueoption and set the queue name toorders. - Click on
Add queue.
- Choose the
Exchangestab. - Click on
amq.direct.
- Expand the
Bindingsoption and define inTo queuethe nameorders. - Click on
Bind.
After creating the bind it will look like this
For you to be able to test it, just produce some messages using the producer, it is configured to generate 1.000 messages that will be stored in the orders queue.
$ go run cmd/producer/main.goNow to finish, just consume these messages, this procedure will occur concurrently and all messages that are consumed will be stored in the SQLite database.
$ go run cmd/main.goSetup Prometheus + Grafana (optional)
The environments were configured using Docker Compose, to start the environment you must run:
$ docker-compose up- Go to http://localhost:9090.
- Choose the
Statusoption. - Click on
Targets.
Make sure the State column is UP
- Go to http://localhost:3000.
- Click on the
Settings iconand choose theData sourcesoption.
- Click on
Add data source.
- Click on
Prometheus.
- Update
URLfield value tohttp://prometheus:9090. - Click on
Save & test.
- Click on the
Dashboard iconand choose the+ Importoption.
- In the
Import via grafana.comfield, enter the value10991and click on theLoadbutton.
10991 is the Rabbitmq Dashboard ID, you can get this and others from this link: https://grafana.com/grafana/dashboards
- Select in the
prometheusoption the Prometheus that was configured there in theData sourcesection and click on theImportbutton, you can change the Dashboard name and the location where it will be saved as well.
Rabbitmq Dashboad













