Spring 4 WebSocket Remote Broker configuration

六眼飞鱼酱① 提交于 2020-01-28 20:59:30

问题


I managed to create simple Websocket application with Spring 4 and Stomp. See my last question here Then I tried to use remote message broker(ActiveMQ). I just started the broker and changed

registry.enableSimpleBroker("/topic");

to

registry.enableStompBrokerRelay("/topic");

and it worked.

The question is how the broker is configured? I understand that in this case the application automagicaly finds the broker on localhost:defaultport, bu what if I need to point the app to some other broker on other machine?


回答1:


The enableStompBrokerRelay method returns a convenient Registration instance that exposes a fluent API.

You can use this fluent API to configure your Broker relay:

registry.enableStompBrokerRelay("/topic").setRelayHost("host").setRelayPort("1234");

You can also configure various properties, like login/pass credentials for your broker, etc.

Same with XML Configuration:

<websocket:message-broker>
  <websocket:stomp-endpoint path="/foo">
    <websocket:handshake-handler ref="myHandler"/>
    <websocket:sockjs/>
  </websocket:stomp-endpoint>
  <websocket:stomp-broker-relay prefix="/topic,/queue" 
      relay-host="relayhost" relay-port="1234"
      client-login="clientlogin" client-passcode="clientpass"
      system-login="syslogin" system-passcode="syspass"
      heartbeat-send-interval="5000" heartbeat-receive-interval="5000"
      virtual-host="example.org"/>
</websocket:message-broker>

See the StompBrokerRelayRegistration javadoc for more details on properties and default values.



来源:https://stackoverflow.com/questions/20747283/spring-4-websocket-remote-broker-configuration

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