6

I am working on a chat application developed using Spring4 Messaging and STOMP implemented with SockJS. The application works fine when I use the Simple Message Broker :

config.enableSimpleBroker("/queue/", "/topic/");

But, now we have a requirement to use an external broker(RabbitMQ) with the same application. For that, I changed the above code with the following:

// config.enableSimpleBroker("/queue/", "/topic/");
config.enableStompBrokerRelay("/queue", "/topic");

My client side is connecting using STOMP client as below:

stompClient.connect({},  function(frame) {
    // subscribe to topics or queues and other stuff
});

But, I got the following exception:

2014-05-09 11:13:13,567 ERROR        o.s.s.support.TaskUtils$LoggingErrorHandler - Unexpected error occurred in scheduled task.
org.springframework.messaging.MessageDeliveryException: Message broker is not active.
at org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler.handleMessageInternal(StompBrokerRelayMessageHandler.java:378) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler.handleMessage(AbstractBrokerMessageHandler.java:171) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.messaging.support.ExecutorSubscribableChannel.sendInternal(ExecutorSubscribableChannel.java:64) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:116) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:98) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.messaging.simp.SimpMessagingTemplate.doSend(SimpMessagingTemplate.java:129) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.messaging.simp.SimpMessagingTemplate.doSend(SimpMessagingTemplate.java:48) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:93) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(AbstractMessageSendingTemplate.java:146) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(AbstractMessageSendingTemplate.java:112) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.messaging.core.AbstractMessageSendingTemplate.convertAndSend(AbstractMessageSendingTemplate.java:106) ~[spring-messaging-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at com.attomic.chat.service.ActiveUserPinger.pingUsers(ActiveUserPinger.java:24) ~[ActiveUserPinger.class:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_05]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_05]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_05]
at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0_05]
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [na:1.7.0_05]
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351) [na:1.7.0_05]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178) [na:1.7.0_05]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) [na:1.7.0_05]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.7.0_05]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [na:1.7.0_05]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [na:1.7.0_05]
at java.lang.Thread.run(Thread.java:722) [na:1.7.0_05]

I checked RabbitMQ and it is up and running. The STOMP plugin is also installed and working fine in RabbitMQ.I also tried the following:

1. config.enableStompBrokerRelay("/queue", "/topic").setSystemLogin("guest").setSystemPasscode("guest");
2. config.enableStompBrokerRelay("/queue", "/topic").setClientLogin("guest").setClientPasscode("guest");
3. config.enableStompBrokerRelay("/queue", "/topic").setRelayHost("localhost").setRelayPort("15672");

I have done quite a bit of search but still unable to resolve this. Can somebody throw some light on this?

Gurminder Singh
  • 1,755
  • 16
  • 19
  • If that is the only thing you changed you are missing several other properties. See also http://stackoverflow.com/questions/20747283/spring-4-websocket-remote-broker-configuration and the [javadoc](http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/messaging/simp/config/StompBrokerRelayRegistration.html) – M. Deinum May 09 '14 at 06:01
  • I have tried all the properties(edited the question). I think there is something missing on the client side, but don't know what. – Gurminder Singh May 09 '14 at 06:10

1 Answers1

3

After doing some research and some experiments, as expected, I found out that the problem is on the client side. Changing

stompClient.connect({},  function(frame) {
    // subscribe to topics or queues and other stuff
});

to

stompClient.connect('guest', 'guest',  function(frame) {
    // subscribe to topics or queues and other stuff
});

worked like a charm. Here, first argument guest is the username and second argument guest is the password of the RabbitMQ server. So the basic point here is that whenever you configure an external broker you need to pass the username and password of the server. In case of simple broker, no need of passing credentials. Cheers!!

Gurminder Singh
  • 1,755
  • 16
  • 19
  • 3
    While slightly old, it might be worth while to mention that you can avoid passing in the user name and password with the connect if you specify the client login credentials from Spring AND set the default user for the RabbitMQ stomp plugin. [See the Default User Section for more details](http://www.rabbitmq.com/stomp.html) – Jaymes Bearden Feb 26 '15 at 18:37