-
Notifications
You must be signed in to change notification settings - Fork 5
[Feat/OPS-344] message queue 구현 #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
The head ref may contain hidden characters: "feat/OPS-344-BE-feat-message-queue-\uAD6C\uD604"
Merged
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
54d64a1
chore : RabbitMQ 환경 설정
feaa21d
chore : CI 파이프라인에서 RabbitMQ 컨테이너를 띄워서 사용하도록 설정
b8a65c3
new : RabbitMQ 설정 클래스, dto 생성
feb8f39
feat : producer method 생성
a41beea
feat : 메세지 큐 구현 완료
afdfdb0
feat : 데이터 저장 요청 테스트 케이스 수정
f76bf0c
feat : ConsumerTest 코드 추가
4550585
fix : 저장 테스트 케이스 성공
b0c8baa
fix : 테스트 코드 수정 중
89acf55
fix : 테스트 케이스 성공
befdbd8
feat : dlq 도입
6e0d280
feat : 데이터 순서 보장을 위해 version 추가
d29ed3d
refactor : MQConfig 파일 위치 변경
a9d1960
chore : RabbitMQ 환경 설정
8158ad5
chore : CI 파이프라인에서 RabbitMQ 컨테이너를 띄워서 사용하도록 설정
7dae036
new : RabbitMQ 설정 클래스, dto 생성
307a1ca
feat : producer method 생성
f44cbc0
feat : 메세지 큐 구현 완료
15b22e5
feat : 데이터 저장 요청 테스트 케이스 수정
40ce2b4
feat : ConsumerTest 코드 추가
65a63e7
fix : 저장 테스트 케이스 성공
05c4f78
fix : 테스트 코드 수정 중
db9ef67
fix : 테스트 케이스 성공
a50b5b7
feat : dlq 도입
974473e
feat : 데이터 순서 보장을 위해 version 추가
fcaefd5
refactor : MQConfig 파일 위치 변경
5d54358
fix : 최신 사항 반영
e4d1679
feat : 최신 커밋 반영
e27ebe2
fix : copilot review 반영
29136fb
feat : Dashboard에서 graph 참조 방식 EAGER -> LAZY 로 변경
6022f40
CI 실패해서 다시 EAGER로 변경
2be799b
fix : 다시 LAZY로 변경
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
7 changes: 7 additions & 0 deletions
7
src/main/java/org/tuna/zoopzoop/backend/domain/dashboard/dto/GraphUpdateMessage.java
This file contains hidden or 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,7 @@ | ||
| package org.tuna.zoopzoop.backend.domain.dashboard.dto; | ||
|
|
||
| public record GraphUpdateMessage( | ||
| Integer dashboardId, | ||
| String requestBody | ||
| ){ | ||
| } |
This file contains hidden or 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 hidden or 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
...n/java/org/tuna/zoopzoop/backend/domain/dashboard/extraComponent/GraphUpdateConsumer.java
This file contains hidden or 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 org.tuna.zoopzoop.backend.domain.dashboard.extraComponent; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
| import org.springframework.orm.ObjectOptimisticLockingFailureException; | ||
| import org.springframework.stereotype.Component; | ||
| import org.tuna.zoopzoop.backend.domain.dashboard.dto.BodyForReactFlow; | ||
| import org.tuna.zoopzoop.backend.domain.dashboard.dto.GraphUpdateMessage; | ||
| import org.tuna.zoopzoop.backend.domain.dashboard.service.DashboardService; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class GraphUpdateConsumer { | ||
| private final DashboardService dashboardService; | ||
| private final ObjectMapper objectMapper; | ||
|
|
||
| @RabbitListener(queues = "graph.update.queue") | ||
| public void handleGraphUpdate(GraphUpdateMessage message) { | ||
| log.info("Received graph update message for dashboardId: {}", message.dashboardId()); | ||
| try { | ||
| BodyForReactFlow dto = objectMapper.readValue(message.requestBody(), BodyForReactFlow.class); | ||
| dashboardService.updateGraph(message.dashboardId(), dto); | ||
| log.info("Successfully updated graph for dashboardId: {}", message.dashboardId()); | ||
| } catch (ObjectOptimisticLockingFailureException e) { | ||
| // Optimistic Lock 충돌 발생! | ||
| // 내가 처리하려던 메시지는 이미 구버전 데이터에 대한 요청이었음. | ||
| // 따라서 이 메시지는 무시하고 정상 처리된 것으로 간주. | ||
| log.warn("Stale update attempt for dashboardId: {}. A newer version already exists. Discarding message.", message.dashboardId()); | ||
| // 예외를 다시 던지지 않으므로, 메시지는 큐에서 정상적으로 제거(ACK)됩니다. | ||
| } catch (Exception e) { | ||
| // 실제 운영에서는 메시지를 재시도하거나, 실패 큐(Dead Letter Queue)로 보내는 등의 | ||
| // 정교한 에러 처리 로직이 필요합니다. | ||
| log.error("Failed to process graph update for dashboardId: {}", message.dashboardId(), e); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
69 changes: 69 additions & 0 deletions
69
src/main/java/org/tuna/zoopzoop/backend/global/config/mq/RabbitMQConfig.java
This file contains hidden or 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,69 @@ | ||
| package org.tuna.zoopzoop.backend.global.config.mq; | ||
|
|
||
| import org.springframework.amqp.core.*; | ||
| import org.springframework.amqp.rabbit.connection.ConnectionFactory; | ||
| import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
| import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; | ||
| import org.springframework.amqp.support.converter.MessageConverter; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| public class RabbitMQConfig { | ||
| private static final String EXCHANGE_NAME = "zoopzoop.exchange"; | ||
| private static final String QUEUE_NAME = "graph.update.queue"; | ||
| private static final String ROUTING_KEY = "graph.update.#"; | ||
|
|
||
| private static final String DLQ_EXCHANGE_NAME = EXCHANGE_NAME + ".dlx"; | ||
| private static final String DLQ_QUEUE_NAME = QUEUE_NAME + ".dlq"; | ||
| private static final String DLQ_ROUTING_KEY = "graph.update.dlq"; | ||
|
|
||
| @Bean | ||
| public TopicExchange exchange() { | ||
| return new TopicExchange(EXCHANGE_NAME); | ||
| } | ||
|
|
||
| @Bean | ||
| public Queue queue() { | ||
| return QueueBuilder.durable(QUEUE_NAME) | ||
| .withArgument("x-dead-letter-exchange", DLQ_EXCHANGE_NAME) // 실패 시 메시지를 보낼 Exchange | ||
| .withArgument("x-dead-letter-routing-key", DLQ_ROUTING_KEY) // 실패 시 사용할 라우팅 키 | ||
| .build(); | ||
| } | ||
|
|
||
| @Bean | ||
| public Binding binding(Queue queue, TopicExchange exchange) { | ||
| return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY); | ||
| } | ||
|
|
||
| // ================= DLQ 인프라 구성 추가 ================= // | ||
|
|
||
| @Bean | ||
| public TopicExchange dlqExchange() { | ||
| return new TopicExchange(DLQ_EXCHANGE_NAME); | ||
| } | ||
|
|
||
| @Bean | ||
| public Queue dlqQueue() { | ||
| return new Queue(DLQ_QUEUE_NAME); | ||
| } | ||
|
|
||
| @Bean | ||
| public Binding dlqBinding(Queue dlqQueue, TopicExchange dlqExchange) { | ||
| return BindingBuilder.bind(dlqQueue).to(dlqExchange).with(DLQ_ROUTING_KEY); | ||
| } | ||
|
|
||
| // ================= DLQ 인프라 구성 추가 ================= // | ||
| @Bean | ||
| public MessageConverter messageConverter() { | ||
| // 메시지를 JSON 형식으로 직렬화/역직렬화하는 컨버터 | ||
| return new Jackson2JsonMessageConverter(); | ||
| } | ||
|
|
||
| @Bean | ||
| public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory, MessageConverter messageConverter) { | ||
| RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory); | ||
| rabbitTemplate.setMessageConverter(messageConverter); | ||
| return rabbitTemplate; | ||
| } | ||
| } |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.