Skip to content

Commit 9687541

Browse files
committed
step8-1 코드 정리
1 parent 517e5f1 commit 9687541

File tree

4 files changed

+19
-23
lines changed

4 files changed

+19
-23
lines changed

src/main/java/net/harunote/hellomessagequeue/step8/OrderConsumer.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
package net.harunote.hellomessagequeue.step8;
22

33
import org.springframework.amqp.rabbit.annotation.RabbitListener;
4-
import org.springframework.retry.RetryCallback;
5-
import org.springframework.retry.RetryContext;
6-
import org.springframework.retry.RetryListener;
7-
import org.springframework.retry.policy.SimpleRetryPolicy;
8-
import org.springframework.retry.support.RetryTemplate;
94
import org.springframework.stereotype.Component;
105

116
@Component
127
public class OrderConsumer {
138

149
private int retryCount;
1510

16-
@RabbitListener(queues = RabbitMQConfig.TOPIC_QUEUE)
11+
@RabbitListener(queues = RabbitMQConfig.ORDER_COMPLETED_QUEUE)
1712
public void processMessage(String message) {
1813
System.out.println("Received message: "+ message + "count : " + retryCount++);
1914
if ("fail".equals(message)) {

src/main/java/net/harunote/hellomessagequeue/step8/OrderDeadLetterRetry.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.springframework.amqp.rabbit.annotation.RabbitListener;
44
import org.springframework.amqp.rabbit.core.RabbitTemplate;
5-
import org.springframework.messaging.handler.annotation.Header;
65
import org.springframework.stereotype.Component;
76

87
/**
@@ -21,18 +20,20 @@ public OrderDeadLetterRetry(RabbitTemplate rabbitTemplate) {
2120
this.rabbitTemplate = rabbitTemplate;
2221
}
2322

24-
@RabbitListener(queues = RabbitMQConfig.TOPIC_DLQ)
23+
@RabbitListener(queues = RabbitMQConfig.DLQ)
2524
public void processDlqMessage(String failedMessage) {
2625
try {
2726
System.out.println("[DLQ Received]: " + failedMessage);
2827

2928
// 실패한 메시지를 성공 메시지로 변경
30-
String modifiedMessage = "success";
29+
String message = "success";
3130

3231
// 수정된 메시지를 원래 큐로 재전송
33-
rabbitTemplate.convertAndSend(RabbitMQConfig.TOPIC_EXCHANGE, "order.completed.shipping", modifiedMessage);
32+
rabbitTemplate.convertAndSend(RabbitMQConfig.ORDER_TOPIC_EXCHANGE,
33+
"order.completed.shipping",
34+
message);
3435

35-
System.out.println("Message successfully reprocessed : " + modifiedMessage);
36+
System.out.println("Message successfully reprocessed : " + message);
3637

3738
} catch (Exception e) {
3839
System.err.println("Error processing DLQ message : " + e);

src/main/java/net/harunote/hellomessagequeue/step8/OrderProducer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public OrderProducer(RabbitTemplate rabbitTemplate) {
1212
}
1313

1414
public void sendShipping(String message) {
15-
rabbitTemplate.convertAndSend(RabbitMQConfig.TOPIC_EXCHANGE, "order.completed.shipping", message);
15+
rabbitTemplate.convertAndSend(RabbitMQConfig.ORDER_TOPIC_EXCHANGE, "order.completed.shipping", message);
1616
System.out.println("[주문 완료. 배송 지시 메시지 생성 : " + message + "]");
1717
}
1818
}

src/main/java/net/harunote/hellomessagequeue/step8/RabbitMQConfig.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@
77
@Configuration
88
public class RabbitMQConfig {
99

10-
public static final String TOPIC_EXCHANGE = "order.topic.exchange";
11-
public static final String TOPIC_QUEUE = "order.completed.queue";
12-
public static final String TOPIC_DLQ = "order.topic.dlq";
13-
public static final String TOPIC_DLX = "order.topic.dlx";
14-
public static final String DEAD_LETTER_ROUTING_KEY = "dlx.#";
15-
10+
public static final String ORDER_COMPLETED_QUEUE = "orderCompletedQueue";
11+
public static final String DLQ = "deadLetterQueue";
12+
public static final String ORDER_TOPIC_EXCHANGE = "orderExchange";
13+
public static final String ORDER_TOPIC_DLX = "deadLetterExchange";
14+
public static final String DEAD_LETTER_ROUTING_KEY = "dead.letter";
1615
@Bean
16+
1717
public TopicExchange exchange() {
18-
return new TopicExchange(TOPIC_EXCHANGE);
18+
return new TopicExchange(ORDER_TOPIC_EXCHANGE);
1919
}
2020

2121
@Bean
2222
public TopicExchange deadLetterExchange() {
23-
return new TopicExchange(TOPIC_DLX);
23+
return new TopicExchange(ORDER_TOPIC_DLX);
2424
}
2525

2626
@Bean
2727
public Queue queue() {
28-
return QueueBuilder.durable(TOPIC_QUEUE)
29-
.withArgument("x-dead-letter-exchange", TOPIC_DLX)
28+
return QueueBuilder.durable(ORDER_COMPLETED_QUEUE)
29+
.withArgument("x-dead-letter-exchange", ORDER_TOPIC_DLX)
3030
.withArgument("x-dead-letter-routing-key", DEAD_LETTER_ROUTING_KEY)
3131
.build();
3232
}
3333

3434
@Bean
3535
public Queue deadLetterQueue() {
36-
return new Queue(TOPIC_DLQ);
36+
return new Queue(DLQ);
3737
}
3838

3939
@Bean

0 commit comments

Comments
 (0)