Loading...
Spring Framework Reference Documentation 7.0.2의 External Broker의 한국어 번역본입니다.
아래의 경우에 피드백에서 신고해주신다면 반영하겠습니다.
감사합니다 :)
The simple broker는 시작하기에 좋지만 지원하는 STOMP command의 subset만 지원하고 (ack, receipt 및 기타 일부 기능을 지원하지 않으며), simple message-sending loop에 의존하고, 클러스터링에는 적합하지 않습니다. 대안으로, 애플리케이션을 업그레이드하여 full-featured message broker를 사용할 수 있습니다.
선호하는 message broker(예: RabbitMQ, ActiveMQ 등)의 STOMP documentation을 참고하고, broker를 설치한 뒤, STOMP support를 활성화하여 실행하십시오. 그런 다음 Spring configuration에서 simple broker 대신 STOMP broker relay를 활성화할 수 있습니다.
다음 example configuration은 full-featured broker를 활성화합니다:
1@Configuration 2@EnableWebSocketMessageBroker 3public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer { 4 5 @Override 6 public void registerStompEndpoints(StompEndpointRegistry registry) { 7 registry.addEndpoint("/portfolio").withSockJS(); 8 } 9 10 @Override 11 public void configureMessageBroker(MessageBrokerRegistry registry) { 12 registry.enableStompBrokerRelay("/topic", "/queue"); 13 registry.setApplicationDestinationPrefixes("/app"); 14 } 15 16}
1@Configuration 2@EnableWebSocketMessageBroker 3class WebSocketConfiguration : WebSocketMessageBrokerConfigurer { 4 5 override fun registerStompEndpoints(registry: StompEndpointRegistry) { 6 registry.addEndpoint("/portfolio").withSockJS() 7 } 8 9 override fun configureMessageBroker(registry: MessageBrokerRegistry) { 10 registry.enableStompBrokerRelay("/topic", "/queue") 11 registry.setApplicationDestinationPrefixes("/app") 12 } 13}
1<beans xmlns="http://www.springframework.org/schema/beans" 2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns:websocket="http://www.springframework.org/schema/websocket" 4 xsi:schemaLocation=" 5 http://www.springframework.org/schema/beans 6 https://www.springframework.org/schema/beans/spring-beans.xsd 7 http://www.springframework.org/schema/websocket 8 https://www.springframework.org/schema/websocket/spring-websocket.xsd"> 9 10 <websocket:message-broker application-destination-prefix="/app"> 11 <websocket:stomp-endpoint path="/portfolio"> 12 <websocket:sockjs /> 13 </websocket:stomp-endpoint> 14 <websocket:stomp-broker-relay prefix="/topic,/queue" /> 15 </websocket:message-broker> 16</beans>
앞선 configuration의 STOMP broker relay는 Spring의
MessageHandler로,
메시지를 external message broker로 forward하여 처리합니다.
이를 위해 broker에 대한 TCP connection을 설정하고, 모든 메시지를 broker로 forward하며,
broker로부터 수신한 모든 메시지를 WebSocket 세션을 통해 클라이언트에게 forward합니다. 본질적으로 양방향으로 메시지를 forward하는 “relay” 역할을 합니다.
| • | TCP connection 관리를 위해 프로젝트에 io.projectreactor.netty:reactor-netty 및 io.netty:netty-all<br>의존성을 추가하십시오. |
또한 애플리케이션 컴포넌트(예: HTTP 요청 처리 메서드, 비즈니스 서비스 등)도 Sending Messages에 설명된 대로 broker relay로 메시지를 전송하여, subscribe된 WebSocket 클라이언트에게 메시지를 broadcast할 수 있습니다.
결과적으로 broker relay는 견고하고 확장 가능한 메시지 broadcasting을 가능하게 합니다.
Simple Broker
Connecting to a Broker