我有简单的弹簧启动应用程序,带有Web套接字配置。
当我用SimpleBroker运行我的应用程序(由spring提供)一切正常,但是当我想使用rabbitmq而不是SimpleBroker时,我遇到了一些问题,我的经纪人“不可用”
{
"name": "bot",
"version": "1.0.0",
"description": "Bot ",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"preinstall": "npm cache clear --force",
"postinstall": "tsc -p ."
},
"dependencies": {
"@types/dotenv": "^4.0.2",
"@types/restify": "^5.0.7",
"@types/tedious": "^1.8.32",
"botbuilder": "^3.14.0",
"botbuilder-azure": "^3.0.4",
"dotenv": "^5.0.0",
"request-promise": "^4.2.2",
"restify": "^6.3.4",
"typescript": "^2.7.1"
},
"engines": {
"node": "4.0.0"
},
"repository": {
...
},
"keywords": [
...
],
"author": "...",
"license": "ISC",
"bugs": {
"url": "..."
},
"homepage": "..."
}
来自WebSocketMessageBrokerStats的响应:
@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)
}
}
经纪人详情:
{
"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"
}
对于客户我正在使用angular 5
当我使用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}]
时,一切正常
当我启用registry.enableSimpleBroker("/chat")
时,我得到了:
消息:经纪人无法使用。 内容长度:0
的pom.xml:
registry.enableStompBrokerRelay("/chat")...
答案 0 :(得分:3)
您正尝试在不运行stomp适配器的rabbitmq上使用stomp协议进行连接。 运行:
rabbitmq-plugins enable rabbitmq_stomp
启用stomp。
此外,您正在连接到端口5672,即amqp协议/适配器。这就是你拥有stompCommand=ERROR, nativeHeaders={message=[Broker not available.]}
的原因。
一旦启用,stomp适配器将默认侦听tcp / 61613。