gpt4 book ai didi

rabbitmq - 在 Spring4+STOMP+SockJS 应用中配置外部 Broker(RabbitMQ)

转载 作者:行者123 更新时间:2023-12-04 15:34:10 25 4
gpt4 key购买 nike

我正在开发使用 Spring4 Messaging 和 SockJS 实现的 STOMP 开发的聊天应用程序。当我使用 时,应用程序工作正常简单消息代理 :

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

但是,现在我们需要在相同的应用程序中使用外部代理(RabbitMQ)。为此,我使用以下内容更改了上述代码:
// config.enableSimpleBroker("/queue/", "/topic/");
config.enableStompBrokerRelay("/queue", "/topic");

我的客户端正在使用 STOMP 客户端进行连接,如下所示:
stompClient.connect({},  function(frame) {
// subscribe to topics or queues and other stuff
});

但是,我得到以下异常:
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]

我检查了 RabbitMQ,它已经启动并正在运行。 STOMP 插件 在 RabbitMQ 中也已安装并运行良好。我还尝试了以下操作:
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");

我已经做了很多搜索,但仍然无法解决这个问题。有人可以对此有所了解吗?

最佳答案

在做了一些研究和一些实验之后,正如预期的那样,我发现问题出在客户端。改变

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


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

像魅力一样工作。这里,第一个参数 guest 是 用户名 第二个参数 guest 是 密码 RabbitMQ 服务器。所以这里的基本点是,每当你配置一个 外部经纪商您需要传递服务器的用户名和密码。如果是 简单的经纪人 ,无需通过凭据。干杯!!

关于rabbitmq - 在 Spring4+STOMP+SockJS 应用中配置外部 Broker(RabbitMQ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23557473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com