From d2e0d67bb1d96aa0ee2bf6af7dedd2dfff338a5f Mon Sep 17 00:00:00 2001 From: jimmy0524 <10jmin04@naver.com> Date: Tue, 12 Aug 2025 21:13:05 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[feat]=20RabbitMQ=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + .../apiserver/BillApiServerApplication.java | 3 +++ .../api/chat/dto/request/PushDTO.java | 17 ++++++++++++++++ .../api/chat/service/ChatService.java | 3 +++ .../api/chat/service/ChatServiceImpl.java | 13 ++++++++++++ .../api/push/dto/request/PushRequest.java | 3 +++ .../config/rabbitMQ/RabbitMQConfig.java | 20 +++++++++++++++++++ 7 files changed, 60 insertions(+) create mode 100644 src/main/java/site/billbill/apiserver/api/chat/dto/request/PushDTO.java create mode 100644 src/main/java/site/billbill/apiserver/config/rabbitMQ/RabbitMQConfig.java diff --git a/build.gradle b/build.gradle index fab5f2e..e57e811 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,7 @@ repositories { } dependencies { + implementation 'org.springframework.boot:spring-boot-starter-amqp' implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-security' diff --git a/src/main/java/site/billbill/apiserver/BillApiServerApplication.java b/src/main/java/site/billbill/apiserver/BillApiServerApplication.java index 10c9f00..ba1f06c 100644 --- a/src/main/java/site/billbill/apiserver/BillApiServerApplication.java +++ b/src/main/java/site/billbill/apiserver/BillApiServerApplication.java @@ -2,12 +2,15 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.servers.Server; +import org.springframework.amqp.rabbit.annotation.EnableRabbit; +import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; +@EnableRabbit @SpringBootApplication(exclude = SecurityAutoConfiguration.class) @EntityScan(basePackages = "site.billbill.apiserver.model") @ConfigurationPropertiesScan("site.billbill.apiserver.config") diff --git a/src/main/java/site/billbill/apiserver/api/chat/dto/request/PushDTO.java b/src/main/java/site/billbill/apiserver/api/chat/dto/request/PushDTO.java new file mode 100644 index 0000000..0c7a869 --- /dev/null +++ b/src/main/java/site/billbill/apiserver/api/chat/dto/request/PushDTO.java @@ -0,0 +1,17 @@ +package site.billbill.apiserver.api.chat.dto.request; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class PushDTO { + private String targetUserId; + private String senderId; + private String channelId; + private String content; +} diff --git a/src/main/java/site/billbill/apiserver/api/chat/service/ChatService.java b/src/main/java/site/billbill/apiserver/api/chat/service/ChatService.java index 316d621..57a316f 100644 --- a/src/main/java/site/billbill/apiserver/api/chat/service/ChatService.java +++ b/src/main/java/site/billbill/apiserver/api/chat/service/ChatService.java @@ -6,6 +6,7 @@ import site.billbill.apiserver.api.chat.dto.response.ChatResponse.ViewChannelInfoResponse; import site.billbill.apiserver.api.chat.dto.response.ChatResponse.ViewChatInfoResponse; import site.billbill.apiserver.api.chat.dto.response.ChatResponse.ViewUnreadChatCountResponse; +import site.billbill.apiserver.api.push.dto.request.PushRequest.SendChatPushRequest; public interface ChatService { String leaveChatChannel(String postId, String userId); @@ -19,4 +20,6 @@ public interface ChatService { String changeDate(String userId, String channelId, changeDate request); ViewUnreadChatCountResponse getUnreadCount(String userId); + + void receivePushRequest(SendChatPushRequest request); } diff --git a/src/main/java/site/billbill/apiserver/api/chat/service/ChatServiceImpl.java b/src/main/java/site/billbill/apiserver/api/chat/service/ChatServiceImpl.java index a80a234..3e4bb5c 100644 --- a/src/main/java/site/billbill/apiserver/api/chat/service/ChatServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/chat/service/ChatServiceImpl.java @@ -5,6 +5,8 @@ import java.util.List; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,6 +18,8 @@ import site.billbill.apiserver.api.chat.dto.response.ChatResponse.ViewChannelInfoResponse; import site.billbill.apiserver.api.chat.dto.response.ChatResponse.ViewChatInfoResponse; import site.billbill.apiserver.api.chat.dto.response.ChatResponse.ViewUnreadChatCountResponse; +import site.billbill.apiserver.api.push.dto.request.PushRequest.SendChatPushRequest; +import site.billbill.apiserver.api.push.service.PushService; import site.billbill.apiserver.common.enums.exception.ErrorCode; import site.billbill.apiserver.common.utils.ULID.ULIDUtil; import site.billbill.apiserver.exception.CustomException; @@ -31,12 +35,14 @@ @Service @RequiredArgsConstructor @Transactional(readOnly = true) +@Slf4j public class ChatServiceImpl implements ChatService { private final ChatRepository chatRepository; private final UserRepository userRepository; private final ItemsRepository itemsRepository; private final ItemsBorrowRepository itemsBorrowRepository; private final ChatServerServiceImpl chatServerService; + private final PushService pushService; @Override @Transactional @@ -164,4 +170,11 @@ public ViewUnreadChatCountResponse getUnreadCount(String userId) { return ChatConverter.toViewUnreadChatCount(count); } + + @Override + @RabbitListener(queues = "push.queue") + public void receivePushRequest(SendChatPushRequest request) { + log.info("Push 요청 수신 성공: {}", request); + pushService.sendChatPush(request); + } } diff --git a/src/main/java/site/billbill/apiserver/api/push/dto/request/PushRequest.java b/src/main/java/site/billbill/apiserver/api/push/dto/request/PushRequest.java index b1477a9..61da169 100644 --- a/src/main/java/site/billbill/apiserver/api/push/dto/request/PushRequest.java +++ b/src/main/java/site/billbill/apiserver/api/push/dto/request/PushRequest.java @@ -27,6 +27,9 @@ public static class SendPushRequest { @Getter @Setter + @ToString + @NoArgsConstructor + @AllArgsConstructor public static class SendChatPushRequest { private String userId; private String senderId; diff --git a/src/main/java/site/billbill/apiserver/config/rabbitMQ/RabbitMQConfig.java b/src/main/java/site/billbill/apiserver/config/rabbitMQ/RabbitMQConfig.java new file mode 100644 index 0000000..d412edf --- /dev/null +++ b/src/main/java/site/billbill/apiserver/config/rabbitMQ/RabbitMQConfig.java @@ -0,0 +1,20 @@ +package site.billbill.apiserver.config.rabbitMQ; + +import org.springframework.amqp.core.Queue; +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 { + @Bean + public Queue pushQueue() { + return new Queue("push.queue", true); + } + + @Bean + public MessageConverter messageConverter() { + return new Jackson2JsonMessageConverter(); + } +} From 5b5bcbc26167539196722e943ece179243e2bd61 Mon Sep 17 00:00:00 2001 From: jimmy0524 <10jmin04@naver.com> Date: Tue, 12 Aug 2025 21:15:51 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[feat]=20dev=5Fdeply.yml=20RabbitMQ=20scrip?= =?UTF-8?q?t=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev_deply.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/dev_deply.yml b/.github/workflows/dev_deply.yml index 17cb08d..2f8c066 100644 --- a/.github/workflows/dev_deply.yml +++ b/.github/workflows/dev_deply.yml @@ -76,6 +76,10 @@ jobs: sudo docker run --name bill-api -d -p 80:8080 \ -e INTERNAL_CHAT_SECRET=${{ secrets.INTERNAL_CHAT_SECRET }} \ -e INTERNAL_API_SECRET=${{ secrets.INTERNAL_API_SECRET }} \ + -e SPRING_RABBITMQ_HOST=${{ secrets.SPRING_RABBITMQ_HOST }} \ + -e SPRING_RABBITMQ_PORT=${{ secrets.SPRING_RABBITMQ_PORT }} \ + -e SPRING_RABBITMQ_USERNAME=${{ secrets.SPRING_RABBITMQ_USERNAME }} \ + -e SPRING_RABBITMQ_PASSWORD=${{ secrets.SPRING_RABBITMQ_PASSWORD }} \ -e SPRING_DATASOURCE_DRIVER_CLASS_NAME=${{ secrets.SPRING_DATASOURCE_DRIVER_CLASS_NAME }} \ -e SPRING_DATASOURCE_URL="${{secrets.SPRING_DATASOURCE_URL}}" \ -e SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }} \