Peer-to-peer messaging: This is the distribution pattern used in message queues with a one-to-one relationship between the sender and recipient of the message. Each message in the queue is sent to only one recipient and is used only once. Peer-to-peer messaging is called when a message is to be acted upon only once. Examples of suitable use cases for this style of messaging include payroll and financial transaction processing. In these systems, both senders and recipients need a guarantee that each payment will be sent once and only once.
- Clone the repository:
git clone https://github.com/setxpro/message-brocker-rabbitmq.git
-
Install dependencies with Maven
-
Run docker-compose up to create database and rabbitmq image
- Create a configuration in
application.yml
server:
- port: 8080
spring:
datasource:
username: root
url: jdbc:mysql://localhost:3306/orders?createDatabaseIfNotExists=true&serverTimezone=UTC&useSSL=false
password: ''
jpa:
show-sql: 'true'
hibernate:
ddl-auto: 'update'
rabbitmq:
host: localhost
port: 5672
username: rabbitmq
password: rabbitmq
- Create a configuration in
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>
-
Create a job with docker in
docker-compose.yml
services: mysql-8: image: mysql:8.0.18 command: --default-authentication-plugin=mysql_native_password environment: MYSQL_ALLOW_EMPTY_PASSWORD: "yes" MYSQL_ROOT_PASSWORD: "" MYSQL_DATABASE: "orders" ports: - "3306:3306"
After your realized all configurations
- Start the application with Maven
- Start docker containers Rabbitmq and mysql
The API provides the following endpoints:
Endpoints
[order-service] - http://localhost:8080/v1/order
{
"id": 16,
"value": 2500,
"paid": false
}
Endpoints
[PAINEL] - http://localhost:15672/
[CONNECTION] - http://localhost:5672/
Queue
[notification-service] - orders.v1.order-created.send-notification
[cashback-service] - orders.v1.order-created.generate-cashback
Mysql - created with Docker
👤 Patrick Anjos