【问题标题】:Spring 4 WebSocket Remote Broker configurationSpring 4 WebSocket 远程代理配置
【发布时间】:2014-01-11 21:25:51
【问题描述】:

我设法使用 Spring 4 和 Stomp 创建了简单的 Websocket 应用程序。看我最后一个问题here 然后我尝试使用远程消息代理(ActiveMQ)。我刚启动代理并更改了

registry.enableSimpleBroker("/topic");

registry.enableStompBrokerRelay("/topic");

它奏效了。

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

【问题讨论】:

  • 如何在 spring boot 中更改 SimpleBroker 的端口?

标签: java spring spring-mvc websocket spring-4


【解决方案1】:

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

您可以使用这个 fluent API 来配置您的代理中继:

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。

【讨论】:

  • 也许你知道。当我写 registry.enableStompBrokerRelay("/topic");它有效,但 simpTemplate.convertAndSend(...) 需要 4-8 秒。使用简单的代理需要几毫秒。为什么?
  • 在这种情况下,唯一的区别是经纪人本身。我想说这应该有它自己的 SO 问题(更多细节 - 你不能从经纪人那里获得更多信息吗?),因为这与当前问题无关。
  • 好吧,题外话,这是我的问题stackoverflow.com/questions/40380069/…
  • @BrianClozel 我们如何在启动时更改简单代理的端口
猜你喜欢
  • 1970-01-01
  • 2012-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多