11package 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 .*;
74import org .springframework .amqp .rabbit .connection .ConnectionFactory ;
85import org .springframework .amqp .rabbit .core .RabbitTemplate ;
96import 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 형식으로 직렬화/역직렬화하는 컨버터
0 commit comments