Reputation: 709
I have simple spring boot app with web socket configuration.
When i run my app with SimpleBroker(provided by spring) everything works fine, but when i want to use rabbitmq instead of SimpleBroker, i have some problems, my broker is "not available"
@Configuration
@EnableWebSocketMessageBroker
open class WebSocketConfig : ILogging by LoggingImp<WebSocketConfig>(),
WebSocketMessageBrokerConfigurer {
@Autowired
private lateinit var env: Environment
override fun registerStompEndpoints(registry: StompEndpointRegistry) {
registry.addEndpoint("/hig").setAllowedOrigins("*").withSockJS()
}
override fun configureMessageBroker(registry: MessageBrokerRegistry) {
registry.setApplicationDestinationPrefixes("/app")
val host = env.getProperty("spring.rabbitmq.host")!!
val port = env.getProperty("spring.rabbitmq.port")!!.toInt()
val login = env.getProperty("spring.rabbitmq.username")!!
val pass = env.getProperty("spring.rabbitmq.password")!!
log.debug("webSocket=$host, $port, $login, $pass")
// registry.enableSimpleBroker("/chat")
registry.enableStompBrokerRelay("/chat")
.setRelayHost(host)
.setRelayPort(port)
.setClientLogin(login)
.setClientPasscode(pass)
.setAutoStartup(true)
.setSystemHeartbeatReceiveInterval(10000)
.setSystemHeartbeatSendInterval(10000)
}
}
response from WebSocketMessageBrokerStats:
{
"loggingPeriod": 1800000,
"webSocketSessionStatsInfo": "0 current WS(0)-HttpStream(0)-HttpPoll(0), 0 total, 0 closed abnormally (0 connect failure, 0 send limit, 0 transport error)",
"stompSubProtocolStatsInfo": "processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)",
"stompBrokerRelayStatsInfo": "1 sessions, localhost:5672 (not available), processed CONNECT(1)-CONNECTED(0)-DISCONNECT(0)",
"clientInboundExecutorStatsInfo": "pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0",
"clientOutboundExecutorStatsInfo": "pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0",
"sockJsTaskSchedulerStatsInfo": "pool size = 1, active threads = 0, queued tasks = 1, completed tasks = 0"
}
Broker details:
2018-02-15 23:03:56.367 [XNIO-2 task-16] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcherServlet' processing GET request for [/hig/websocket]
2018-02-15 23:03:56.367 [XNIO-2 task-16] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /hig/websocket
2018-02-15 23:03:56.368 [XNIO-2 task-16] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Did not find handler method for [/hig/websocket]
2018-02-15 23:03:56.368 [XNIO-2 task-16] DEBUG o.s.w.s.s.s.WebSocketHandlerMapping - Matching patterns for request [/hig/websocket] are [/hig/**]
2018-02-15 23:03:56.368 [XNIO-2 task-16] DEBUG o.s.w.s.s.s.WebSocketHandlerMapping - URI Template variables for request [/hig/websocket] are {}
2018-02-15 23:03:56.368 [XNIO-2 task-16] DEBUG o.s.w.s.s.s.WebSocketHandlerMapping - Mapping [/hig/websocket] to HandlerExecutionChain with handler [org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler@352c1b98] and 1 interceptor
2018-02-15 23:03:56.368 [XNIO-2 task-16] DEBUG o.s.web.servlet.DispatcherServlet - Last-Modified value for [/hig/websocket] is: -1
2018-02-15 23:03:56.369 [XNIO-2 task-16] DEBUG o.s.w.s.s.t.h.DefaultSockJsService - Processing transport request: GET http://localhost:8080/hig/websocket
2018-02-15 23:03:56.370 [XNIO-2 task-16] DEBUG o.s.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2018-02-15 23:03:56.370 [XNIO-2 task-16] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
2018-02-15 23:03:56.371 [XNIO-2 task-16] DEBUG o.s.w.s.h.LoggingWebSocketHandlerDecorator - New StandardWebSocketSession[id=Enl3glxP29UhO95gUafWViRXrXaZn3Kv556EVxW4, uri=/hig/websocket]
2018-02-15 23:03:56.374 [clientOutboundChannel-7] DEBUG o.s.w.s.a.NativeWebSocketSession - Closing StandardWebSocketSession[id=Enl3glxP29UhO95gUafWViRXrXaZn3Kv556EVxW4, uri=/hig/websocket]
2018-02-15 23:03:56.374 [clientOutboundChannel-7] DEBUG o.s.w.s.h.LoggingWebSocketHandlerDecorator - StandardWebSocketSession[id=Enl3glxP29UhO95gUafWViRXrXaZn3Kv556EVxW4, uri=/hig/websocket] closed with CloseStatus[code=1002, reason=]
2018-02-15 23:03:56.374 [clientOutboundChannel-7] DEBUG o.s.w.s.m.SubProtocolWebSocketHandler - Clearing session Enl3glxP29UhO95gUafWViRXrXaZn3Kv556EVxW4
2018-02-15 23:03:56.375 [clientOutboundChannel-8] DEBUG o.s.w.s.m.SubProtocolWebSocketHandler - No session for GenericMessage [payload=byte[0], headers={simpMessageType=OTHER, stompCommand=ERROR, nativeHeaders={message=[Broker not available.]}, simpSessionId=Enl3glxP29UhO95gUafWViRXrXaZn3Kv556EVxW4}]
For client i'm using angular 5
When i'm using registry.enableSimpleBroker("/chat")
everything works fine
When i enable registry.enableStompBrokerRelay("/chat")...
i'm getting:
message:Broker not available. content-length:0
pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>2.0.0.M7</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>2.0.0.M7</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-net</artifactId>
<version>2.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>io.projectreactor.ipc</groupId>
<artifactId>reactor-netty</artifactId>
<version>0.7.3.RELEASE</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.21.Final</version>
</dependency>
Upvotes: 3
Views: 2959
Reputation: 2683
You are trying to connect using stomp protocol on a rabbitmq which doesn't run the stomp adapter. Run:
rabbitmq-plugins enable rabbitmq_stomp
to enable stomp.
Also, you are connecting to the port 5672 which is the amqp protocol / adapter. This is why you have this stompCommand=ERROR, nativeHeaders={message=[Broker not available.]}
.
Once enabled, the stomp adapter will by default listen on tcp/61613.
Upvotes: 8