Java Spring STOMP: Set broker IP

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-07 05:33:05

问题


I have a Java application using Spring that uses Websocket, which works fine as long as RabbitMQ runs in the same machine as tomcat.

How can I set the IP for RabbitMQ ? I am reading the documentation and I don't find it.

My current configuration is very similar to the one in the documentation

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:websocket="http://www.springframework.org/schema/websocket"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/websocket
        http://www.springframework.org/schema/websocket/spring-websocket.xsd">

    <websocket:message-broker application-destination-prefix="/app">
        <websocket:stomp-endpoint path="/portfolio">
            <websocket:sockjs/>
        </websocket:stomp-endpoint>
        <websocket:simple-broker prefix="/topic, /queue"/>
    </websocket:message-broker>

</beans>

How can I set the IP ?


回答1:


Hi You are using simple broker(<websocket:simple-broker prefix="/topic, /queue"/>). Try to use below settings :

<websocket:message-broker application-destination-prefix="/app">
    <websocket:stomp-endpoint path="/ws">
      <websocket:sockjs/>
    </websocket:stomp-endpoint>
     <websocket:stomp-broker-relay prefix="/topic"
           relay-host="${websocket.relay.host}" relay-port="61613" client-login="user" client-passcode="passwd" system-login="user" system-passcode="passwd"
           heartbeat-send-interval="20000" heartbeat-receive-interval="20000"/>
</websocket:message-broker>

This configuration will help you adding ip. You might also need to add inbound and outbound channel configuration as default channel is one.Under load on a single channel response will be very slow. Insert below snippet in between <websocket:message-broker> and </websocket:message-broker> tags :

<websocket:client-inbound-channel>
<websocket:executor core-pool-size="50" max-pool-size="100" keep-alive-seconds="60"/>
</websocket:client-inbound-channel>
<websocket:client-outbound-channel>
<websocket:executor core-pool-size="50" max-pool-size="100" keep-alive-seconds="60"/>
</websocket:client-outbound-channel>
<websocket:broker-channel>
<websocket:executor core-pool-size="50" max-pool-size="100" keep-alive-seconds="60"/>
</websocket:broker-channel>

Also you will need to add login credentials in case your rabbitmq server is a different from application. For this you need to change configuration file. You can get this in RabbitMQ documentation



来源:https://stackoverflow.com/questions/34504410/java-spring-stomp-set-broker-ip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!