File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
src/main/java/org/tuna/zoopzoop/backend/domain/dashboard Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change 33import jakarta .persistence .CascadeType ;
44import jakarta .persistence .Entity ;
55import jakarta .persistence .OneToMany ;
6+ import jakarta .persistence .Version ;
67import lombok .Getter ;
78import lombok .Setter ;
89import org .tuna .zoopzoop .backend .global .jpa .entity .BaseEntity ;
1415@ Setter
1516@ Entity
1617public class Graph extends BaseEntity {
18+
19+ @ Version
20+ private Long version ;
21+
1722 @ OneToMany (mappedBy = "graph" , cascade = CascadeType .ALL , orphanRemoval = true )
1823 private List <Node > nodes = new ArrayList <>();
1924
Original file line number Diff line number Diff line change 44import lombok .RequiredArgsConstructor ;
55import lombok .extern .slf4j .Slf4j ;
66import org .springframework .amqp .rabbit .annotation .RabbitListener ;
7+ import org .springframework .orm .ObjectOptimisticLockingFailureException ;
78import org .springframework .stereotype .Component ;
89import org .tuna .zoopzoop .backend .domain .dashboard .dto .BodyForReactFlow ;
910import org .tuna .zoopzoop .backend .domain .dashboard .dto .GraphUpdateMessage ;
@@ -23,6 +24,12 @@ public void handleGraphUpdate(GraphUpdateMessage message) {
2324 BodyForReactFlow dto = objectMapper .readValue (message .requestBody (), BodyForReactFlow .class );
2425 dashboardService .updateGraph (message .dashboardId (), dto );
2526 log .info ("Successfully updated graph for dashboardId: {}" , message .dashboardId ());
27+ } catch (ObjectOptimisticLockingFailureException e ) {
28+ // Optimistic Lock 충돌 발생!
29+ // 내가 처리하려던 메시지는 이미 구버전 데이터에 대한 요청이었음.
30+ // 따라서 이 메시지는 무시하고 정상 처리된 것으로 간주.
31+ log .warn ("Stale update attempt for dashboardId: {}. A newer version already exists. Discarding message." , message .dashboardId ());
32+ // 예외를 다시 던지지 않으므로, 메시지는 큐에서 정상적으로 제거(ACK)됩니다.
2633 } catch (Exception e ) {
2734 // 실제 운영에서는 메시지를 재시도하거나, 실패 큐(Dead Letter Queue)로 보내는 등의
2835 // 정교한 에러 처리 로직이 필요합니다.
You can’t perform that action at this time.
0 commit comments