java Spring RabbitMQ 教程导致 Connection Refused 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30223203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring RabbitMQ tutorial results in Connection Refused error
提问by stackoverflowuser2010
I'm an experienced Java programmer and am trying out Spring Rabbit MQ for the first time.
我是一名经验丰富的 Java 程序员,并且是第一次尝试 Spring Rabbit MQ。
I followed the messaging-rabbitMQ tutorial exactlyusing Maven. http://spring.io/guides/gs/messaging-rabbitmq/
我完全使用 Maven遵循了消息传递rabbitMQ 教程。 http://spring.io/guides/gs/messaging-rabbitmq/
I am running on CentOS as a user account.
我作为用户帐户在 CentOS 上运行。
When I ran the application at the very end of the tutorial with java -jar target/gs-messaging-rabbitmq-0.1.0.jar
, I got the following Connection Refused error. Can someone help?
当我在教程的最后使用 运行应用程序时java -jar target/gs-messaging-rabbitmq-0.1.0.jar
,出现以下连接拒绝错误。有人可以帮忙吗?
prompt> java -jar target/gs-messaging-rabbitmq-0.1.0.jar
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.2.3.RELEASE)
2015-05-13 11:49:44.833 INFO 26218 --- [ main] hello.Application : Starting Application v0.1.0 on minerva-02-33.gbcl.net with PID 26218 (/home/ccpm/test/spring_rabbitmq/target/gs-messaging-rabbitmq-0.1.0.jar started by ccpm in /home/ccpm/test/spring_rabbitmq)
2015-05-13 11:49:44.912 INFO 26218 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@8146158: startup date [Wed May 13 11:49:44 PDT 2015]; root of context hierarchy
2015-05-13 11:49:45.863 INFO 26218 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.amqp.rabbit.annotation.RabbitBootstrapConfiguration' of type [class org.springframework.amqp.rabbit.annotation.RabbitBootstrapConfiguration$$EnhancerBySpringCGLIB$a886eed] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-05-13 11:49:46.397 INFO 26218 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2015-05-13 11:49:46.404 INFO 26218 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647
2015-05-13 11:49:46.433 ERROR 26218 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).
org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:54)
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:207)
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:441)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:80)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:130)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:67)
at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1035)
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1028)
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1004)
at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:254)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.redeclareElementsIfNecessary(SimpleMessageListenerContainer.java:947)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access0(SimpleMessageListenerContainer.java:82)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1065)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:615)
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:199)
... 12 common frames omitted
Waiting five seconds...
2015-05-13 11:49:51.437 WARN 26218 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused
2015-05-13 11:49:51.437 INFO 26218 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0
2015-05-13 11:49:51.441 ERROR 26218 --- [cTaskExecutor-2] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).
org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:54)
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:207)
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:441)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:80)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:130)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:67)
at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1035)
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1028)
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1004)
at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:254)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.redeclareElementsIfNecessary(SimpleMessageListenerContainer.java:947)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access0(SimpleMessageListenerContainer.java:82)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1065)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at com.rabbitmq.client.impl.FrameHandlerFactory.create(FrameHandlerFactory.java:32)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:615)
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:199)
... 12 common frames omitted
回答by Leon
You do not have RabbitMQ server installed. Luckily this is pretty easy to do. You mentioned you are using CentOS, here you can download RabbitMQ server: https://www.rabbitmq.com/install-rpm.html
您没有安装 RabbitMQ 服务器。幸运的是,这很容易做到。您提到您使用的是 CentOS,您可以在这里下载 RabbitMQ 服务器:https: //www.rabbitmq.com/install-rpm.html
There are a couple of steps you will need to follow, including installing Erlang.
您需要遵循几个步骤,包括安装 Erlang。
The Spring example assumes you already know a bit about using a message broker. This is in itself a technology you will need to use, like when you had to learn to use a database or an operating system.
Spring 示例假设您已经对使用消息代理有所了解。这本身就是一项您需要使用的技术,就像您必须学习使用数据库或操作系统时一样。
回答by ionised
This is an old question but I'll post my answer anyway as it addresses an issue with this particular step of the Spring tutorial that the other answer doesn't.
这是一个老问题,但无论如何我都会发布我的答案,因为它解决了 Spring 教程中这个特定步骤的问题,而另一个答案没有。
If you are using the docker-compose.yml
file specified in the Spring tutorial to launch a RabbitMQ server in a Docker container you might run into the same issue I had connecting to it, which I outlined in this question;
如果您使用docker-compose.yml
Spring 教程中指定的文件在 Docker 容器中启动 RabbitMQ 服务器,您可能会遇到我连接到它时遇到的相同问题,我在这个问题中概述了这个问题;
Docker image for Spring/RabbitMQ tutorial results in connection refused
Spring/RabbitMQ 教程的 Docker 映像导致连接被拒绝
After coming back to it a couple of days later though I managed to find the solution;
几天后回到它之后,虽然我设法找到了解决方案;
https://stackoverflow.com/a/44882772/8215811
https://stackoverflow.com/a/44882772/8215811
The Spring tutorial unfortunately does not clarify that you need to configure connection information when choosing using the docker-compose
file over the manual installation of RabbitMQ, which is unfortunate as the Docker method seems easier and more straightforward.
不幸的是,Spring 教程没有说明在选择使用docker-compose
文件而不是手动安装 RabbitMQ时需要配置连接信息,这很不幸,因为 Docker 方法看起来更简单、更直接。