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 @MessageMapping controller methods.

Endpoint Registration

  • Registers the /ws endpoint 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:
  • WebSocketMessageBrokerConfigurer
  • EnableWebSocketMessageBroker
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    configureMessageBroker(org.springframework.messaging.simp.config.MessageBrokerRegistry config)
    Configures the message broker options.
    void
    registerStompEndpoints(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, wait

    Methods 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 /topic for subscriptions, and sets the application destination prefix /app for routing messages to controller methods.

      Specified by:
      configureMessageBroker in interface org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer
      Parameters:
      config - the MessageBrokerRegistry used 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 /ws endpoint is exposed with SockJS fallback for browsers that do not support native WebSocket. All origin patterns are allowed.

      Specified by:
      registerStompEndpoints in interface org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer
      Parameters:
      registry - the StompEndpointRegistry used for endpoint registration