1 Configuration
Ralph Schaer edited this page 2026-10-30 16:08:52 +01:00

Configuration

Choose the enable annotation for your transport: @EnableServletWamp, @EnableReactiveWamp, or @EnableServletWampLongpoll. They import configurations derived from ch.rasc.wamp2spring.config.WampConfiguration.

Configurer beans

Implement a configurer on a Spring-managed bean. Common hooks are inherited from WampConfigurer:

Hook Purpose
configureFeatures(Features) Disable broker/dealer roles or individual capabilities; see Features
configureClientInboundChannel(AbstractMessageChannel) Add channel interceptors
addArgumentResolvers(List<HandlerMethodArgumentResolver>) Add application argument resolvers for annotated handlers

WampServletConfigurer adds configureWebSocketHandlerRegistration and decorateWebSocketHandler. For example:

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistration;
import ch.rasc.wamp2spring.servlet.WampServletConfigurer;

@Configuration
public class WampOptions implements WampServletConfigurer {
  @Override
  public void configureWebSocketHandlerRegistration(WebSocketHandlerRegistration registration) {
    registration.setAllowedOrigins("http://localhost:8100");
  }
}

WampReactiveConfigurer adds configureHandlerMapping(SimpleUrlHandlerMapping) and a decorator for the reactive WebSocketHandler. Use the mapping hook to configure CORS. The default reactive mapping order is -1.

WampServletLongpollConfigurer adds queue and timeout settings; see Transports. Prefer one bean for these settings: each matching configurer replaces the values, including any defaults inherited from the interface.

Endpoint path and transport customization

The default WebSocket path is /wamp. To change it, use a configuration subclass in place of the corresponding enable annotation:

import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.HandshakeHandler;
import ch.rasc.wamp2spring.servlet.PreferJsonHandshakeHandler;
import ch.rasc.wamp2spring.servlet.WampServletConfiguration;

@Configuration
public class CustomWampConfiguration extends WampServletConfiguration {
  @Override
  protected String getWebSocketHandlerPath() {
    return "/messaging";
  }

  @Override
  protected HandshakeHandler getHandshakeHandler() {
    return new PreferJsonHandshakeHandler();
  }
}

Use WampReactiveConfiguration for a reactive path override. Servlet subclasses can also override getSendTimeLimit() (milliseconds) and getSendBufferSizeLimit() (bytes); both return null by default, leaving Spring's transport settings in effect. The servlet default handshake handler prefers MessagePack, then Smile, then CBOR. Alternatives are PreferJsonHandshakeHandler, PreferMsgpackHandshakeHandler, PreferCborHandshakeHandler, and PreferSmileHandshakeHandler.

The long-poll controller has a fixed /wamp mapping; getWebSocketHandlerPath() does not change its URLs. Each enable annotation imports its own core configuration. The repository supplies separate transport setups, not a combined WebSocket/long-poll enable annotation; combining configurations requires arranging a shared set of core beans.

Channels and execution

Bean Behavior
clientInboundChannel OrderedSessionExecutorSubscribableChannel; processes inbound messages in order for each WAMP session while allowing different sessions to run concurrently
clientOutboundChannel Executor-backed channel for responses and events to transports
brokerChannel Channel used by WampPublisher; synchronous by default

Inbound and outbound executors each use 2 * availableProcessors core threads, an unbounded queue, a maximum pool size of Integer.MAX_VALUE, a 60-second keep-alive, and core-thread timeout. Override the executor bean methods in a configuration subclass to tune them. brokerChannelExecutor() returns null by default; override it to make server publication asynchronous. Inbound session ordering does not imply a global ordering guarantee across every channel.

Conversion, codecs, and stores

  • Handler binding uses Spring's DefaultFormattingConversionService and a Jackson mapper. Built-in resolvers support Principal, @WampSessionId, and WAMP message objects; see RPC.
  • Mapper beans are named jsonJsonFactory, msgpackJsonFactory, cborJsonFactory, and smileJsonFactory, and use Jackson 3 ObjectMapper. MessagePack uses MessagePackCodec with the JSON mapper's value conversion.
  • Supply an EventStore bean to replace MemoryEventStore; see PubSub for retention/history requirements.
  • Supply WampAuthenticationProvider beans for authentication and WampAuthorizer beans for operation authorization; see Authentication and Security.

Source: WampConfiguration.