rabbitmq连接amqp.rabbit.connection.CachingConnectionFactory] - Channel shutdown: connection error

在windows服务器装了一个rabbitmq消息中间件,在项目中进行远程连接时,当一段时间没有使用,项目中一直出现如下异常,一旦你进行消息发送又不能够正常工作,这个异常不影响使用,但是具体存在什么隐患我也不清楚:

[SimpleAsyncTaskExecutor-9] WARN  [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] - Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection timed out: connect

[SimpleAsyncTaskExecutor-9] INFO  [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] - Restarting Consumer: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0

ERROR [org.springframework.amqp.rabbit.connection.CachingConnectionFactory] - Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - broker forced connection closure with reason 'shutdown', class-id=0, method-id=0)

ERROR [org.springframework.amqp.rabbit.connection.CachingConnectionFactory] - Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - broker forced connection closure with reason 'shutdown', class-id=0, method-id=0)

[SimpleAsyncTaskExecutor-10] WARN  [org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] - Consumer raised exception, processing can restart if the connection factory supports it
com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - broker forced connection closure with reason 'shutdown', class-id=0, method-id=0)
    at com.rabbitmq.client.impl.AMQConnection.startShutdown(AMQConnection.java:715)
    at com.rabbitmq.client.impl.AMQConnection.shutdown(AMQConnection.java:705)
    at com.rabbitmq.client.impl.AMQConnection.handleConnectionClose(AMQConnection.java:660)
    at com.rabbitmq.client.impl.AMQConnection.processControlCommand(AMQConnection.java:615)
    at com.rabbitmq.client.impl.AMQConnection$1.processAsync(AMQConnection.java:107)
    at com.rabbitmq.client.impl.AMQChannel.handleCompleteInboundCommand(AMQChannel.java:144)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:91)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:540)
    at java.lang.Thread.run(Thread.java:745)

 

在远程连接时出现此问题,查询网上资料说rabbitmq在单机情况下都是长连接,我这也并没有使用集群,考虑会不会是新建用户并授权后,但是远程连接有限制一定时间后对于不活动的客户端连接会自动断开连接,抱着试试的心态,找到rabbitmq.config,设置{loopback_users, ["username"]} 引号内是用户名,如果是对所有用户就置空就行

 %% The default "guest" user is only permitted to access the server
   %% via a loopback interface (e.g. localhost).
   %% {loopback_users, [<<"guest">>]},
   %%
   %% Uncomment the following line if you want to allow access to the
   %% guest user from anywhere on the network.
   %% {loopback_users, []},  --注意下面没有元素是逗号不要

然后通过命令stop停止rabbitmq服务器并install重装服务,再start启动,客户端再没有出现这个异常问题了,特此记录一下备忘

To define a bean of type 'org.springframework.amqp.rabbit.connection.ConnectionFactory' in your Spring configuration, you can use the following steps: 1. Make sure you have the necessary dependencies in your project's build file. For example, if you're using Maven, include the following dependency in your pom.xml file: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency> ``` 2. Open your configuration class and annotate it with `@Configuration` to indicate that it is a configuration class. 3. Define a method within the class and annotate it with `@Bean`. This method will create and configure the bean. 4. Inside the method, instantiate an object of type `org.springframework.amqp.rabbit.connection.ConnectionFactory`. You can use any implementation of this interface, such as `org.springframework.amqp.rabbit.connection.CachingConnectionFactory`. 5. Configure the connection factory according to your needs. For example, you can set the host, port, username, password, etc. using appropriate setters or through application properties. Here's an example of how the code might look like: ```java import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class RabbitMQConfig { @Bean public ConnectionFactory connectionFactory() { CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); connectionFactory.setHost("localhost"); connectionFactory.setPort(5672); connectionFactory.setUsername("guest"); connectionFactory.setPassword("guest"); // Configure other properties as needed return connectionFactory; } } ``` Make sure to adjust the connection details based on your RabbitMQ setup. I hope this helps! Let me know if you have any further questions.
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值