Package com.nadiyar.kiwi.websocket
Class WebsocketBrokerConfig
java.lang.Object
com.nadiyar.kiwi.websocket.WebsocketBrokerConfig
- All Implemented Interfaces:
org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer
@Configuration
@EnableWebSocketMessageBroker
public class WebsocketBrokerConfig
extends Object
implements org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer
WebSocket configuration for enabling STOMP messaging in the application.
This configuration class:
- Enables a simple in-memory message broker for broadcasting messages to subscribed clients.
- Registers a STOMP WebSocket endpoint for clients to connect to.
- Defines application destination prefixes for routing messages to server-side controllers.
Broker Configuration
- Message broker destination prefix:
/topic— used for publishing server-to-client broadcasts. - Application destination prefix:
/app— used for mapping messages from clients to@MessageMappingcontroller methods.
Endpoint Registration
- Registers the
/wsendpoint for STOMP connections. - Enables SockJS fallback options for browsers that do not support WebSocket.
- Allows all origin patterns (use cautiously in production; restrict if possible).
- Author:
- Nadiyar
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigureMessageBroker(org.springframework.messaging.simp.config.MessageBrokerRegistry config) Configures the message broker options.voidregisterStompEndpoints(org.springframework.web.socket.config.annotation.StompEndpointRegistry registry) Registers STOMP WebSocket endpoints that clients can connect to.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer
addArgumentResolvers, addReturnValueHandlers, configureClientInboundChannel, configureClientOutboundChannel, configureMessageConverters, configureWebSocketTransport, getPhase
-
Constructor Details
-
WebsocketBrokerConfig
public WebsocketBrokerConfig()
-
-
Method Details
-
configureMessageBroker
public void configureMessageBroker(org.springframework.messaging.simp.config.MessageBrokerRegistry config) Configures the message broker options.Enables a simple in-memory broker with destination prefix
/topicfor subscriptions, and sets the application destination prefix/appfor routing messages to controller methods.- Specified by:
configureMessageBrokerin interfaceorg.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer- Parameters:
config- theMessageBrokerRegistryused to configure message broker options
-
registerStompEndpoints
public void registerStompEndpoints(org.springframework.web.socket.config.annotation.StompEndpointRegistry registry) Registers STOMP WebSocket endpoints that clients can connect to.The
/wsendpoint is exposed with SockJS fallback for browsers that do not support native WebSocket. All origin patterns are allowed.- Specified by:
registerStompEndpointsin interfaceorg.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer- Parameters:
registry- theStompEndpointRegistryused for endpoint registration
-