本文介绍了Spring 4 WebSocket 远程代理配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

registry.enableSimpleBroker("/topic");

registry.enableStompBrokerRelay("/topic");

它奏效了.

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

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?

推荐答案

enableStompBrokerRelay 方法返回一个方便的 Registration 实例,该实例公开了一个流畅的 API.

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

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

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.

与 XML 配置相同:

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>

参见StompBrokerRelayRegistration javadoc 了解有关属性和默认值的更多详细信息.

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

这篇关于Spring 4 WebSocket 远程代理配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 07:54