-
Notifications
You must be signed in to change notification settings - Fork 3
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 #89 from HongDam-org/feat/rabbitmq-deadletter
[FEAT] rabbitmq deadletter 처리
- Loading branch information
Showing
5 changed files
with
71 additions
and
15 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
32 changes: 32 additions & 0 deletions
32
backend/src/main/java/com/twtw/backend/domain/deadletter/DeadLetterConsumer.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,32 @@ | ||
package com.twtw.backend.domain.deadletter; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
@Slf4j | ||
@Component | ||
public class DeadLetterConsumer { | ||
|
||
private final WebClient webClient; | ||
private final String slackUrl; | ||
|
||
public DeadLetterConsumer(@Value("${slack.url}") final String slackUrl) { | ||
this.webClient = WebClient.create("https://hooks.slack.com/services/"); | ||
this.slackUrl = slackUrl; | ||
} | ||
|
||
@RabbitListener(queues = "deadletter.queue") | ||
public void handleDeadLetterMessage(final String message) { | ||
log.error("Dead letter received: {}", message); | ||
webClient.post() | ||
.uri(slackUrl) | ||
.bodyValue("{\"text\": \"Dead letter received: " + message + "\"}") | ||
.retrieve() | ||
.bodyToMono(String.class) | ||
.doOnSuccess(s -> log.info("Slack message sent: {}", s)) | ||
.subscribe(); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -83,3 +83,5 @@ tmap: | |
url: ${TMAP_URL} | ||
firebase: | ||
location: ${FIREBASE_LOCATION} | ||
slack: | ||
url: ${SLACK_URL} |