gpt4 book ai didi

Spring Boot Web Socket RabbitMQ 不可用

转载 作者:行者123 更新时间:2023-12-02 00:37:27 36 4
gpt4 key购买 nike

我有一个带有网络套接字配置的简单 spring boot 应用程序。

当我使用 SimpleBroker(由 spring 提供)运行我的应用程序时,一切正常,但是当我想使用 rabbitmq 而不是 SimpleBroker 时,我遇到了一些问题,我的代理“不可用”

@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)
}

}

来自 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"
}

经纪人详情:

Overview

Connections

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}]

对于客户,我使用的是 angular 5

当我使用 registry.enableSimpleBroker("/chat") 时一切正常

当我启用 registry.enableStompBrokerRelay("/chat")... 我得到:

消息:经纪人不可用。内容长度: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>

最佳答案

您正在尝试在未运行 stomp 适配器的 rabbitmq 上使用 stomp 协议(protocol)进行连接。运行:

rabbitmq-plugins 启用 rabbitmq_stomp

启用踩踏。

此外,您正在连接到端口 5672,它是 amqp 协议(protocol)/适配器。这就是为什么你有这个 stompCommand=ERROR, nativeHeaders={message=[Broker not available.]}。启用后,stomp 适配器将默认监听 tcp/61613。

关于Spring Boot Web Socket RabbitMQ 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48816410/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com