【问题标题】:Creating multiple instances of websocket message broker in Spring 4在 Spring 4 中创建多个 websocket 消息代理实例
【发布时间】:2015-06-29 06:18:13
【问题描述】:

我想在 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>

在我的控制器中,我正在自动装配 SimpMessagingTemplate。

我收到以下异常:

引起:org.springframework.beans.factory.BeanCreationException:
无法自动装配字段: org.springframework.messaging.simp.SimpMessagingTemplate
com.cdk.phoenix.app.controller.tools.tail.LogTailController.template; 嵌套
例外是 org.springframework.beans.factory.NoUniqueBeanDefinitionException: 否
限定 bean 类型 [org.springframework.messaging.simp.SimpMessagingTemplate]
是 已定义:预期的单个匹配 bean,但找到了 2:
org.springframework.messaging.simp.SimpMessagingTemplate#0,org.springframework.mes
saging.simp.SimpMessagingTemplate#1

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

【问题讨论】:

    标签: java spring spring-mvc spring-websocket


    【解决方案1】:

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

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

    有没有办法修复这个错误?

    谢谢, 桑托什

    【讨论】:

    • 你还记得你是如何解决这个问题的吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 2014-02-07
    • 1970-01-01
    • 2016-07-06
    相关资源
    最近更新 更多