-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from f-lab-edu/feature/70-retry
[#70] RabbitMQ 재처리 설정
- Loading branch information
Showing
26 changed files
with
648 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/modoospace/alarm/consumer/AlarmDLQConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.modoospace.alarm.consumer; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.amqp.core.Message; | ||
import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
@Slf4j | ||
public class AlarmDLQConsumer { | ||
|
||
private static final String RETRY_COUNT_HEADER = "x-retries_count"; | ||
|
||
private final RabbitTemplate rabbitTemplate; | ||
|
||
@Value("${spring.rabbitmq.retry_count}") | ||
private int retryCount; | ||
|
||
@RabbitListener(queues = "q.alarm.dead") | ||
public void processFailedMessagesRequeue(Message failedMessage) { | ||
Integer retriesCnt = (Integer) failedMessage.getMessageProperties().getHeaders() | ||
.get(RETRY_COUNT_HEADER); | ||
if (retriesCnt == null) { | ||
retriesCnt = 0; | ||
} | ||
if (retriesCnt >= retryCount) { | ||
log.info("Discarding message"); | ||
return; | ||
} | ||
log.info("Retrying message for the {} time", retriesCnt); | ||
failedMessage.getMessageProperties().getHeaders().put(RETRY_COUNT_HEADER, ++retriesCnt); | ||
rabbitTemplate.send("x.alarm.work", | ||
failedMessage.getMessageProperties().getReceivedRoutingKey(), failedMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/modoospace/common/exception/MessageParsingError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.modoospace.common.exception; | ||
|
||
public class MessageParsingError extends RuntimeException { | ||
|
||
private static final String MESSAGE = "메세지를 파싱할 수 없습니다."; | ||
public MessageParsingError() { | ||
super(MESSAGE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/java/com/modoospace/config/auth/SecurityConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 0 additions & 60 deletions
60
src/main/java/com/modoospace/config/auth/dto/AuthProvider.java
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
src/main/java/com/modoospace/config/auth/dto/AuthProviderConvertor.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.