spring-framework / org.springframework.web.socket.config.annotation / EnableWebSocketMessageBroker

EnableWebSocketMessageBroker

@Target([AnnotationTarget.CLASS, AnnotationTarget.FILE]) @Import(DelegatingWebSocketMessageBrokerConfiguration) class EnableWebSocketMessageBroker

Add this annotation to an @Configuration class to enable broker-backed messaging over WebSocket using a higher-level messaging sub-protocol.

 @Configuration @EnableWebSocketMessageBroker public class MyWebSocketConfig { } 

Customize the imported configuration by implementing the WebSocketMessageBrokerConfigurer interface or more likely extend the convenient base class AbstractWebSocketMessageBrokerConfigurer:

 @Configuration @EnableWebSocketMessageBroker public class MyConfiguration extends AbstractWebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/portfolio").withSockJS(); } @Bean public void configureMessageBroker(MessageBrokerRegistry registry) { registry.enableStompBrokerRelay("/queue/", "/topic/"); registry.setApplicationDestinationPrefixes("/app/"); } } 

Author
Rossen Stoyanchev

Since
4.0

Constructors

<init>

EnableWebSocketMessageBroker()

Add this annotation to an @Configuration class to enable broker-backed messaging over WebSocket using a higher-level messaging sub-protocol.

 @Configuration @EnableWebSocketMessageBroker public class MyWebSocketConfig { } 

Customize the imported configuration by implementing the WebSocketMessageBrokerConfigurer interface or more likely extend the convenient base class AbstractWebSocketMessageBrokerConfigurer:

 @Configuration @EnableWebSocketMessageBroker public class MyConfiguration extends AbstractWebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/portfolio").withSockJS(); } @Bean public void configureMessageBroker(MessageBrokerRegistry registry) { registry.enableStompBrokerRelay("/queue/", "/topic/"); registry.setApplicationDestinationPrefixes("/app/"); } }