swarrot / SwarrotBundle

A symfony bundle for swarrot integration
MIT License
89 stars 59 forks source link

Unable to manage heartbeats with PECL provider #146

Closed dorianyah closed 5 years ago

dorianyah commented 5 years ago

Hi,

Here is our stack :

Our problem

  1. Our HaProxy has a timeout that close the connection between our application and RabbitMQ.
  2. According to RabbitMQ specs, the use of heartbeats is highly recommended (https://www.rabbitmq.com/heartbeats.html)
  3. Do you know any implementation to manage heartbeats using the PECL provider with the SwarrotBundle ?

Thanks

odolbeau commented 5 years ago

Hi.

Thanks for this bug report. Could we have more information?

Regarding the heartbeat configuration with pecl it looks like it's not perfectly implemented: (See https://github.com/pdezwart/php-amqp/blob/master/stubs/AMQPConnection.php#L42-L44). It looks like it's used only when using blocking call. As we do not use the consume method in the current swarrot implementation it probably won't change anything to specify a heartbeat configuration.

dorianyah commented 5 years ago

Hi,

Thanks for the fast feedback.

Answers to your 3 questions :

  1. Here is the essential part of our HaProxy configuration, we are using timeout of 10 seconds

    defaults
    timeout connect 10s
    timeout client 10s
    timeout server 10s
  2. We are experiencing that while publishing. We are using a daemon that publish messages on a irregular basis. But because the connection is established once at the first "publishing", it is closed when no messages are sent for more than the "10s defined timeout". We then noticed a crash of the script with this exception : "[Error] Library error: a socket error occured" "[Error] Could not publish to exchange. No channel available"

  3. We understood that sending heartbeats could maintain a TCP connection opened during a certain amount of time to keep some TCP activity and to prevent the connexion to be closed by a proxy.

We first thought of implementing a reconnection pattern, but as the heartbeat seems to be a core feature of the AMQP protocol, we were interested in using it.

Thanks for any insight

odolbeau commented 5 years ago

Thanks, that's perfectly clear!

As mention in the documentation I gave previously, I doubt you'll solve your problem with the heartbeat implementation provided by the pecl extension. Anyway, don't hesitate to make a PR to support this option in the bundle. You should only need to update the PeclFactory to update your connection if a heartbeat is specified (in the url maybe?).

2 others solutions you should consider:

dorianyah commented 5 years ago

Edit : Thanks, we will investigate this.