Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/7 : 외부 메시지 브로커와 연동 #8

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/Be9room/festime/config/WebSocketConfigurer.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -54,7 +52,7 @@ public void leave(MessageDTO message){

/* 메세지 저장 부분 */

template.convertAndSend("/sub/guestbook", message);
template.convertAndSend("/topic/guestbook", message);
}


Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application.properties

This file was deleted.

7 changes: 7 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
spring:
application:
name: festime_BE


rabbit:
host: ${RABBIT_HOST}
Loading