8

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?

Community
  • 1
  • 1
Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145

1 Answers1

14

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.

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
  • Maybe you know. When I write registry.enableStompBrokerRelay("/topic"); its worked, but simpTemplate.convertAndSend(...) take 4-8 seconds. With simple broker its take some milliseconds. Why? – Nickolay Savchenko Feb 23 '17 at 08:33
  • In that case, the only difference is the broker itself. I'd say this deserves its own SO question (with more details - can't you get more information from the broker?), since this has nothing to do with the current one. – Brian Clozel Feb 23 '17 at 08:35
  • Ok its offtopic, here my question http://stackoverflow.com/questions/40380069/simpmessagingtemplate-convertandsend-with-rabbitmq-works-very-slow – Nickolay Savchenko Feb 23 '17 at 08:50
  • @BrianClozel how would we change port of simple broker in boot – naila naseem Apr 06 '18 at 11:29