我想阅读SYSTEM.ADMIN.QMGR.EVENT事件消息。我可以收到消息,但输出格式不可读。
这是我用于阅读的PERL子:
sub readEventMessage() {
my $self = shift;
my $qmgr = shift; # the name of the queue manager
my $sourceq = shift;
my $nmessages = shift;
my $count = 0;
my $sourcequeue = MQSeries::Queue->new
(
QueueManager => $qmgr,
Queue => $sourceq,
#Mode => 'input',
Options => MQOO_INPUT_SHARED | MQOO_BROWSE,
)|| die ("Unable to instantiate $qmgr::$sourceq object\n");
while (1)
{
#my $returned_message = MQSeries::Message->new( Data =>"" );
my $returned_message = MQSeries::Message->new(),
#Data => {
# Format => MQEVENT,
#},
GetMsgOpts => {
Options => MQSeries::MQGMO_BROWSE_NEXT | MQSeries::MQGMO_ACCEPT_TRUNCATED_MSG | MQSeries::MQGMO_FAIL_IF_QUIESCING
}
;
my $rc=$sourcequeue->Get( Message => $returned_message);
if ($rc == 1)
{
my $msg_data = $returned_message->Data();
#print "returned EVENT message\t======>\n";
#print Dumper($msg_data);
#print $msg_data."\n";
$count++;
my $msg_header = $returned_message->MsgDesc();
$msg_header->{Data}=$msg_data;
foreach (keys %$msg_header)
{
my $arg = "$_:$msg_header->{$_}";
#
# encode the data
#
$arg=~s/\\/\\\\/g;
$arg=~s/\n/\\n/g;
if ( $arg=~/^\s*$/ )
{
next;
}
print "\n$arg";
}
if ( defined $nmessages )
{
if ( $nmessages < ($count +1))
{
last;
}
}
}
elsif ($rc == -1)
{
my $status="\nNo more messages found on $sourceq\n \n";
last;
}
else
{
my $status="\nError retrieving messages from $sourceq." .
"\nCompCode =" . $sourcequeue->CompCode() .
"\nReason =" . $sourcequeue->Reason() . "\n";
last;
}
}
}
我得到的输出是:
PutTime:12065823 ReplyToQ: GroupId: UserIdentifier: Encoding:546 ApplIdentityData: BackoutCount:0 Format:MQEVENT MsgFlags:0 ApplOriginData: PutApplName:QM_H35299 MsgType:8 MsgSeqNumber:1 CodedCharSetId:850 AccountingToken: Offset:0 CorrelId: ReplyToQMgr:QM_H35299 Persistence:1 PutDate:20120607 OriginalLength:-1 PutApplType:7 Expiry:-1 Version:2 Priority:0 Data: $ ☺ , ☺ ☺ ☺ ☻ ♦ D ▀ 0 QM_H35299 ♥ ► ³♥ ♣
数据格式为MQEVENT,CCSI为850,编码为546。
感谢任何帮助。
答案 0 :(得分:0)
事件消息采用可编程消息格式(PCF)。此格式是链接列表中的一组名称/类型/值三元组。有必要遍历列表以阅读消息。幸运的是,MQSeries Perl Module包含一个MQSeries::Message::Event类来做这件事。各种参数和属性以Perl哈希的形式返回,因此它们很容易枚举或访问它们的值。