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