PHP solves the problem of automatic disconnection of RabbitMQ consumers

 When running php under cmd and using rabbitmq to obtain server message consumption, after running for a few minutes, it will be stuck and disconnected.

No matter how to send a message to the server, the consumer did not respond.

I grabbed a data packet to view it. The following picture shows the consumer consuming the message, port 55155:

Later learned that a value of zero means that the peer (consumer) recommends to disable heartbeat altogether.

The default in the code is 0:

 

Later, the packet was captured again, port 60351, when there was no message in the queue,

Later, I saw that it was performing heartbeat packet detection:

Finally, it actively disconnected from the consumer.

After rabbitmq receives the connection.tune-ok signaling from the client, it enables heartbeat detection,

Rabbitmq will create two processes for each tcp connection for heartbeat detection. One process regularly detects whether there is data sent on the tcp connection (the sending here refers to rabbitmq sending data to the client),

If no data is sent to the client within a period of time, a heartbeat packet is sent to the client, and then the next detection is performed in a loop;

Another process regularly detects whether there is data reception on the tcp connection. If no data is received for a period of time, it is determined that the heartbeat has timed out, and the tcp connection will eventually be closed.

 

When you start the consumer, you see in the rabbitmq background:

The final solution:

more info:

https://www.rabbitmq.com/heartbeats.html

https://blog.csdn.net/jiao_fuyou/article/details/23186407

https://www.jianshu.com/p/59247da47db4

http://www.nowamagic.net/academy/detail/23350382

 

 

Guess you like

Origin blog.csdn.net/yyws2039725/article/details/113897388