Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Stomp time out error

by magarwal (Novice)
on Jun 23, 2010 at 21:26 UTC ( #846180=perlquestion: print w/replies, xml ) Need Help??
magarwal has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,
I am trying to create a activemq producer, which will keep on sending requests after a certain interval of time. I am creating the stomp object as,
my $stmp = Net::Stomp->new( { hostname => $broker, port => 61613} );
After waiting fro some time(120 min), I ma trying to connect it to the broker as  $stmp->connect(); . At the connect, following error is thrown,
Error reading command: Connection timed out at /usr/local/lib/perl5/si +te_perl/5.10.0/Net/Stomp/ line 37.
. If I do connect without waiting, it works fine.
Please let me know if there is some other parameter that I need to set for stomp, or if this is the expected behaviour.

Replies are listed 'Best First'.
Re: Stomp time out error
by Khen1950fx (Canon) on Jun 24, 2010 at 00:56 UTC
    You probably don't want to wait for 120 minutes. Use something more reasonable like 5 seconds:
    #!/usr/bin/perl use strict; use warnings; use Net::Stomp; my $stomp = Net::Stomp->new({ hostname => 'localhost', port => '61613' + }); $stomp->connect({ login => 'user', passcode => 'passcode' }); $stomp->subscribe( { destination => '/queue/foo', 'ack' => 'client', 'activemq.prefetchSize' => 1 } ); my $frame = $stomp->receive_frame; warn $frame->body; my $can_read = $stomp->can_read({ timeout => 5 }); $stomp->ack({ frame => $frame }); $stomp->disconnect;
      Thanks for your reply.

      My issue is that, I want to keep my programming running, infinitely and only at intervals of 120 min., it should send the message. So, I need someway to send message after every 120 min. or more, without time out.

      Please let me know your inputs.

Re: Stomp time out error
by Old_Gray_Bear (Bishop) on Jun 24, 2010 at 13:52 UTC
    When I see "Connection timed out", my first thought is that the TCP socket has been closed on the Server side due to lack of traffic. I often see Apache servers routinely configured to close unused sockets after a period of inactivity (usually 300 seconds, but that just may be the default. It is a configuration parameter). That is what I suspect is occurring here.

    The solution is to sent periodic "keep-alive" messages to your server. This will reset the inactive-socket timer and keep your connection established while you wait for your 120 minutes to pass. You will have to talk to the Server SysAdmin to find out what the appropriate interval is and possibly include code on the Server side to handle the "keep-alive" messages.

    A more resource friendly solution would be to establish your connection, send your MQ message and process the reply; then close the connection before you go to sleep for 120 minutes. Repeat the connect/send-receive/disconnect sequence when you wake up.

    I Go Back to Sleep, Now.


      I tried to check for connection time out, but it looks fine.In the below code, even after waiting for 120 min., its printing the "connection defined", but when it comes to $stmp-> connect(); I get the same error.
      if(defined($stmp->socket->connected)){ print "\nconnection defined\n"; } $stmp->connect();

      So, can socket time out be the only reason. How can I set that up.
      I dont want to send the keep alive message as it may increase the traffic at peak times.

      Please let me know your inputs.

Re: Stomp time out error
by andreas1234567 (Vicar) on Jun 24, 2010 at 20:11 UTC
    If there is a router between the two end-points you might suffer from it disconnecting apparently idle connections.
    No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://846180]
Approved by sweetblood
[jedikaiti]: 'ello
[1nickt]: Bah, still does not work under Perlbrew

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2017-10-18 15:51 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (249 votes). Check out past polls.