|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
MQSeries/Perl |
« View previous topic :: View next topic » |
Author |
Message
|
mq_nyc |
Posted: Tue Sep 30, 2003 11:24 am Post subject: MQSeries/Perl |
|
|
Newbie
Joined: 30 Sep 2003 Posts: 3
|
I am trying to get my feet wet with the MQSeries Perl Module.
Can anyone help give me a jump start by providing some code to Get/Put messages and also read the queue attributes such as the MaxQLength.
I have read through the Perl/MQ doc's and the sample code on this site but things are still clear as mud.
Thanx in advance. |
|
Back to top |
|
 |
mrlinux |
Posted: Wed Oct 01, 2003 7:10 am Post subject: |
|
|
 Grand Master
Joined: 14 Feb 2002 Posts: 1261 Location: Detroit,MI USA
|
Have you successfully installed the MQSeries modules ???
And how simple a put/get do you want ???
The MQSeries Perl module comes with 2 type of interfaces one closely matches the C API MQCONN/MQPUT/MQGET/MQCLOSE or there is
the objec oriented interface, the OO interface is much simpler.
use MQSeries;
use MQSeries::QueueManager;
use MQSeries::Message;
use MQSeries::Message::IIH;
$qmgr = MQSeries::QueueManager->new
(
QueueManager => ' ', ClientConn =>{ 'ChannelName'=> 'SYSTEM.DEF.SVRCONN','TransportType'=> 'TCP','ConnectionName' => "TC3MSGBK(14140)"}) || die("Unable to connect to queue manager\n");
# QueueManager => ' ', ClientConn =>{ 'ChannelName'=> 'SYSTEM.DEF.SVRCONN','TransportType'=> 'TCP','ConnectionName' => "HOSTSYSB"}) || die("Unable to connect to queue manager\n");
#
# Create a message to be put on a queue going to IMS
#
my $putmsg = MQSeries::Message->new (MsgDesc=>{Format=> MQFMT_IMS});
$PutMsgOpts = {
Options => {MQPMO_SET_IDENTITY_CONTEXT}
};
my $mainMessage = MQSeries::Message::IIH->
new(MsgDesc=>{UserIdentifier=>"mqsiserv",Format=> MQFMT_IMS, ReplyToQ => "AAAAA"},
Header => {
Encoding => MQENC_INTEGER_REVERSED,
StrucId => MQIIH_STRUC_ID,
StrucLength => MQIIH_LENGTH_1,
Format => MQFMT_IMS_VAR_STRING,
Flags => MQIIH_NONE,
LTermOverride => 'MASTER ',
MFSMapName => ' ',
ReplyToFormat => MQFMT_IMS_VAR_STRING,
Authenticator => ' ',
TranInstanceId => MQITII_NONE,
TranState => MQSeries::MQITS_NOT_IN_CONVERSATION,
CommitMode => MQSeries::MQICM_SEND_THEN_COMMIT,
SecurityScope => MQISS_CHECK,
Reserved => ' ',
},
Data => { Transaction => 'HMIQ',
Body => '1111111',
},
);
# $mainMessage = MQSeries::Message::->
# (Header => { MsgDesc =>{Format=> MQFMT_STRING,},
# Authenticator => 'foobar',
# CommitMode => MQSeries::MQICM_COMMIT_THEN_SEND,
# TranState => MQSeries::MQITS_NOT_IN_CONVERSATION,
# },
# Data => { Transaction => 'AUIQ',Body => '1111111',} );
#$qmgr->Put1(PutMsgOpts =>$PutMsgOpts, Message => $mainMessage, Queue => "AAAA",);
$qmgr->Put1(Message => $mainMessage, Queue => "AUTO.BILLING.SUFFIX",);
#$qmgr->Put1(Message => $mainMessage, Queue => "SYSB.IMST.BRIDGE.QUEUE",);
#
# Get a message from an IMS queue
#
#my $queue = MQSeries::Queue->
# new(QueueManager => 'TEST.QM',
# Queue => 'IMS.DATA.QUEUE',
# Mode => 'input');
#my $msg = MQSeries::Message::IIH->new();
#$queue->Get(Message => $msg);
#my $data = $msg->Data();
#print "Have transaction '", $data->{Transaction},
# "' and body '", $data->{Body}, "'\n"; _________________ Jeff
IBM Certified Developer MQSeries
IBM Certified Specialist MQSeries
IBM Certified Solutions Expert MQSeries |
|
Back to top |
|
 |
mq_nyc |
Posted: Wed Oct 01, 2003 9:33 am Post subject: |
|
|
Newbie
Joined: 30 Sep 2003 Posts: 3
|
Thank you for your help Mr Linux.
Actually, my experimentation is very simple.
I have downloaded the MQSeries Win2K client and I am testing with local queues.
I have managed to get/put messages, but I am getting annoyed with the Inquire method of the Queue object. I am trying to get the Max Depth of the queue, but it is complaining that the queue is not open.
From the doc's the new method automagically opens the queue??
Can you point me in the right direction.....
My code
#!/usr/bin/perl
use MQSeries::Queue;
my $queue = MQSeries::Queue->new
(
QueueManager => 'some.queue.manager',
Queue => 'SOME.QUEUE',
Mode => 'input_exclusive',
)
or die("Unable to open queue.\n");
my %qattr = $queue->Inquire( qw(MaxQDepth) );
H:\>perl inquire.pl
MQINQ call failed. CompCode => '2', Reason => '2038'
at inquire.pl line 16
This error msg is translated as:
2038 => "Queue not open for inquire." |
|
Back to top |
|
 |
EddieA |
Posted: Wed Oct 01, 2003 10:07 am Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
If you want to use INQ, then you have to tell that to the Queue when you open it.
For 'normal' MQ, this is MQOO_INQUIRE option in the OPEN Options. You need to find the Perl way of doing this.
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
mrlinux |
Posted: Wed Oct 01, 2003 10:35 am Post subject: |
|
|
 Grand Master
Joined: 14 Feb 2002 Posts: 1261 Location: Detroit,MI USA
|
Well Brandon has this posted on this website
#!/usr/bin/perl
## 07/23/01
## Depth Inquiry sample program.
## Arguments: [Queue Name] [Queue Manager Name]
## Connects to the queue manager specified by the command line,
## if not supplied, it will connect to the default queue manager.
## It then inquires about the queue name passed in, specifically,
## the current depth of that queue. This is displayed to the user.
## This code can easily be modified to display other queue properties.
## Furthermore, MQINQ can be used to inquire about the attributes of
## other objects, not just queues.
##
## Author: Brandon Duncan
## brandon@mqseries.net
## www.mqseries.net
##
use MQSeries;
my $qname = $ARGV[0];
my $qmgrname = $ARGV[1];
my $Hconn = MQCONN($qmgrname, $CompCode, $Reason);
print"MQCONN reason:$Reason\n";
my $ObjDesc = { ObjectType => MQOT_Q, ObjectName => $qname };
my $Options = MQOO_INQUIRE | MQOO_SET | MQOO_FAIL_IF_QUIESCING;
my $Hobj = MQOPEN($Hconn,$ObjDesc,$Options,$CompCode,$Reason);
print"MQOPEN reason:$Reason\n";
my $tst = MQINQ($Hconn,$Hobj,$CompCode,$Reason,MQIA_CURRENT_Q_DEPTH);
print"Depth of $qname is: $tst\n";
MQCLOSE($Hconn,$Hobj,$COptions,$CompCode,$Reason);
print"MQCLOSE reason:$Reason\n";
MQDISC($Hconn,$CompCode,$Reason);
print"MQDISC reason:$Reason\n"; _________________ Jeff
IBM Certified Developer MQSeries
IBM Certified Specialist MQSeries
IBM Certified Solutions Expert MQSeries |
|
Back to top |
|
 |
mq_nyc |
Posted: Wed Oct 01, 2003 1:25 pm Post subject: |
|
|
Newbie
Joined: 30 Sep 2003 Posts: 3
|
The sample script was using the direct access to MQI.... I wanted to achieve the same result using the OO interface...
Anyway after further thought and testing, the code below will be able to list the attributes of a queue.
Thank you for steering me in the right direction...
#!/usr/bin/perl
use MQSeries::Queue;
my $queue = MQSeries::Queue::-> new
(
'QueueManager' => 'some.queue.manager',
'Queue' => 'SOME.QUEUE',
'Options' => MQSeries::MQOO_INQUIRE,
)
or die("Unable to open queue.\n");
%attr = $queue->Inquire(qw(MaxQDepth CurrentQDepth));
foreach $key (keys %attr ) {
print "\t$key => $attr{$key}\n";
}
H:\>perl inq.pl
CurrentQDepth => 3
MaxQDepth => 5000 |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|