我一直在尝试开发同时使用activeMQ和RabbitMQ的项目.我在pom.xml中添加的依赖项如下所示:
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>1.4.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
<version>5.13.0</version>
</dependency>
另外,我同时运行apache-activemq-5.13.0和rabbitmq-server-3.5.6.
但不幸的是,我遇到了与AMQP相关的错误,并在下面进行了演示:
java.io.IOException
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:350)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:648)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:678)
at org.hafiz.framework.common.rabbit.filter.ReceiveRabbitMessageFilter.init(ReceiveRabbitMessageFilter.java:33)
at org.hafiz.common.filter.PrmTarrifTypeMessageFilter.init(PrmTarrifTypeMessageFilter.java:21)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4854)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5546)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1263)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1948)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error
at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:37)
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:367)
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:293)
... 20 more
Caused by: com.rabbitmq.client.MalformedFrameException: AMQP protocol version mismatch; we are version 0-9-1, server sent signature 0,1,0,0
at com.rabbitmq.client.impl.Frame.protocolVersionMismatch(Frame.java:174)
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:111)
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:536)
... 1 more
java.lang.NullPointerException
at org.hafiz.framework.common.rabbit.filter.ReceiveRabbitMessageFilter.receiveMessage(ReceiveRabbitMessageFilter.java:61)
at org.hafiz.common.filter.PrmTarrifTypeMessageFilter$1.run(PrmTarrifTypeMessageFilter.java:29)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
如果有人帮助我解决此错误,我将不胜感激.
解决方法:
解决方案是仅更改那些消息代理端口号之一.由于它们都在同一个端口(5672)上工作,因此您只需更改其中一个的配置即可.
对于RabbitMQ,您可以使用here解释的指令,就像@Kenney所说的那样,它就像设置环境变量一样简单.
注意:在设置变量期间,不要忘记重新安装RabbitMQ服务.
在Windows中,您可以通过在命令提示符下运行以下命令来执行此操作:
> cd进入RabbitMQ服务器安装目录下的sbin文件夹,然后运行rabbitmq-service.bat remove
>设置RABBITMQ_NODE_PORT = xxxx
> rabbitmq-service.bat安装
此外,如果它不起作用,您可以简单地将ActiveMQ的默认端口更改为amqp.为此,您应该在ActiveMQ服务器安装目录中的conf文件夹中查找文件名activemq.xml.
希望这对您有用.