use MQSeries qw(:functions);
use MQSeries::QueueManager;
use MQSeries::Queue;
use MQSeries::Message;
use MQSeries::Command;
use Data::Dumper;
#
# Open a queue for input, loop getting messages, updating some
# database with the data.
#
if ( $#ARGV < 4 ){
print "Usage ./get_mq_sessage YWJZZF_CZCB_SEND CHANNEL1 192.168.137.2 5015 CZ_RSP:!
";
exit(-1);
};
my $QueueManager=$ARGV[0];
my $ChannelName=$ARGV[1];
my $ip=$ARGV[2];
my $port=$ARGV[3];
my $QueueName=$ARGV[4];
my $qmgr_obj = MQSeries::QueueManager->new
(
QueueManager => "$QueueManager",
ClientConn => { 'ChannelName' => "$ChannelName",
'TransportType' => 'TCP', # Default
'ConnectionName' => "$ip($port)",
'MaxMsgLength' => 16 * 1024 * 1024,
},
) || die("Unable to connect to queue manager
");
my $queue = MQSeries::Queue->
new(QueueManager => $qmgr_obj,
Queue => "$QueueName",
Mode => 'input',
) or die("Unable to open queue.
");
my $command = MQSeries::Command->new(QueueManager => $qmgr_obj);
my $getmessage = MQSeries::Message->new(Data =>"");
$attr = $command->InquireQueue
(
QName => "$QueueName",
QAttrs => [qw(
OpenInputCount
OpenOutputCount
CurrentQDepth
)],
) or die "InquireQueue: " . MQReasonToText($command->Reason()) . "
";
print "$QueueName 当前队列深度为==";
print $attr->{CurrentQDepth}."
";
$queue->
Get(Message => $getmessage
) or die("Unable to get message
" .
"CompCode = " . $queue->CompCode() . "
" .
"Reason = " . $queue->Reason() . "
");
my $msg_header = $getmessage->MsgDesc();
my $msg_data = $getmessage->Data();
print "MsgSeqNumber====";
print $msg_header->{MsgSeqNumber}."
";
print "第一条消息内容==";
print $msg_data;
print "
";
#print Dumper(%$msg_header);
$qmgr_obj->Close();