Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

check if conx to Net::RabbitMQ is still alive

by perl_help26 (Beadle)
on Jun 22, 2016 at 14:04 UTC ( [id://1166263]=perlquestion: print w/replies, xml ) Need Help??

perl_help26 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have a rabbitmq server running on an external server node. My problem is that if I don't communicate with the rabbitmq server for a certain amount of time, the server will kill the connexion which will kill my perl script. Is there a method to know if the timeout has been reached (when requesting something from the rabbitmq) or a flag like 'is_connected'? That way I could reconnect everytime this happens.

Also, if i set a param value for heartbeat for example heartbeat=>60, will this ping the server every 30 seconds and will my problem be solved? Thanks
my $res = $rabbit_mq->publish(1, "my_exchange.lookup", $bin, {exchang +e=>'my_exchange'}, {reply_to => $rabbit_mq->{replyQ},}); #####in here if timeout has been reached reconnect #####or if the cnx is dead reconnect $res = $rabbit_mq->recv();

Replies are listed 'Best First'.
Re: check if conx to Net::RabbitMQ is still alive
by GotToBTru (Prior) on Jun 22, 2016 at 14:33 UTC

    It looks to me like the heartbeat parameter will determine how often you need to send a heartbeat frame; it's up to you to make sure that happens. I don't see that there is a way to get the server to tell you it's about to disconnect. You need to store somewhere in your program the last time you interacted with the server.

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

      So I need to say somewhere in my code : if X amount of time has passed $rabbitmq->heartbeat() ? is this what you mean ? Or setting the param will do this by itself?

        Yes. It will not automatically send the heartbeat. The RabbitMQ documentation indicates that heartbeating is intended to allow for quicker detection of a lost connection. Any activity on the connection counts as a heartbeat; you only need to send an explicit beat if nothing else is happening.

        But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1166263]
Approved by Corion
Front-paged by GotToBTru
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-24 22:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found