spring boot无法连接远程rabbitmq,Failed to check/redeclare auto-delete queue(s).
让运维在192.168.1.73上新装了rabbitmq,版本如下
当在本地使用idea spring boot代码连接远程rabbitmq配置,死活连不上,本地代码连接本机的MQ就没有问题,连接远程报如下错误
5:22:42.157 [restartedMain] INFO o.s.a.r.c.CachingConnectionFactory - [connectAddresses,638] - Attempting to connect to: [192.169.1.73:5672] 15:23:42.163 [restartedMain] INFO o.s.a.r.l.SimpleMessageListenerContainer - [checkMismatchedQueues,1850] - Broker not available; cannot force queue declarations during start: java.net.SocketTimeoutException: connect timed out 15:23:42.169 [org.springframework.amqp.rabbit.RabbitListenerEndpointContainer#0-1] INFO o.s.a.r.c.CachingConnectionFactory - [connectAddresses,638] - Attempting to connect to: [192.169.1.73:5672] 15:24:42.172 [restartedMain] ERROR o.s.a.r.l.SimpleMessageListenerContainer - [getStartupException,1183] - Consumer failed to start in 60000 milliseconds; does the task executor have enough threads to support the container concurrency? 15:24:42.173 [restartedMain] DEBUG o.s.c.s.DefaultLifecycleProcessor - [doStart,184] - Successfully started bean 'org.springframework.amqp.rabbit.config.internalRabbitListenerEndpointRegistry' 15:24:42.173 [restartedMain] INFO o.s.s.q.SchedulerFactoryBean - [startScheduler,729] - Starting Quartz Scheduler now 15:24:42.173 [restartedMain] INFO o.q.c.QuartzScheduler - [start,547] - Scheduler quartzScheduler_$_NON_CLUSTERED started. 15:24:42.173 [restartedMain] DEBUG o.s.c.s.DefaultLifecycleProcessor - [doStart,184] - Successfully started bean 'quartzScheduler' 15:24:42.173 [restartedMain] DEBUG o.s.c.s.DefaultLifecycleProcessor - [doStart,184] - Successfully started bean 'webServerGracefulShutdown' 15:24:42.178 [org.springframework.amqp.rabbit.RabbitListenerEndpointContainer#0-1] ERROR o.s.a.r.l.SimpleMessageListenerContainer - [redeclareElementsIfNecessary,1901] - Failed to check/redeclare auto-delete queue(s). org.springframework.amqp.AmqpIOException: java.net.SocketTimeoutException: connect timed out at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:70) at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:602) at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:724) at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:252) at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:2175) at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2148) at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2128) at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueInfo(RabbitAdmin.java:407) at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:391) at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.attemptDeclarations(AbstractMessageListenerContainer.java:1914) at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.redeclareElementsIfNecessary(AbstractMessageListenerContainer.java:1895) at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.initialize(SimpleMessageListenerContainer.java:1374) at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1220) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.net.SocketTimeoutException: connect timed out at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399) at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242) at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224) at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.base/java.net.Socket.connect(Socket.java:608) at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1220) at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1170) at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connectAddresses(AbstractConnectionFactory.java:640) at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connect(AbstractConnectionFactory.java:615) at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:565) ... 12 common frames omitted 15:24:42.180 [org.springframework.amqp.rabbit.RabbitListenerEndpointContainer#0-1] DEBUG o.s.a.r.l.BlockingQueueConsumer - [start,590] - Starting consumer Consumer@64b7120d: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0 15:24:42.181 [org.springframework.amqp.rabbit.RabbitListenerEndpointContainer#0-1] INFO o.s.a.r.c.CachingConnectionFactory - [connectAddresses,638] - Attempting to connect to: [192.169.1.73:5672]
就算是把代码打包,部署到rabbitmq所在服务器,也无法连接。
最后尝试一招,在rabbitmq上新创建admin类型的用户,配置好相关权限,将新配置写入代码,发现就可以了!!!
本文来自博客园,作者:margo,转载请注明原文链接:https://www.cnblogs.com/ZMargo/articles/16825633.html