8

我设法用 Spring 4 和 Stomp 创建了简单的 Websocket 应用程序。在这里查看我的最后一个问题 然后我尝试使用远程消息代理(ActiveMQ)。我刚开始代理并改变了

registry.enableSimpleBroker("/topic");

registry.enableStompBrokerRelay("/topic");

它奏效了。

问题是如何配置代理?我知道在这种情况下,应用程序会自动在 localhost:defaultport 上找到代理,但是如果我需要将应用程序指向其他机器上的其他代理怎么办?

4

1 回答 1

14

enableStompBrokerRelay方法返回一个方便的注册实例,该实例公开了一个流畅的 API。

你可以使用这个 fluent API 来配置你的 Broker 中继:

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

您还可以配置各种属性,例如代理的登录/传递凭据等。

与 XML 配置相同:

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

有关属性和默认值的更多详细信息,请参阅StompBrokerRelayRegistration javadoc。

于 2013-12-27T10:29:07.870 回答