Unwanted closing of consumers after a long Idle time.

1,300 views
Skip to first unread message

tester...@gmail.com

unread,
Jun 17, 2015, 8:08:39 AM6/17/15
to rabbitm...@googlegroups.com
I am new to RabbitMQ and using PHP-AMQPlib with HA-Policy. I have started creating queues there for my campaigning through CRON. All the entries are getting queued in timely manner. Also  I have a plan of having one consumer alive all the time so the queue message are consumed almost instantly. But the main problem I am facing the Idle consumers/connections/channels are getting removed in any time. As a result the messages which are gathering in the queue are not released until or unless I create one manually.

So anyone please help me to make the consumer alive all the time.

Alvaro Videla

unread,
Jun 17, 2015, 8:22:30 AM6/17/15
to tester...@gmail.com, rabbitm...@googlegroups.com
You can either use heartbeats on your connection, or use something like suepervisord to restart/keepalive your consumers

On Wed, Jun 17, 2015 at 2:08 PM <tester...@gmail.com> wrote:
I am new to RabbitMQ and using PHP-AMQPlib with HA-Policy. I have started creating queues there for my campaigning through CRON. All the entries are getting queued in timely manner. Also  I have a plan of having one consumer alive all the time so the queue message are consumed almost instantly. But the main problem I am facing the Idle consumers/connections/channels are getting removed in any time. As a result the messages which are gathering in the queue are not released until or unless I create one manually.

So anyone please help me to make the consumer alive all the time.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tester...@gmail.com

unread,
Jun 17, 2015, 8:51:09 AM6/17/15
to rabbitm...@googlegroups.com, tester...@gmail.com
Thanx Alvaro Videla for a quick reply. I already have the keep alive ON and also used heartbeat of around 300 sec. But with no result.

Michael Klishin

unread,
Jun 17, 2015, 8:59:26 AM6/17/15
to rabbitm...@googlegroups.com, tester...@gmail.com
On 17 June 2015 at 15:51:12, tester...@gmail.com (tester...@gmail.com) wrote:
> Thanx Alvaro Videla for a quick reply. I already have the keep
> alive ON and also used heartbeat of around 300 sec. But with no
> result.

Networking gear or software between your consumers and RabbitMQ may consider
300 seconds to be larger than their configured idle connection timeouts.

Try 20 seconds ;)
--
MK

Staff Software Engineer, Pivotal/RabbitMQ


Michael Klishin

unread,
Jun 17, 2015, 10:01:12 AM6/17/15
to tester...@gmail.com, rabbitm...@googlegroups.com
+rabbitmq-users 

On 17 June 2015 at 16:56:31, tester...@gmail.com (tester...@gmail.com) wrote:
> Ok thats great. Thanx Michael Klishin alot. Now I need to demonstrate
> my system briefly. In my staging server I have the heartbeat say
> 300 sec. When I have my code uploaded to Production I can not implement
> heartbeat there. Can you please provide me a sample PHP code for
> these. I have also some other issues like .. x-max-prority. How
> to and when pass the arguments for those. I searched a lot bot no
> vein.. all are in JAVA not in PHP.

Please start new threads for new questions. x-max-prority is used the same
way as any other optional queue argument when declaring a queue.

> One more thing, as far as my little knowledge goes, the consumer
> should be alive all the time unless manually drop it down. But
> I am not sure when it drops. Can you share any idea how long it will
> be alive.

If you want to log it when a connection goes down, add a shutdown listener
(in the Java client) or similar. Consumers should also provide a way to run a function
when they are cancelled, in the Java client see Consumer#handleCancel.

tester...@gmail.com

unread,
Jun 18, 2015, 1:32:50 AM6/18/15
to rabbitm...@googlegroups.com, tester...@gmail.com
Hi Alvaro, In any case do you have any sample PHP code to keep comsumer alive?



On Wednesday, June 17, 2015 at 5:52:30 PM UTC+5:30, Alvaro Videla wrote:

Alvaro Videla

unread,
Jun 29, 2015, 10:20:52 AM6/29/15
to tester...@gmail.com, rabbitm...@googlegroups.com
Please keep rabbitmq-users on the CC list
 
The error says the function socket_import_stream is not available on your PHP install. 

According to the PHP manual, that function exist since PHP 5.4


On Mon, Jun 29, 2015 at 3:10 PM <tester...@gmail.com> wrote:

Hi Alvaro,

It’s good to write to you once again. Please read this carefully.  I am a newbie in RabbitMQ and using the repository you have uploaded to github [https://github.com/videlalvaro/php-amqplib]. This is working fine with simple queue. But I badly need to implement a feature of having some of the connections to be alive all the time or say infinite time, In case of a producer the connection needs to be closed with no effect [which I have done already], but in the time of consumer, the connection needs to alive all the time as the queue required to be consumed instantly [Sorry, no help].

That’s why we are running our producer through CRON and the queues are getting generated in regular intervals. Whereas the worker is fired once and that will consume for infinite time, as my application really leads me this way.

The main challenge lies in keep my consumer connection awake all time. It dies in no time.

I applied heartbeat with 30 sec. that’s fine. The connections are set as auto-delete false. That’s fine too. They are durable. Again fine.

I have in my head a couple of question right now,

1.       The AMQPConnection constructor are having these parameters  

public function __construct(

                                                               i.              $host,

                                                             ii.              $port,

                                                            iii.              $user,

                                                           iv.              $password,

                                                             v.              $vhost = '/',

                                                           vi.              $insist = false,

                                                          vii.              $login_method = 'AMQPLAIN',

                                                        viii.              $login_response = null,

                                                           ix.              $locale = 'en_US',

                                                             x.              $connection_timeout = 2,

                                                           xi.              $read_write_timeout = 60,

                                                          xii.              $context = null,

                                                        xiii.              $keepalive = false,

                                                        xiv.              $heartbeat = 30

    )

What  is the connection timeout, and what will be its value to keep it alive all the time? I passed ‘ ’, 0, 10000 with no result.

 

2.       When I keep $keepalive = true, the system eventually punches me back with these errors.

 ( ! ) Fatal error: Uncaught exception 'AMQPIOException' with message 'Can not enable keepalive: function socket_import_stream does not exist'

( ! ) AMQPIOException: Can not enable keepalive: function socket_import_stream does not exist 

I could not help me out to find any method in the repository with the same name, or I blindly make some mistakes. The repository is not containing any functions.

Probably I express my problem properly so Please help me out of this. Sorry for this long topic.  Tons of thanx in advance.

tester...@gmail.com

unread,
Jun 29, 2015, 10:41:45 AM6/29/15
to rabbitm...@googlegroups.com, tester...@gmail.com
Hi Alvaro,

Thanx for quick reply. Wondering, coz I am having PHP v. 5.4.3. Is there anything else?

Alvaro Videla

unread,
Jun 29, 2015, 10:46:09 AM6/29/15
to tester...@gmail.com, rabbitm...@googlegroups.com
Try writing some code that tests for the existence of that function and see what happens. Here's an example: https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Wire/IO/StreamIO.php#L298

--

tester...@gmail.com

unread,
Jun 30, 2015, 7:16:46 AM6/30/15
to rabbitm...@googlegroups.com, tester...@gmail.com
Hi Alvaro,

Thanx for the last input from yours. I did somehow manage with keep-alive to be true. Made a small changes in the php.ini file, i.e. uncommented the line extension=php_sockets.dll. It works well. I am no longer facing any error in my application while queuing.

Now I am wondering if actually the code making any queue with keep-alive value as true. Can't find any place to find this. Do you know any way to get it displayed?
My another question is what is actual usage of $connection_timeout in AMQPConnection constructor? Is this related anyhow with the lifetime of any connection?  if yes, what value to be provided to make a connection everlasting.

Thanx for your co-operation.

Michael Klishin

unread,
Jun 30, 2015, 7:20:33 AM6/30/15
to rabbitm...@googlegroups.com, tester...@gmail.com
 On 30 June 2015 at 14:16:49, tester...@gmail.com (tester...@gmail.com) wrote:
> Now I am wondering if actually the code making any queue with
> keep-alive value as true. Can't find any place to find this. Do
> you know any way to get it displayed?

TCP socket options are not displayed anywhere. It is possible to retrieve them
with a bit of rabbitmqctl eval magic, I believe this was discussed previously on this list.

> My another question is what is actual usage of $connection_timeout
> in AMQPConnection constructor? Is this related anyhow with
> the lifetime of any connection? if yes, what value to be provided
> to make a connection everlasting.

It is a timeout for initial connection. If TCP connection (or possibly protocol handshake, not familiar
with this specific client) does not succeed in that many seconds,
the client will throw an error.

Using "infinity" for a timeout is not a good idea. This is in no way related to how long
a connection can stay open, with or without any activity on it.

tester...@gmail.com

unread,
Jun 30, 2015, 8:14:27 AM6/30/15
to rabbitm...@googlegroups.com, tester...@gmail.com
Hi Michael,

Its good to have your support once again,

>Using "infinity" for a timeout is not a good idea. This is in no way related to how long
>a connection can stay open, with or without any activity on it.


you almost gave me a relief  with this note. Loads of thanx for that.


Now I am providing you a scenario which will give you an idea of how I am trying to make my consumer alive. I am sending
$connection_timeout = 2,
$read_write_timeout = 60,
$context = null,
$keepalive = true,
$heartbeat = 30,
as parameter while creating queue. Is these enough or I need to possibly send something more to keep the consumer connection everlasting.

Thanx once again in advance :)




Reply all
Reply to author
Forward
0 new messages