From 908f00fc3a26667c9931814eb774e1a6a48a180f Mon Sep 17 00:00:00 2001 From: thsghdud13 Date: Wed, 25 Sep 2024 21:55:15 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Add=20:=20rabbitMQ=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++++ .../resources/{application.properties => application.yml} | 0 2 files changed, 4 insertions(+) rename src/main/resources/{application.properties => application.yml} (100%) diff --git a/build.gradle b/build.gradle index 892dc71..d4a02ba 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,10 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-websocket' implementation group: 'org.webjars', name: 'stomp-websocket', version: '2.3.3-1' + //rabbitMQ + implementation 'org.springframework.boot:spring-boot-starter-amqp' + implementation 'org.springframework.boot:spring-boot-starter-reactor-netty:3.0.0' + implementation 'io.netty:netty-resolver-dns-native-macos:4.1.68.Final:osx-aarch_64' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' diff --git a/src/main/resources/application.properties b/src/main/resources/application.yml similarity index 100% rename from src/main/resources/application.properties rename to src/main/resources/application.yml From e13c55d2c01f27ce523574ec0d61691cf9018b6c Mon Sep 17 00:00:00 2001 From: thsghdud13 Date: Wed, 25 Sep 2024 21:56:01 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Feat=20:=20RabbitMQ=EC=99=80=20=EC=97=B0?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../festime/config/WebSocketConfigurer.java | 17 ++++++++++++----- .../festime/controller/MessageController.java | 8 +++----- src/main/resources/application.yml | 8 +++++++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/Be9room/festime/config/WebSocketConfigurer.java b/src/main/java/Be9room/festime/config/WebSocketConfigurer.java index 67db3c4..7934e3d 100644 --- a/src/main/java/Be9room/festime/config/WebSocketConfigurer.java +++ b/src/main/java/Be9room/festime/config/WebSocketConfigurer.java @@ -1,9 +1,9 @@ package Be9room.festime.config; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.messaging.simp.config.MessageBrokerRegistry; -import org.springframework.util.AntPathMatcher; import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; import org.springframework.web.socket.config.annotation.StompEndpointRegistry; import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; @@ -12,6 +12,8 @@ @EnableWebSocketMessageBroker @RequiredArgsConstructor public class WebSocketConfigurer implements WebSocketMessageBrokerConfigurer { + @Value("${rabbit.host}") + private String rabbitHost; // private final StompHandler stompHandler; @Override public void registerStompEndpoints(StompEndpointRegistry registry) { @@ -23,10 +25,15 @@ public void registerStompEndpoints(StompEndpointRegistry registry) { @Override public void configureMessageBroker(MessageBrokerRegistry registry) { -// registry.setPathMatcher(new AntPathMatcher(".")); - registry.setApplicationDestinationPrefixes("/pub"); -// registry.enableStompBrokerRelay("/queue", "/topic", "/exchange", "/amq/queue"); - registry.enableSimpleBroker("/sub"); + registry.setApplicationDestinationPrefixes("/pub") + .enableStompBrokerRelay("/topic") + .setRelayHost(rabbitHost) + .setVirtualHost("/") + .setRelayPort(61613) + .setClientLogin("admin") + .setClientPasscode("admin") + .setSystemLogin("admin") + .setSystemPasscode("admin"); } // @Override diff --git a/src/main/java/Be9room/festime/controller/MessageController.java b/src/main/java/Be9room/festime/controller/MessageController.java index 9e649a0..2c0eb5f 100644 --- a/src/main/java/Be9room/festime/controller/MessageController.java +++ b/src/main/java/Be9room/festime/controller/MessageController.java @@ -20,13 +20,12 @@ public class MessageController { */ @MessageMapping(value = "/guestbook/enter") public void enter(MessageDTO message){ - log.info("eee"); message.setMessageType(MessageType.ENTER.toString()); message.setMessage(message.getMemberName() + "님이 방명록에 참여했어요!"); /* 메세지 저장 부분 */ - template.convertAndSend("/sub/guestbook", message); + template.convertAndSend("/topic/guestbook", message); } /** @@ -35,12 +34,11 @@ public void enter(MessageDTO message){ */ @MessageMapping(value = "/guestbook/message") public void message(MessageDTO message){ - log.info("messsaggee"); message.setMessageType(MessageType.MESSAGE.toString()); /* 메세지 저장 부분 */ - template.convertAndSend("/sub/guestbook", message); + template.convertAndSend("/topic/guestbook", message); } /** @@ -54,7 +52,7 @@ public void leave(MessageDTO message){ /* 메세지 저장 부분 */ - template.convertAndSend("/sub/guestbook", message); + template.convertAndSend("/topic/guestbook", message); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index eea48b4..11f75f0 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1 +1,7 @@ -spring.application.name=festime +spring: + application: + name: festime_BE + + +rabbit: + host: ${RABBIT_HOST}