Creating multiple instances of websocket message broker in Spring 4

I want to create multiple instances of a message broker in Spring 4. I am using the following configuration:

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

      

And in my controller I am running SimpMessagingTemplate.

I am getting the following exception:

Caused by: org.springframework.beans.factory.BeanCreationException:
Failed to create autwire field: org.springframework.messaging.simp.SimpMessagingTemplate
com.cdk.phoenix.app.controller.tools.tail.LogTailController.template; nested
exception org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
qualifying bean of type [org.springframework.messaging.simp.SimpMessagingTemplate]
is definition: Expected single match bean but found 2:
org.springframework.SimpagingMessaging # , org.springframework.mes
saging.simp.SimpMessagingTemplate # 1

How can I create a unique instance SimpMessagingTemplate

for different message brokers?

+3


source to share


1 answer


As an interim fix, I added a classifier as shown below:

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

      

Everything works as expected, but the logs show one error message:



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

      

Is there a way to fix this error?

Thanks, Santosh

+1


source







All Articles