Skip to content

Commit 72ba2e3

Browse files
committed
- add rabbitmq dependencies to project
- config publisher & listener
1 parent cb8dac5 commit 72ba2e3

File tree

7 files changed

+95
-0
lines changed

7 files changed

+95
-0
lines changed

.idea/encodings.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amqp/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.hrk</groupId>
8+
<artifactId>microservices-tutorial</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>amqp</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>20</maven.compiler.source>
16+
<maven.compiler.target>20</maven.compiler.target>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-amqp</artifactId>
24+
</dependency>
25+
</dependencies>
26+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.hrk.amqp;
2+
3+
import lombok.AllArgsConstructor;
4+
import org.springframework.amqp.core.AmqpTemplate;
5+
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
6+
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
7+
import org.springframework.amqp.rabbit.core.RabbitTemplate;
8+
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
9+
import org.springframework.amqp.support.converter.MessageConverter;
10+
import org.springframework.context.annotation.Bean;
11+
import org.springframework.context.annotation.Configuration;
12+
13+
@Configuration
14+
@AllArgsConstructor
15+
public class RabbitMQConfig {
16+
17+
private final ConnectionFactory connectionFactory;
18+
19+
@Bean
20+
public AmqpTemplate amqpTemplate() {
21+
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
22+
rabbitTemplate.setMessageConverter(jacksonConverter());
23+
return rabbitTemplate;
24+
}
25+
26+
@Bean
27+
public SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory(){
28+
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
29+
factory.setConnectionFactory(connectionFactory);
30+
factory.setMessageConverter(jacksonConverter());
31+
return factory;
32+
}
33+
34+
@Bean
35+
public MessageConverter jacksonConverter() {
36+
return new Jackson2JsonMessageConverter();
37+
}
38+
}

customer/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@
4949
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
5050
</dependency>
5151

52+
<dependency>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-starter-amqp</artifactId>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>com.hrk</groupId>
59+
<artifactId>amqp</artifactId>
60+
<version>1.0-SNAPSHOT</version>
61+
</dependency>
62+
5263
<dependency>
5364
<groupId>com.hrk</groupId>
5465
<artifactId>clients</artifactId>

docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ services:
3232
container_name: zipkin
3333
ports:
3434
- "9411:9411"
35+
rabbitmq:
36+
image: rabbitmq:3.9.11-management-alpine
37+
container_name: rabbitmq
38+
ports:
39+
- "5672:5672"
40+
- "15672:15672"
3541

3642
networks:
3743
postgres:

notification/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@
4949
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
5050
</dependency>
5151

52+
<dependency>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-starter-amqp</artifactId>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>com.hrk</groupId>
59+
<artifactId>amqp</artifactId>
60+
<version>1.0-SNAPSHOT</version>
61+
</dependency>
62+
5263
<dependency>
5364
<groupId>com.hrk</groupId>
5465
<artifactId>clients</artifactId>

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<module>clients</module>
1818
<module>notification</module>
1919
<module>apigw</module>
20+
<module>amqp</module>
2021
</modules>
2122

2223
<properties>

0 commit comments

Comments
 (0)