Skip to content

Commit befdbd8

Browse files
author
EpicFn
committed
feat : dlq 도입
1 parent 89acf55 commit befdbd8

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

src/main/java/org/tuna/zoopzoop/backend/global/mq/RabbitMQConfig.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package org.tuna.zoopzoop.backend.global.mq;
22

3-
import org.springframework.amqp.core.Binding;
4-
import org.springframework.amqp.core.BindingBuilder;
5-
import org.springframework.amqp.core.Queue;
6-
import org.springframework.amqp.core.TopicExchange;
3+
import org.springframework.amqp.core.*;
74
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
85
import org.springframework.amqp.rabbit.core.RabbitTemplate;
96
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
@@ -17,21 +14,46 @@ public class RabbitMQConfig {
1714
private static final String QUEUE_NAME = "graph.update.queue";
1815
private static final String ROUTING_KEY = "graph.update.#";
1916

17+
private static final String DLQ_EXCHANGE_NAME = EXCHANGE_NAME + ".dlx";
18+
private static final String DLQ_QUEUE_NAME = QUEUE_NAME + ".dlq";
19+
private static final String DLQ_ROUTING_KEY = "graph.update.dlq";
20+
2021
@Bean
2122
public TopicExchange exchange() {
2223
return new TopicExchange(EXCHANGE_NAME);
2324
}
2425

2526
@Bean
2627
public Queue queue() {
27-
return new Queue(QUEUE_NAME);
28+
return QueueBuilder.durable(QUEUE_NAME)
29+
.withArgument("x-dead-letter-exchange", DLQ_EXCHANGE_NAME) // 실패 시 메시지를 보낼 Exchange
30+
.withArgument("x-dead-letter-routing-key", DLQ_ROUTING_KEY) // 실패 시 사용할 라우팅 키
31+
.build();
2832
}
2933

3034
@Bean
3135
public Binding binding(Queue queue, TopicExchange exchange) {
3236
return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY);
3337
}
3438

39+
// ================= DLQ 인프라 구성 추가 ================= //
40+
41+
@Bean
42+
public TopicExchange dlqExchange() {
43+
return new TopicExchange(DLQ_EXCHANGE_NAME);
44+
}
45+
46+
@Bean
47+
public Queue dlqQueue() {
48+
return new Queue(DLQ_QUEUE_NAME);
49+
}
50+
51+
@Bean
52+
public Binding dlqBinding(Queue dlqQueue, TopicExchange dlqExchange) {
53+
return BindingBuilder.bind(dlqQueue).to(dlqExchange).with(DLQ_ROUTING_KEY);
54+
}
55+
56+
// ================= DLQ 인프라 구성 추가 ================= //
3557
@Bean
3658
public MessageConverter messageConverter() {
3759
// 메시지를 JSON 형식으로 직렬화/역직렬화하는 컨버터

src/main/resources/application.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ spring:
5151
port: 5672
5252
username: guest
5353
password: guest
54-
54+
listener:
55+
simple:
56+
retry:
57+
enabled: true
58+
initial-interval: 2000
59+
max-attempts: 3
5560
springdoc:
5661
default-produces-media-type: application/json;charset=UTF-8
5762
logging:
@@ -60,6 +65,7 @@ logging:
6065
org.hibernate.orm.jdbc.extract: TRACE
6166
org.springframework.transaction.interceptor: TRACE
6267
com.back: DEBUG
68+
org.springframework.retry: DEBUG
6369

6470
server:
6571
port: 8080

src/test/java/org/tuna/zoopzoop/backend/domain/dashboard/extraComponent/GraphUpdateConsumerTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package org.tuna.zoopzoop.backend.domain.dashboard.extraComponent;
22

3-
import org.assertj.core.api.AbstractStringAssert;
43
import org.junit.jupiter.api.*;
54
import org.springframework.amqp.rabbit.core.RabbitTemplate;
65
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
77
import org.springframework.boot.test.context.SpringBootTest;
8-
import org.springframework.test.annotation.DirtiesContext;
9-
import org.springframework.test.context.jdbc.Sql;
108
import org.springframework.transaction.annotation.Transactional;
119
import org.springframework.transaction.support.TransactionTemplate;
1210
import org.tuna.zoopzoop.backend.domain.dashboard.dto.GraphUpdateMessage;

0 commit comments

Comments
 (0)