gpt4 book ai didi

java - 在 Spring 4 中创建多个 websocket 消息代理实例

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:58:50 24 4
gpt4 key购买 nike

我想在 Spring 4 中创建多个消息代理实例。我正在使用以下配置:

<websocket:message-broker application-destination-prefix="/App1" >
<websocket:stomp-endpoint path="/path1">
<websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic"/>
</websocket:message-broker>

<websocket:message-broker application-destination-prefix="/App2">
<websocket:stomp-endpoint path="/path2">
<websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic"/>
</websocket:message-broker>

在我的 Controller 中,我正在 Autowiring SimpMessagingTemplate。

我收到以下异常:

Caused by: org.springframework.beans.factory.BeanCreationException:
Could not autowire field: org.springframework.messaging.simp.SimpMessagingTemplate
com.cdk.phoenix.app.controller.tools.tail.LogTailController.template; nested
exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
qualifying bean of type [org.springframework.messaging.simp.SimpMessagingTemplate]
is defined: expected single matching bean but found 2:
org.springframework.messaging.simp.SimpMessagingTemplate#0,org.springframework.mes
saging.simp.SimpMessagingTemplate#1

如何为不同的消息代理创建唯一的 SimpMessagingTemplate 实例?

最佳答案

作为临时修复,我添加了如下限定符:

@Autowired
@Qualifier("org.springframework.messaging.simp.SimpMessagingTemplate#1")
SimpMessagingTemplate template;

一切都按预期工作,但日志中显示一条错误消息:

*ERROR* SubProtocolWebSocketHandler: handleMessage - No session for [Payload byte[0]][Headers={simpMessageType=CONNECT_ACK, nativeHeaders={}, simpConnectMessage=[Payload byte[0]][Headers={simpMessageType=CONNECT, stompCommand=CONNECT, nativeHeaders={heart-beat=[10000,10000], accept-version=[1.1,1.0]}, simpSessionAttributes={}, simpSessionId=katcl9hg, id=2627fb55-4c8a-365c-7211-e543578e9ffb, timestamp=1438601578923}], simpSessionId=katcl9hg, id=4b4f7b0e-237a-7b3b-7d3e-247096e82b51, timestamp=1438601578924}]

有没有办法解决这个错误?

谢谢,桑托斯

关于java - 在 Spring 4 中创建多个 websocket 消息代理实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31108966/

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