diff --git a/src/backend/chatting-server/build.gradle b/src/backend/chatting-server/build.gradle index 48bc0db9..37d089ab 100644 --- a/src/backend/chatting-server/build.gradle +++ b/src/backend/chatting-server/build.gradle @@ -35,9 +35,21 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' + implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:4.1.0' + annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' } +ext { + set('springCloudVersion', "2023.0.0") +} + +dependencyManagement { + imports { + mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" + } +} + tasks.named('test') { useJUnitPlatform() } diff --git a/src/backend/chatting-server/src/main/java/chattingserver/config/AsyncConfig.java b/src/backend/chatting-server/src/main/java/chattingserver/config/AsyncConfig.java new file mode 100644 index 00000000..af102a78 --- /dev/null +++ b/src/backend/chatting-server/src/main/java/chattingserver/config/AsyncConfig.java @@ -0,0 +1,29 @@ +package chattingserver.config; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +import java.util.concurrent.Executor; + +@Slf4j +@EnableAsync +@Configuration +public class AsyncConfig { + + @Bean(name = "search") + public Executor pushAsyncExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + int processors = Runtime.getRuntime().availableProcessors(); + log.info("processors count {}", processors); + executor.setThreadNamePrefix("SearchAsync- "); + executor.setCorePoolSize(processors); + executor.setMaxPoolSize(processors * 2); + executor.setQueueCapacity(50); + executor.setKeepAliveSeconds(60); + executor.initialize(); + return executor; + } +} diff --git a/src/backend/chatting-server/src/main/java/chattingserver/config/OpenFeignConfig.java b/src/backend/chatting-server/src/main/java/chattingserver/config/OpenFeignConfig.java new file mode 100644 index 00000000..893bcbab --- /dev/null +++ b/src/backend/chatting-server/src/main/java/chattingserver/config/OpenFeignConfig.java @@ -0,0 +1,10 @@ +package chattingserver.config; + +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableFeignClients(basePackages = {"chattingserver.controller"}) +public class OpenFeignConfig { + +} diff --git a/src/backend/chatting-server/src/main/java/chattingserver/config/kafka/Consumers.java b/src/backend/chatting-server/src/main/java/chattingserver/config/kafka/Consumers.java index 03971aca..b964907f 100644 --- a/src/backend/chatting-server/src/main/java/chattingserver/config/kafka/Consumers.java +++ b/src/backend/chatting-server/src/main/java/chattingserver/config/kafka/Consumers.java @@ -1,8 +1,7 @@ package chattingserver.config.kafka; import chattingserver.dto.ChatMessageDto; -import chattingserver.dto.RoomMessageDto; -import chattingserver.dto.response.RoomResponseDto; +import chattingserver.dto.request.IndexingRequestMessageDto; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.kafka.annotation.KafkaListener; @@ -20,11 +19,11 @@ public void listenChat(ChatMessageDto chatMessageDto) { template.convertAndSend("/chat/topic/room/" + chatMessageDto.getRoomId(), chatMessageDto); } + // TODO search indexing test용 추후 삭제 예정 @KafkaListener(groupId = "${spring.kafka.consumer.room-consumer.group-id}", topics = "${kafka.topic.room-name}", containerFactory = "kafkaListenerContainerFactory") - public void listenGroupCreation(RoomMessageDto roomMessageDto) { - RoomResponseDto roomResponseDto = roomMessageDto.getRoomResponseDto(); - for (Long userId : roomMessageDto.getReceivers()) { - template.convertAndSend("/chat/topic/new-room/" + userId, roomResponseDto); - } + public void listenRoomCreation(IndexingRequestMessageDto indexingRequestMessageDto) { + + template.convertAndSend("/chat/topic/search/room/index", indexingRequestMessageDto); + } } \ No newline at end of file diff --git a/src/backend/chatting-server/src/main/java/chattingserver/config/kafka/KafkaProducerConfig.java b/src/backend/chatting-server/src/main/java/chattingserver/config/kafka/KafkaProducerConfig.java index 5edcd8c1..2e29ab36 100644 --- a/src/backend/chatting-server/src/main/java/chattingserver/config/kafka/KafkaProducerConfig.java +++ b/src/backend/chatting-server/src/main/java/chattingserver/config/kafka/KafkaProducerConfig.java @@ -1,8 +1,7 @@ package chattingserver.config.kafka; import chattingserver.dto.ChatMessageDto; -import chattingserver.dto.RoomMessageDto; -import chattingserver.dto.response.ChatMessageResponseDto; +import chattingserver.dto.request.IndexingRequestMessageDto; import org.apache.kafka.clients.producer.ProducerConfig; import org.apache.kafka.common.serialization.StringSerializer; import org.springframework.beans.factory.annotation.Value; @@ -51,7 +50,7 @@ public KafkaTemplate chatKafkaTemplate() { } @Bean - public ProducerFactory roomProducerFactory() { + public ProducerFactory roomProducerFactory() { return new DefaultKafkaProducerFactory<>(roomProducerConfigurations()); } @@ -65,7 +64,7 @@ public Map roomProducerConfigurations() { } @Bean - public KafkaTemplate roomKafkaTemplate() { + public KafkaTemplate roomKafkaTemplate() { return new KafkaTemplate<>(roomProducerFactory()); } } diff --git a/src/backend/chatting-server/src/main/java/chattingserver/config/kafka/Producers.java b/src/backend/chatting-server/src/main/java/chattingserver/config/kafka/Producers.java index fc19a579..bd2f824d 100644 --- a/src/backend/chatting-server/src/main/java/chattingserver/config/kafka/Producers.java +++ b/src/backend/chatting-server/src/main/java/chattingserver/config/kafka/Producers.java @@ -1,9 +1,8 @@ package chattingserver.config.kafka; -import chattingserver.domain.room.User; import chattingserver.dto.ChatMessageDto; import chattingserver.dto.RoomMessageDto; -import chattingserver.dto.response.ChatMessageResponseDto; +import chattingserver.dto.request.IndexingRequestMessageDto; import chattingserver.dto.response.RoomResponseDto; import chattingserver.dto.response.UserListResponseDto; import chattingserver.service.ChatMessageService; @@ -32,23 +31,23 @@ public class Producers { @Value("${kafka.topic.room-name}") private String topicRoomName; - private final KafkaTemplate roomKafkaTemplate; + private final KafkaTemplate roomKafkaTemplate; private final ChatMessageService chatMessageService; private final RoomService roomService; public void sendMessage(ChatMessageDto chatMessageDto) { - if (chatMessageDto.getMessageType() == MessageType.ENTRANCE) { - log.info("producers.sendMessage.if MessageType == ENTRANCE"); + if (chatMessageDto.getMessageType() == MessageType.CREATION) { RoomResponseDto roomResponseDto = roomService.getRoomInfo(chatMessageDto.getRoomId()); List receivers = roomResponseDto.getUsers().stream().map(UserListResponseDto::getUid).collect(Collectors.toList()); receivers.remove(chatMessageDto.getSenderId()); - sendRoomMessage(RoomMessageDto.builder() - .receivers(receivers) - .roomResponseDto(roomResponseDto) + sendRoomMessage(IndexingRequestMessageDto.builder() + .roomId(roomResponseDto.getId()) + .roomName(roomResponseDto.getRoomName()) + .playlistId(roomResponseDto.getPlaylist().getId()) + .thumbnailImage(roomResponseDto.getThumbnailImage()) .build()); } else { - log.info("producers.sendMessage.if MessageType != ENTRANCE"); CompletableFuture> completableFuture = chatKafkaTemplate.send(topicChatName, chatMessageDto); completableFuture.whenComplete((result, ex) -> { @@ -63,14 +62,14 @@ public void sendMessage(ChatMessageDto chatMessageDto) { } } - public void sendRoomMessage(RoomMessageDto roomMessageDto) { - CompletableFuture> completableFuture = roomKafkaTemplate.send(topicRoomName, roomMessageDto); + public void sendRoomMessage(IndexingRequestMessageDto roomMessageDto) { + CompletableFuture> completableFuture = roomKafkaTemplate.send(topicRoomName, roomMessageDto); completableFuture.whenComplete((result, ex) -> { if (ex == null) { - log.info("메시지 전송 성공=[" + roomMessageDto.getRoomResponseDto().getId() + "] with offset=[" + result.getRecordMetadata().offset() + "]"); + log.info("메시지 전송 성공=[" + roomMessageDto.getRoomId() + "] with offset=[" + result.getRecordMetadata().offset() + "]"); log.info("roomMessageDto={}", roomMessageDto.toString()); } else { - log.info("메시지 전송 불가=[" + roomMessageDto.getRoomResponseDto().getId() + "] 원인 : " + ex.getMessage()); + log.info("메시지 전송 불가=[" + roomMessageDto.getRoomId() + "] 원인 : " + ex.getMessage()); } }); } diff --git a/src/backend/chatting-server/src/main/java/chattingserver/config/util/SwaggerConfig.java b/src/backend/chatting-server/src/main/java/chattingserver/config/util/SwaggerConfig.java index d8abc5c2..11f77c88 100644 --- a/src/backend/chatting-server/src/main/java/chattingserver/config/util/SwaggerConfig.java +++ b/src/backend/chatting-server/src/main/java/chattingserver/config/util/SwaggerConfig.java @@ -17,7 +17,7 @@ public class SwaggerConfig { @Bean public GroupedOpenApi chatOpenApi() { - String[] paths = {"/api/**", "/chat/**"}; + String[] paths = {"/v1/**", "/**/chat"}; return GroupedOpenApi.builder() .group("CHATTING-SERVER API V1") diff --git a/src/backend/chatting-server/src/main/java/chattingserver/controller/ChatController.java b/src/backend/chatting-server/src/main/java/chattingserver/controller/ChatController.java index 7a6121f2..760c7603 100644 --- a/src/backend/chatting-server/src/main/java/chattingserver/controller/ChatController.java +++ b/src/backend/chatting-server/src/main/java/chattingserver/controller/ChatController.java @@ -27,7 +27,7 @@ @Tag(name = "chat", description = "채팅 API") @RequiredArgsConstructor @RestController -@RequestMapping("/chat") +@RequestMapping("v1/api/chat") @Slf4j public class ChatController { @@ -90,7 +90,7 @@ public ResponseEntity allMessagesAtRoom(@PathVariable String r return new ResponseEntity<>(apiMessage, HttpStatus.OK); } - @Operation(summary = "채팅 메시지 Pagination", description = "내림차순으로 해당 채팅방 메시지 Pagination, 사이즈 N = 12 고정") + @Operation(summary = "채팅 메시지 Pagination", description = "내림차순으로 해당 채팅방 메시지 Pagination, 사이즈 N = 20 고정") @GetMapping("/history") public ResponseEntity chatMessagePagination( @RequestParam String roomId, diff --git a/src/backend/chatting-server/src/main/java/chattingserver/controller/RoomController.java b/src/backend/chatting-server/src/main/java/chattingserver/controller/RoomController.java index 59d60616..e8fae3bf 100644 --- a/src/backend/chatting-server/src/main/java/chattingserver/controller/RoomController.java +++ b/src/backend/chatting-server/src/main/java/chattingserver/controller/RoomController.java @@ -1,17 +1,16 @@ package chattingserver.controller; import chattingserver.config.kafka.Producers; -import chattingserver.domain.room.User; -import chattingserver.dto.RoomMessageDto; +import chattingserver.dto.request.IndexingRequestMessageDto; import chattingserver.dto.request.ReadMessageUpdateRequestDto; import chattingserver.dto.request.RoomCreateRequestDto; import chattingserver.dto.request.UserEntranceRequestDto; import chattingserver.dto.response.CommonAPIMessage; import chattingserver.dto.response.JoinedRoomResponseDto; import chattingserver.dto.response.RoomResponseDto; -import chattingserver.dto.response.UserListResponseDto; import chattingserver.service.ChatMessageService; import chattingserver.service.RoomService; +import chattingserver.service.SearchService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -26,17 +25,17 @@ import java.util.HashMap; import java.util.List; -import java.util.stream.Collectors; @Tag(name = "room", description = "채팅방 API") @Slf4j @RestController -@RequestMapping("/api/v1/rooms") +@RequestMapping("/v1/api/rooms") @RequiredArgsConstructor public class RoomController { private final RoomService roomService; private final ChatMessageService chatMessageService; + private final SearchService searchService; private final Producers producers; @Operation(summary = "채팅방 생성 API", description = "신규 채팅방 생성", responses = { @@ -47,15 +46,19 @@ public ResponseEntity groupCreation(@Valid @RequestBody RoomCr RoomResponseDto roomResponseDto = roomService.create(roomCreateRequestDto); - producers.sendRoomMessage(RoomMessageDto.builder() - .receivers(roomResponseDto.getUsers().stream().map(UserListResponseDto::getUid).collect(Collectors.toList())) - .roomResponseDto(roomResponseDto) + producers.sendRoomMessage(IndexingRequestMessageDto.builder() + .roomId(roomResponseDto.getId()) + .roomName(roomResponseDto.getRoomName()) + .playlistId(roomResponseDto.getPlaylist().getId()) + .thumbnailImage(roomResponseDto.getThumbnailImage()) .build()); CommonAPIMessage apiMessage = new CommonAPIMessage(); apiMessage.setMessage(CommonAPIMessage.ResultEnum.success); apiMessage.setData(roomResponseDto); + searchService.sendIndexingRequestToSearchServer(roomResponseDto); + return new ResponseEntity<>(apiMessage, HttpStatus.CREATED); } diff --git a/src/backend/chatting-server/src/main/java/chattingserver/controller/SearchProxy.java b/src/backend/chatting-server/src/main/java/chattingserver/controller/SearchProxy.java new file mode 100644 index 00000000..3849c2a9 --- /dev/null +++ b/src/backend/chatting-server/src/main/java/chattingserver/controller/SearchProxy.java @@ -0,0 +1,12 @@ +package chattingserver.controller; + +import chattingserver.dto.request.IndexingRequestMessageDto; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +@FeignClient(name = "search-service", url = "localhost:20000") +public interface SearchProxy { + @PostMapping("/search/index/send") + void sendIndexingRequest(@RequestBody IndexingRequestMessageDto dto); +} diff --git a/src/backend/chatting-server/src/main/java/chattingserver/dto/request/IndexingRequestMessageDto.java b/src/backend/chatting-server/src/main/java/chattingserver/dto/request/IndexingRequestMessageDto.java new file mode 100644 index 00000000..5b386da8 --- /dev/null +++ b/src/backend/chatting-server/src/main/java/chattingserver/dto/request/IndexingRequestMessageDto.java @@ -0,0 +1,16 @@ +package chattingserver.dto.request; + +import lombok.*; + + +@ToString +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Builder +public class IndexingRequestMessageDto { + private String roomId; + private String roomName; + private String playlistId; + private String thumbnailImage; +} \ No newline at end of file diff --git a/src/backend/chatting-server/src/main/java/chattingserver/dto/request/ReadMessageUpdateRequestDto.java b/src/backend/chatting-server/src/main/java/chattingserver/dto/request/ReadMessageUpdateRequestDto.java index 1d4e313c..a19b5187 100644 --- a/src/backend/chatting-server/src/main/java/chattingserver/dto/request/ReadMessageUpdateRequestDto.java +++ b/src/backend/chatting-server/src/main/java/chattingserver/dto/request/ReadMessageUpdateRequestDto.java @@ -14,7 +14,7 @@ public class ReadMessageUpdateRequestDto { @NotBlank private String roomId; @NotBlank - private String uid; + private Long uid; @NotBlank private String messageId; } \ No newline at end of file diff --git a/src/backend/chatting-server/src/main/java/chattingserver/repository/ChatMessageRepositoryImpl.java b/src/backend/chatting-server/src/main/java/chattingserver/repository/ChatMessageRepositoryImpl.java index 3bb5b713..4aa39c9a 100644 --- a/src/backend/chatting-server/src/main/java/chattingserver/repository/ChatMessageRepositoryImpl.java +++ b/src/backend/chatting-server/src/main/java/chattingserver/repository/ChatMessageRepositoryImpl.java @@ -77,9 +77,10 @@ public ChatMessage getLastMessage(String roomId) { @Override public List findPreviousMessages(String roomId, String readMsgId, int limit) { + ObjectId readMsgObjectId = new ObjectId(readMsgId); Query query = new Query(); - query.addCriteria(Criteria.where("roomId").is(roomId).and("_id").lt(readMsgId)); // 이전 메시지만 가져오도록 쿼리 설정 - query.limit(20); // 최대 20개의 메시지 가져오도록 제한 설정 + query.addCriteria(Criteria.where("roomId").is(roomId).and("_id").lt(readMsgObjectId)); + query.limit(20); return mongoTemplate.find(query, ChatMessage.class); } } diff --git a/src/backend/chatting-server/src/main/java/chattingserver/repository/RoomRepository.java b/src/backend/chatting-server/src/main/java/chattingserver/repository/RoomRepository.java index ef6fa013..884de581 100644 --- a/src/backend/chatting-server/src/main/java/chattingserver/repository/RoomRepository.java +++ b/src/backend/chatting-server/src/main/java/chattingserver/repository/RoomRepository.java @@ -1,6 +1,7 @@ package chattingserver.repository; import chattingserver.domain.room.Room; +import chattingserver.domain.room.User; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.Query; @@ -24,4 +25,6 @@ public interface RoomRepository extends MongoRepository, RoomRepos @Override boolean existsById(String s); + + } \ No newline at end of file diff --git a/src/backend/chatting-server/src/main/java/chattingserver/repository/RoomRepositoryCustom.java b/src/backend/chatting-server/src/main/java/chattingserver/repository/RoomRepositoryCustom.java index d63a123c..00007873 100644 --- a/src/backend/chatting-server/src/main/java/chattingserver/repository/RoomRepositoryCustom.java +++ b/src/backend/chatting-server/src/main/java/chattingserver/repository/RoomRepositoryCustom.java @@ -1,10 +1,13 @@ package chattingserver.repository; +import chattingserver.domain.room.User; import chattingserver.dto.request.ReadMessageUpdateRequestDto; import com.mongodb.client.result.UpdateResult; public interface RoomRepositoryCustom { void exitRoom(String roomId, Long uid); + UpdateResult addUserToRoom(String roomId, User user); + UpdateResult updateLastReadMsgId(ReadMessageUpdateRequestDto requestDto); } diff --git a/src/backend/chatting-server/src/main/java/chattingserver/repository/RoomRepositoryImpl.java b/src/backend/chatting-server/src/main/java/chattingserver/repository/RoomRepositoryImpl.java index 63135945..c8acc799 100644 --- a/src/backend/chatting-server/src/main/java/chattingserver/repository/RoomRepositoryImpl.java +++ b/src/backend/chatting-server/src/main/java/chattingserver/repository/RoomRepositoryImpl.java @@ -1,6 +1,7 @@ package chattingserver.repository; import chattingserver.domain.room.Room; +import chattingserver.domain.room.User; import chattingserver.dto.request.ReadMessageUpdateRequestDto; import com.mongodb.client.result.UpdateResult; import org.springframework.data.mongodb.core.MongoTemplate; @@ -29,12 +30,18 @@ public void exitRoom(String roomId, Long uid) { public UpdateResult updateLastReadMsgId(ReadMessageUpdateRequestDto requestDto) { Query query = Query.query( - Criteria.where("roomId").is(requestDto.getRoomId()) + Criteria.where("_id").is(requestDto.getRoomId()) .andOperator(Criteria.where("users").elemMatch(Criteria.where("uid").is(requestDto.getUid()))) ); Update update = new Update().set("users.$.lastReadMessageId", requestDto.getMessageId()); + return mongoTemplate.updateFirst(query, update, Room.class); + } + @Override + public UpdateResult addUserToRoom(String roomId, User user) { + Query query = new Query(Criteria.where("_id").is(roomId)); + Update update = new Update().addToSet("users", user); return mongoTemplate.updateFirst(query, update, Room.class); } } \ No newline at end of file diff --git a/src/backend/chatting-server/src/main/java/chattingserver/service/ChatMessageService.java b/src/backend/chatting-server/src/main/java/chattingserver/service/ChatMessageService.java index 5d749507..a2fa95bf 100644 --- a/src/backend/chatting-server/src/main/java/chattingserver/service/ChatMessageService.java +++ b/src/backend/chatting-server/src/main/java/chattingserver/service/ChatMessageService.java @@ -14,7 +14,9 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; +import org.springframework.data.mongodb.MongoTransactionManager; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; @@ -35,6 +37,7 @@ public class ChatMessageService { private final RoomRepository roomRepository; private final EntityToResponseDtoConverter entityToResponseDtoConverter; + private static final int SIZE = 20; public void sendMessage(WebSocketSession session, T message) { @@ -87,39 +90,44 @@ public void deleteChat(String id) { chatMessageRepository.deleteById(id); } + @Transactional public ChatMessageDto join(ChatMessageDto chatMessageDto) { + try { + Optional optionalRoom = roomRepository.findById(chatMessageDto.getRoomId()); + if (optionalRoom.isEmpty()) { + log.info("해당하는 방이 없습니다. roomId={}", chatMessageDto.getRoomId()); + // TODO null처리 + return null; + } - Optional optionalRoom = roomRepository.findById(chatMessageDto.getRoomId()); - if (optionalRoom.isEmpty()) { - log.info("해당하는 방이 없습니다. roomId={}", chatMessageDto.getRoomId()); - // TODO null처리 - return null; + Room room = optionalRoom.get(); + + ChatMessage message = chatMessageRepository.save(ChatMessage.builder() + .messageType(MessageType.ENTRANCE) + .roomId(chatMessageDto.getRoomId()) + .senderId(chatMessageDto.getSenderId()) + .nickName(chatMessageDto.getNickName()) + .content(chatMessageDto.getNickName() + "님이 입장하셨습니다.") + .senderProfileImage(chatMessageDto.getSenderProfileImage()) + .createdAt(LocalDateTime.now()) + .build()); + + User joinedUser = User.builder() + .uid(chatMessageDto.getSenderId()) + .nickName(chatMessageDto.getNickName()) + .profileImage(chatMessageDto.getSenderProfileImage()) + .enteredAt(LocalDateTime.now()) + .lastReadMessageId(message.getId()) + .build(); + + roomRepository.addUserToRoom(room.getId(), joinedUser); + + return entityToResponseDtoConverter.convertMessage(message); + } catch (Exception e) { + log.error("트랜잭션 오류: {}", e.getMessage()); + // TODO 트랜잭션 롤백 또는 예외 처리 로직 추가 + throw new RuntimeException("트랜잭션 오류 발생"); } - - Room room = optionalRoom.get(); - - ChatMessage message = chatMessageRepository.save(ChatMessage.builder() - .messageType(MessageType.ENTRANCE) - .roomId(chatMessageDto.getRoomId()) - .senderId(chatMessageDto.getSenderId()) - .nickName(chatMessageDto.getNickName()) - .content(chatMessageDto.getNickName() + "님이 입장하셨습니다.") - .senderProfileImage(chatMessageDto.getSenderProfileImage()) - .createdAt(LocalDateTime.now()) - .build()); - - User joinedUser = User.builder() - .uid(chatMessageDto.getSenderId()) - .nickName(chatMessageDto.getNickName()) - .profileImage(chatMessageDto.getSenderProfileImage()) - .enteredAt(LocalDateTime.now()) - .lastReadMessageId(message.getId()) - .build(); - - room.getUsers().add(joinedUser); - - return entityToResponseDtoConverter.convertMessage(message); - } public ChatMessageDto permanentLeaving(String roomId, UserEntranceRequestDto userDto) { diff --git a/src/backend/chatting-server/src/main/java/chattingserver/service/SearchService.java b/src/backend/chatting-server/src/main/java/chattingserver/service/SearchService.java new file mode 100644 index 00000000..6a3beddd --- /dev/null +++ b/src/backend/chatting-server/src/main/java/chattingserver/service/SearchService.java @@ -0,0 +1,33 @@ +package chattingserver.service; + +import chattingserver.controller.SearchProxy; +import chattingserver.dto.request.IndexingRequestMessageDto; +import chattingserver.dto.response.RoomResponseDto; +import feign.FeignException; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@Async("search") +@RequiredArgsConstructor +public class SearchService { + private final SearchProxy searchProxy; + + public void sendIndexingRequestToSearchServer(RoomResponseDto roomResponseDto) { + + try { + searchProxy.sendIndexingRequest(IndexingRequestMessageDto.builder() + .roomId(roomResponseDto.getId()) + .roomName(roomResponseDto.getRoomName()) + .playlistId(roomResponseDto.getPlaylist().getId()) + .thumbnailImage(roomResponseDto.getThumbnailImage()) + .build()); + } catch (FeignException e) { + log.error("searchProxy.sendIndexingRequest, 검색 서버 연결 불가"); + } + log.info("검색 서버에 인덱싱 요청 성공"); + } +} diff --git a/src/backend/chatting-server/src/main/java/chattingserver/util/constant/MessageType.java b/src/backend/chatting-server/src/main/java/chattingserver/util/constant/MessageType.java index 907e16c8..622149e2 100644 --- a/src/backend/chatting-server/src/main/java/chattingserver/util/constant/MessageType.java +++ b/src/backend/chatting-server/src/main/java/chattingserver/util/constant/MessageType.java @@ -1,5 +1,5 @@ package chattingserver.util.constant; public enum MessageType{ - ENTRANCE, MSG + ENTRANCE, CREATION, MSG }