ali_kerem has asked for the wisdom of the Perl Monks concerning the following question:
Hello All,
I have a problem about logging in my code ( which is shared below ). My code is reading IBM MQ to get new data each 5 seconds. The code is working but logging is done once in 2 minutes. I mean when I tail the log file, I see it as nothing happens but then, after approximately 2 minutes logs appear as bulk, then stops again. While I'm expecting it to flow, like a normal log file should do, it does bulk printing to log file...
You can check the whole code below, and if there are wrong parts, please make me fix it. Thanks in advance.
#!/usr/bin/perl # IBM Message Queue Reader use warnings; use strict; use Config::Simple; use MQSeries; use MQSeries::Queue; use MQSeries::QueueManager; use XML::Simple; use POSIX; use Time::Local; use Data::Dumper; # Read MQ Settings from config file my $conf = new Config::Simple("/customS/config.ini"); my $qmgr = $conf->param('MQConf.QueueManager'); my $chnl = $conf->param('MQConf.ChannelName'); my $ipad = $conf->param('MQConf.IPAddress'); my $port = $conf->param('MQConf.Port'); my $qnam = $conf->param('MQConf.Queue'); my $xDir = $conf->param('Folder.XMLunread'); my ($queue,$qmgr_obj); while(1) { print "".(localtime)." - Trying to open Queue Manager: $qmgr w +ith Channel: $chnl ...\n"; # Open Queue Manager with defined settings if ( $qmgr_obj = MQSeries::QueueManager->new( QueueManager => $qmgr, ClientConn => { ChannelName => $chnl, TransportType => 'TCP', ConnectionName => "$ipad($port)", MaxMsgLength => 16 * 1024 * 1024 } ) ) { print "".(localtime)." - Queue Manager $qmgr has been +opened succesfully.\n"; } else { print "".(localtime)." - Can't connect to the queue ma +nager, quitting...\n"; } ;; ;; print "".(localtime)." - Trying to open Queue: $qnam...\n"; if ( # Open Queue with defined settings $queue = MQSeries::Queue->new( QueueManager => $qmgr_obj , Queue => $qnam , Mode => 'input' ) ) { print "".(localtime)." - Queue $qnam has been opened s +uccesfully.\n"; } else { print "".(localtime)." - Can't connect to the queue, q +uitting...\n"; } ;; ;; my $c=1; while ( $c==1 ) { my $getmessage = MQSeries::Message->new(); my $dataFromMQ; $queue->Get( Message => $getmessage, # Get Queue's Message +portion Sync => 0, # 0 removes message from queue +, 1 keeps message in queue ); # or warn( # "".(localtime). # "Unable to get message\n" . # "CompCode = " . $queue->CompCode() . "\n" . # "Reason = " . $queue->Reason() . "\n"); if ( defined $getmessage->Data ) { print "".(localtime)." - got a message from MQ +...\n"; ;; # Get current time as Array my @cTimeA = POSIX::strftime("%Y-%m-%dT%H +:%M:%S", gmtime) =~ /(\d+)/g; ;; # Convert Current Time ----Second-----,--- +Minute---,------Hour------,-----Day------,----Month-----,----Year--- print "Current time GMT values; ".$cTimeA[3]." +:".$cTimeA[4].":".$cTimeA[5]." ".$cTimeA[2]."-".$cTimeA[1]."-".$cTime +A[0]."\n"; my $epoch = timelocal($cTimeA[5],$cTimeA +[4],$cTimeA[3],$cTimeA[2],$cTimeA[1]-1,$cTimeA[0]); ;; # Put message time info into array(s) my @qDate= $getmessage->{MsgDesc}->{PutDate}=~ + /(\d{4})(\d\d)(\d\d)/; my @qTime= $getmessage->{MsgDesc}->{PutTime}=~ + /(\d?)(\d\d)(\d\d)(\d\d)(\d\d)$/; ;; # Get epoch time of message ---Second----, +---Minute----,----Hour-----,-----Day-----,----Month----,----Year--- print "Message PutTime GMT values; ".$qTime[1] +.":".$qTime[2].":".$qTime[3]." ".$qDate[2]."-".$qDate[1]."-".$qDate[0 +]."\n"; my $qTimeE = timelocal($qTime[3],$qTime[2],$qT +ime[1],$qDate[2],$qDate[1]-1,$qDate[0]); print "".(localtime)." - epoch time is ".$epoc +h." and mq time is ".$qTimeE."\n"; ;; # Epoch Time minus 1 hour is => $epoch - 3 +600 ;; # If message time is older than 10 minutes + ignore it unless ( $qTimeE <= ($epoch - 600) ) { ;; # Convert Message's Data to XML my $xmlData = XMLin($getmessage->D +ata); my @timeA; # Time Array = $xml +Data->{STO}=~ /(\d+)/g; ;; # Check Time of Flights #if ($xmlData->{AnnouncementCode} eq " +11") #{ @timeA = $xmlData->{ATO}=~ /( +\d+)/g; } #else #{ @timeA = $xmlData->{STO}=~ /(\d+)/g; #} ;; ############ my $timeS = join "", @timeA; # P +ut TimeA Values into String #my $timeE = timelocal($timeA[5], +$timeA[4],$timeA[3],$timeA[2],$timeA[1],$timeA[0]); my $filename = $xmlData->{UniqueID} +.'_'.$xmlData->{AnnouncementCode}.'_'.$timeS.'.xml'; print "filename is ".$filename."\n"; open(FILE,'>',"$xDir/$filename") or di +e "Can't write file '$xDir\/$filename' [$!]\n"; print FILE $getmessage->Data; close(FILE); } else { print "".(localtime)." - message put t +ime is older than 10 minutes...\n"; } } else { if ( $queue->{Reason} == 2033 ) { ;; # Reason 2033 means queue is empty print "".(localtime)." - Message Queue + is empty, checking it again in 5 seconds...\n"; sleep 5; } elsif ( $queue->{Reason} == 2009 ) { print "".(localtime)." - Due to MQ Err +or 2009, connection will be restarted...\n"; sleep 10; } else { print "".(localtime)." - Unable to get + message. Reason is ",$queue->{Reason},", Completion Code is ",$queue +->{CompCode},", re-trying in 5 seconds...\n"; sleep 5; } #$c++; } ;; # End of Inner WHILE Loop } ;; # Wait 5 seconds before retrying... #sleep 5; ;; # End of Infinite WHILE Loop } my $EoF = "End of File";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Late Logging...
by rjt (Curate) on Jul 06, 2013 at 11:39 UTC | |
by ali_kerem (Acolyte) on Jul 06, 2013 at 12:44 UTC | |
|
Re: Late Logging...
by roboticus (Chancellor) on Jul 06, 2013 at 14:10 UTC | |
by ali_kerem (Acolyte) on Jul 09, 2013 at 11:28 UTC | |
by roboticus (Chancellor) on Jul 09, 2013 at 11:36 UTC |