2013-12-23 96 views
6

我設法使用Spring 4和Stomp創建簡單的Websocket應用程序。看到我的最後一個問題here 然後我嘗試使用遠程消息代理(ActiveMQ)。我剛開始代理並改變Spring 4 WebSocket Remote Broker配置

registry.enableSimpleBroker("/topic"); 

registry.enableStompBrokerRelay("/topic"); 

和它的工作。

問題是經紀人是如何配置的?我知道在這種情況下,應用程序automagicaly會在localhost上找到代理:defaultport,如果我需要將應用程序指向其他計算機上的其他代理,該怎麼辦?

回答

10

enableStompBrokerRelay方法返回一個方便的註冊實例,公開流暢的API。

您可以使用此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。

+0

也許你知道。當我寫registry.enableStompBrokerRelay(「/ topic」);它的工作,但simpTemplate.convertAndSend(...)需要4-8秒。簡單的經紀人需要幾毫秒。爲什麼? –

+0

在這種情況下,唯一的區別是經紀人本身。我想說這是值得的自己的問題(有更多的細節 - 你不能從經紀人那裏獲得更多信息嗎?),因爲這與現在的問題無關。 –

+0

確定其offtopic,在這裏我的問題http://stackoverflow.com/questions/40380069/simpmessagingtemplate-convertandsend-with-rabbitmq-works-very-slow –