I am configuring external broker (amazonMQ) relay for websocket in my Spring Boot application.
At startup configurations seems fine and relay is connected as per below is log. I tested with bad URL and I clearly get UnknownHostException so I think my host configurations are good.
I have tested this with local ActiveMQ and my test set up works perfectly fine so there is no issue with Message Flow also. I could see consumers connected and topic created in management console.
Here is my code based on Spring Documentation here!
When I try to connect client I receive connect message followed by disconnect for same session.
If is it's the issue with SSL then I found no reference in Spring Documentation for configuring SSL.
private static final String HOST = "b-xxxxxxxxxxxxxxxxxx.mq.aws-region.amazonaws.com";
private static final int PORT = 61617;
private static final String USER = "username-here";
private static final String PASSCODE = "passcode-here";
private ReactorNettyTcpClient<byte[]> createTcpClient() {
return new ReactorNettyTcpClient(HOST, PORT, new StompReactorNettyCodec());
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableStompBrokerRelay()
.setRelayHost(HOST)
.setRelayPort(PORT)
.setSystemLogin(USER)
.setSystemPasscode(PASSCODE)
.setClientLogin(USER)
.setClientPasscode(PASSCODE)
.setTcpClient(createTcpClient());
registry.setApplicationDestinationPrefixes("/app")
.setPathMatcher(new AntPathMatcher("."));
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws")
.setAllowedOrigins("*").withSockJS();
}
@Override
public void configureClientInboundChannel(ChannelRegistration registration) {
AuthenticatedUser a = null;
registration.interceptors(new ChannelInterceptorAdapter() {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
log.info(" accessor {}", accessor);
return message;
}
});
Log while starting
Starting...
Connecting "system" session to
stomp://XXXXXXXXXXXXXXXXX.mq.XXXXXX.amazonaws.com:61617
Started.
Tomcat started on port(s): 8080 (http) with context path ''
Log when client tries to connect
accessor StompHeaderAccessor [headers={simpMessageType=CONNECT,
stompCommand=CONNECT, nativeHeaders={accept-version=[1.1,1.0], heart-beat=[10000,10000]},
simpSessionAttributes={}, simpHeartbeat=[J@7070e97e,
simpSessionId=52usza4t}]
accessor StompHeaderAccessor [headers={simpMessageType=DISCONNECT,
stompCommand=DISCONNECT, simpSessionAttributes={},
simpSessionId=52usza4t}]
Anybody faced something similar ? Thanks in advance :)