spring-bootsslwebsocketstompamazon-mq

How to use spring-messaging-5.1.* to connect stomp+ssl broker?


I wanna using stomp over websocket and intend to integrate with Amazon MQ, but Amazon MQ using stomp+ssl as default, then i encounter my problem.

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

@Autowired
private ActiveMQProperties activeMQProperties;

/**
 * Register STOMP endpoints mapping each to a specific URL and (optionally)
 * enabling and configuring SockJS fallback options.
 *
 * @param registry
 */
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/endpoint").setAllowedOrigins("*");
}

/**
 * Configure message broker options.
 *
 * @param registry
 */
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
    registry.setApplicationDestinationPrefixes("/app");
    registry.enableStompBrokerRelay("/queue", "/topic")
            .setAutoStartup(true)
            .setVirtualHost(activeMQProperties.getHost())
            .setRelayHost(activeMQProperties.getHost())
            .setRelayPort(activeMQProperties.getPort())
            .setSystemLogin(activeMQProperties.getUser())
            .setSystemPasscode(activeMQProperties.getPassword())
            .setClientLogin(activeMQProperties.getUser())
            .setClientPasscode(activeMQProperties.getPassword());
   }}

ReactorNettyTcpClient is the implementation of TcpOperations in spring-messaging-5.1.*, how can it support SSL?


Solution

  • Recently encountered this issue using ActiveMQ.

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
    
        ReactorNettyTcpClient<byte[]> client = new ReactorNettyTcpClient<>(builder -> { 
            builder.port(activeMQProperties.getPort())
                   .host(activeMQProperties.getHost())
                   .sslSupport(opts -> { /* set SSL options here */})
        }, new StompReactorNettyCodec());
    
        registry.setApplicationDestinationPrefixes("/app");
        registry.enableStompBrokerRelay("/queue", "/topic")
            .setAutoStartup(true)
            .setVirtualHost(activeMQProperties.getHost())
            .setSystemLogin(activeMQProperties.getUser())
            .setSystemPasscode(activeMQProperties.getPassword())
            .setClientLogin(activeMQProperties.getUser())
            .setClientPasscode(activeMQProperties.getPassword())
            .setTcpClient(client);
    }}