From 3acff9e5230c1731bd3e0fd8edc9b29b1d75f0cd Mon Sep 17 00:00:00 2001 From: bviz6542 Date: Tue, 9 Jul 2024 22:02:29 +0900 Subject: [PATCH 1/3] fix: SimpMessageSendingOperations --- .../service/GatheringSessionService.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/example/swiftgathering_server/service/GatheringSessionService.java b/src/main/java/com/example/swiftgathering_server/service/GatheringSessionService.java index 5d26c31..8784239 100644 --- a/src/main/java/com/example/swiftgathering_server/service/GatheringSessionService.java +++ b/src/main/java/com/example/swiftgathering_server/service/GatheringSessionService.java @@ -8,11 +8,7 @@ import com.example.swiftgathering_server.repository.GatheringSessionRepository; import com.example.swiftgathering_server.repository.MemberRepository; import lombok.RequiredArgsConstructor; -import org.springframework.amqp.core.Binding; -import org.springframework.amqp.core.BindingBuilder; -import org.springframework.amqp.core.Queue; -import org.springframework.amqp.core.DirectExchange; -import org.springframework.amqp.core.AmqpTemplate; +import org.springframework.messaging.simp.SimpMessageSendingOperations; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -28,7 +24,7 @@ public class GatheringSessionService { private final MemberRepository memberRepository; private final GatheringSessionRepository gatheringSessionRepository; // private final FlagLocationRepository flagLocationRepository; - private final AmqpTemplate amqpTemplate; + private final SimpMessageSendingOperations messagingTemplate; public void createSession(CreateSessionRequestDto requestDto) { List sessionMembers = memberRepository @@ -71,11 +67,8 @@ private void notifyClients(GatheringSession session) { .collect(Collectors.toList()); for (Long memberId : memberIds) { - Queue queue = new Queue("swift-gathering.queue." + memberId, false); - DirectExchange exchange = new DirectExchange("swift-gathering.exchange." + memberId); - Binding binding = BindingBuilder.bind(queue).to(exchange).with("swift-gathering.routing." + memberId); GatheringSessionNotificationDto notification = new GatheringSessionNotificationDto(session.getId(), memberIds); - amqpTemplate.convertAndSend(exchange.getName(), binding.getRoutingKey(), notification); + messagingTemplate.convertAndSend("/topic/private/" + memberId, notification); } } } \ No newline at end of file From 21757d3805df5e5ad67f0e1343651da9f37eb3c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=EC=A4=80=EC=9A=B0?= Date: Sun, 14 Jul 2024 15:06:24 +0900 Subject: [PATCH 2/3] fix: websocket client endpoint to dot not slash --- .../swiftgathering_server/service/GatheringSessionService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/swiftgathering_server/service/GatheringSessionService.java b/src/main/java/com/example/swiftgathering_server/service/GatheringSessionService.java index 8784239..78091c9 100644 --- a/src/main/java/com/example/swiftgathering_server/service/GatheringSessionService.java +++ b/src/main/java/com/example/swiftgathering_server/service/GatheringSessionService.java @@ -68,7 +68,7 @@ private void notifyClients(GatheringSession session) { for (Long memberId : memberIds) { GatheringSessionNotificationDto notification = new GatheringSessionNotificationDto(session.getId(), memberIds); - messagingTemplate.convertAndSend("/topic/private/" + memberId, notification); + messagingTemplate.convertAndSend("/topic/private." + memberId, notification); } } } \ No newline at end of file From 39ac62b9f65af38b25af48489189623689aeb4da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=EC=A4=80=EC=9A=B0?= Date: Sun, 14 Jul 2024 17:08:22 +0900 Subject: [PATCH 3/3] feature: CreatedSessionIdDto for session creater --- .../controller/GatheringSessionController.java | 7 ++++--- .../domain/GatheringSession.java | 2 +- .../dto/CreatedSessionIdDto.java | 12 ++++++++++++ .../dto/GatheringSessionNotificationDto.java | 4 ++-- .../service/GatheringSessionService.java | 7 +++++-- 5 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/example/swiftgathering_server/dto/CreatedSessionIdDto.java diff --git a/src/main/java/com/example/swiftgathering_server/controller/GatheringSessionController.java b/src/main/java/com/example/swiftgathering_server/controller/GatheringSessionController.java index 1f335de..88dc2b7 100644 --- a/src/main/java/com/example/swiftgathering_server/controller/GatheringSessionController.java +++ b/src/main/java/com/example/swiftgathering_server/controller/GatheringSessionController.java @@ -1,6 +1,7 @@ package com.example.swiftgathering_server.controller; import com.example.swiftgathering_server.dto.CreateSessionRequestDto; +import com.example.swiftgathering_server.dto.CreatedSessionIdDto; import com.example.swiftgathering_server.dto.ParticipateSessionRequestDto; import com.example.swiftgathering_server.service.GatheringSessionService; import lombok.RequiredArgsConstructor; @@ -15,9 +16,9 @@ public class GatheringSessionController { private final GatheringSessionService gatheringSessionService; @PostMapping - public ResponseEntity createSession(@RequestBody CreateSessionRequestDto requestDto) { - gatheringSessionService.createSession(requestDto); - return ResponseEntity.ok().build(); + public ResponseEntity createSession(@RequestBody CreateSessionRequestDto requestDto) { + CreatedSessionIdDto createdSessionIdDto = gatheringSessionService.createSession(requestDto); + return ResponseEntity.ok(createdSessionIdDto); } @PatchMapping diff --git a/src/main/java/com/example/swiftgathering_server/domain/GatheringSession.java b/src/main/java/com/example/swiftgathering_server/domain/GatheringSession.java index 2b34880..c46c1f3 100644 --- a/src/main/java/com/example/swiftgathering_server/domain/GatheringSession.java +++ b/src/main/java/com/example/swiftgathering_server/domain/GatheringSession.java @@ -20,7 +20,7 @@ public class GatheringSession { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - private UUID sessionId = UUID.randomUUID(); + private final UUID sessionId = UUID.randomUUID(); private LocalDateTime createdTime; @ElementCollection diff --git a/src/main/java/com/example/swiftgathering_server/dto/CreatedSessionIdDto.java b/src/main/java/com/example/swiftgathering_server/dto/CreatedSessionIdDto.java new file mode 100644 index 0000000..e6da228 --- /dev/null +++ b/src/main/java/com/example/swiftgathering_server/dto/CreatedSessionIdDto.java @@ -0,0 +1,12 @@ +package com.example.swiftgathering_server.dto; + +import lombok.Getter; + +@Getter +public class CreatedSessionIdDto { + private final String sessionId; + + public CreatedSessionIdDto(String sessionId) { + this.sessionId = sessionId; + } +} diff --git a/src/main/java/com/example/swiftgathering_server/dto/GatheringSessionNotificationDto.java b/src/main/java/com/example/swiftgathering_server/dto/GatheringSessionNotificationDto.java index fd749b2..57a0f71 100644 --- a/src/main/java/com/example/swiftgathering_server/dto/GatheringSessionNotificationDto.java +++ b/src/main/java/com/example/swiftgathering_server/dto/GatheringSessionNotificationDto.java @@ -6,10 +6,10 @@ @Getter public class GatheringSessionNotificationDto { - final private Long sessionId; + final private String sessionId; final private List participantIds; - public GatheringSessionNotificationDto(Long sessionId, List participantIds) { + public GatheringSessionNotificationDto(String sessionId, List participantIds) { this.sessionId = sessionId; this.participantIds = participantIds; } diff --git a/src/main/java/com/example/swiftgathering_server/service/GatheringSessionService.java b/src/main/java/com/example/swiftgathering_server/service/GatheringSessionService.java index 78091c9..b4f7706 100644 --- a/src/main/java/com/example/swiftgathering_server/service/GatheringSessionService.java +++ b/src/main/java/com/example/swiftgathering_server/service/GatheringSessionService.java @@ -2,6 +2,7 @@ import com.example.swiftgathering_server.domain.*; import com.example.swiftgathering_server.dto.CreateSessionRequestDto; +import com.example.swiftgathering_server.dto.CreatedSessionIdDto; import com.example.swiftgathering_server.dto.GatheringSessionNotificationDto; import com.example.swiftgathering_server.dto.ParticipateSessionRequestDto; import com.example.swiftgathering_server.exception.ResourceNotFoundException; @@ -26,7 +27,7 @@ public class GatheringSessionService { // private final FlagLocationRepository flagLocationRepository; private final SimpMessageSendingOperations messagingTemplate; - public void createSession(CreateSessionRequestDto requestDto) { + public CreatedSessionIdDto createSession(CreateSessionRequestDto requestDto) { List sessionMembers = memberRepository .findAllByIds(requestDto.getGuestIds()).stream() .map(member -> GatheringSessionMember.builder() @@ -43,6 +44,8 @@ public void createSession(CreateSessionRequestDto requestDto) { GatheringSession savedSession = gatheringSessionRepository.save(session); notifyClients(savedSession); + + return new CreatedSessionIdDto(savedSession.getSessionId().toString()); } public void participateSession(ParticipateSessionRequestDto requestDto) { @@ -67,7 +70,7 @@ private void notifyClients(GatheringSession session) { .collect(Collectors.toList()); for (Long memberId : memberIds) { - GatheringSessionNotificationDto notification = new GatheringSessionNotificationDto(session.getId(), memberIds); + GatheringSessionNotificationDto notification = new GatheringSessionNotificationDto(session.getSessionId().toString(), memberIds); messagingTemplate.convertAndSend("/topic/private." + memberId, notification); } }