-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from FinalDoubleTen/BE-66-Refactor-STOMP
Be 66 refactor stomp
- Loading branch information
Showing
10 changed files
with
139 additions
and
115 deletions.
There are no files selected for viewing
20 changes: 13 additions & 7 deletions
20
src/main/java/org/tenten/tentenstomp/config/WebSocketConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
package org.tenten.tentenstomp.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.messaging.simp.config.ChannelRegistration; | ||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; | ||
import org.springframework.web.socket.config.annotation.EnableWebSocket; | ||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; | ||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; | ||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; | ||
import org.tenten.tentenstomp.global.stomp.StompExceptionHandler; | ||
import org.tenten.tentenstomp.global.stomp.StompPreHandler; | ||
|
||
@Configuration | ||
@EnableWebSocket | ||
@EnableWebSocketMessageBroker | ||
@RequiredArgsConstructor | ||
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { | ||
|
||
private final StompExceptionHandler stompExceptionHandler; | ||
private final StompPreHandler stompPreHandler; | ||
@Override | ||
public void registerStompEndpoints(StompEndpointRegistry endpointRegistry) { | ||
endpointRegistry.addEndpoint("/ws-stomp")// 소켓 연결 Endpoint 설정 | ||
.setAllowedOriginPatterns("http://*:8080", "http://*.*.*.*:8080", "https://jxy.me/", "http://localhost:5173", "https://weplanplans.vercel.app", "https://dev-weplanplans.vercel.app"); | ||
// .withSockJS() | ||
// .setClientLibraryUrl("https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.1.2/sockjs.js"); // Todo 추후 특정 url 변경 | ||
|
||
endpointRegistry.setErrorHandler(stompExceptionHandler); | ||
} | ||
|
||
@Override | ||
public void configureMessageBroker(MessageBrokerRegistry brokerRegistry) { | ||
// 클라이언트가 Server로 메세지 발행 -> @MessageMapping 이 붙어있는 메서드와 연결 | ||
brokerRegistry.setApplicationDestinationPrefixes("/pub"); | ||
// 메서드에서 처리된 메세지의 결과를 broker를 통해서 /sub/message 를 구독하고 있는 | ||
// 모든 클라이언트들에게 메세지를 전달 | ||
brokerRegistry.enableSimpleBroker("/sub"); | ||
} | ||
|
||
@Override | ||
public void configureClientInboundChannel(ChannelRegistration registration) { | ||
registration.interceptors(stompPreHandler); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.