ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » message get

Post new topic  Reply to topic
 message get « View previous topic :: View next topic » 
Author Message
rbreault
PostPosted: Wed Feb 14, 2007 10:52 am    Post subject: message get Reply with quote

Novice

Joined: 23 Jan 2007
Posts: 21

I am trying to get messages off a queue which I can do just fine with the following code. I want to seperate these messages before I write them to a files how would I do that here is my code when I look at the console I see them all.



package com.arkona.mq.client;

import com.ibm.mq.*;

public class MQClntPut {

public static void main(final String args[]) {

final int openOptions = MQC.MQOO_INPUT_SHARED;

final String qsystemName = "arkdev";
final String queueManagerName = "ARKDEV.QUEUE.MANAGER";
final String queueName = "ROB.IN.QUEUE";



MQEnvironment.hostname = (qsystemName);
MQEnvironment.channel = ("SYSTEM.ADMIN.SVRCONN");
MQEnvironment.port = 1414;

MQEnvironment.disableTracing ();
MQException.log = null;

MQQueueManager qMgr = null;

try {
qMgr = new MQQueueManager(queueManagerName);
} catch (MQException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println();

MQQueue inputQueue = null;
try {
inputQueue = qMgr.accessQueue(queueName, openOptions, null, null,
null);
} catch (MQException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("MQ Open Occurred");

final MQMessage msgData = new MQMessage();
final MQGetMessageOptions gmo = new MQGetMessageOptions();

gmo.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_SYNCPOINT;
gmo.waitInterval = 15000;

boolean Done = false;
while (!Done) {
try {
msgData.messageId = MQC.MQMI_NONE;
msgData.correlationId = MQC.MQCI_NONE;
inputQueue.get(msgData, gmo);
System.out.println("MQ Get Occurred");


final int totalMsgLength = msgData.getTotalMessageLength();
System.out.println("Total Message Length: " + totalMsgLength);

final byte[] strData = new byte[totalMsgLength];
msgData.readFully(strData, 0, totalMsgLength);
System.out.println("Message Read: " + new String(strData));
qMgr.commit();
} catch (final MQException ex) {
System.out.println("MQ Queue Empty");
Done = true;
try {
qMgr.backout();
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (final java.io.IOException ex) {
System.out.println("An error occurred while "
+ "writing the message buffer " + ex);
Done = true;
try {
qMgr.backout();
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
try {
inputQueue.close();
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("MQ Close occurred");
try {
qMgr.disconnect();
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("MQ Disconnect occurred");

System.exit(0);
}
}
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Feb 14, 2007 11:08 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

By changing your code to separate them based on the meaningful divisions between them.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
rbreault
PostPosted: Wed Feb 14, 2007 11:27 am    Post subject: Reply with quote

Novice

Joined: 23 Jan 2007
Posts: 21

ok I am very new to this. I am a System Admin that has been thrown in to get this done. I will explain a bit more what I am trying to do. I would like to use the MQ java client on iSeries / AS400 to get message off a queue and write them to a datafile. I would just like a example or two on how to do this. just little bits of code help greatly as I am very new to java. Any help or just point me to a web-site with a sample or two would be great.

Thanks
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Feb 14, 2007 12:02 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

The code you posted above appears to do what you want.

It's not clear what you need it to do that's different than what it already does.

You might look at the Perl API for MQ - most system administrators are more familiar with Perl programming than Java. It's available through CPAN in the package MQSeries.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
rbreault
PostPosted: Wed Feb 14, 2007 1:46 pm    Post subject: Reply with quote

Novice

Joined: 23 Jan 2007
Posts: 21

Here is the output from my program its great but I am needing just a couple things

MQ Open Occurred
MQ Get Occurred
Total Message Length: 414
<?xml version="1.0" encoding="UTF-8"?>

<!ELEMENT addrPhone EMPTY>
<!ATTLIST addrPhone addr1 CDATA #REQUIRED
addr2 CDATA #IMPLIED
city CDATA #REQUIRED
stateProv CDATA #REQUIRED
postalCd CDATA #REQUIRED
country CDATA #IMPLIED
phone CDATA #IMPLIED
otherPhone1 CDATA #IMPLIED
otherPhone2 CDATA #IMPLIED>
MQ Get Occurred
Total Message Length: 293
<?xml version="1.0" encoding="UTF-8"?>

<!ELEMENT cairInfo (cair*)>

<!ELEMENT cair (open, reason)>
<!ATTLIST cair owner CDATA #REQUIRED
number CDATA #REQUIRED>

<!ELEMENT open (date)>
<!ELEMENT reason (desc, narrative)>
<!ELEMENT desc (#PCDATA)>
<!ELEMENT narrative (#PCDATA)>

MQ Queue Empty
MQ Close occurred
MQ Disconnect occurred


So as you can I get messages off the queue. What I want or need to do is write each message as an seperate message to a iSeries IFS file or and perferriable a data file with record access.

I wouold really love to just get 1 message at a time no matter how many are on the queue

Thanks
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Feb 14, 2007 2:02 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Your code *does* get one message at a time, regardless of how many are on the queue. MQ *always* only lets you get one message at a time.

Code:

while (!Done) {
try {
...
 catch (final MQException ex) {
System.out.println("MQ Queue Empty");
Done = true;

That's your main loop, that will get each message and do stuff to it.

Everything else you want to do, you need to do by changing where the printlns are written.

See the Java Tutorial on Basic I/O for more help.

http://java.sun.com/docs/books/tutorial/essential/io/index.html
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
rbreault
PostPosted: Wed Feb 14, 2007 2:57 pm    Post subject: Reply with quote

Novice

Joined: 23 Jan 2007
Posts: 21

ok I will admit I shouldn't be the one writing this code as its like I am bind. But after reading that link and trying to figure out how to get that stream of bytes I have to a file I am ready to give in. Any help more help would be great. I am sure its something easy for everyone but me at this point
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Feb 14, 2007 3:36 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

If your shell script is better than your Java, then just get rid of that While loop.

Then the program will only read the first message on the queue, and write to stdout.

Your shell script can then run it for some number of times, perhaps until it exits with an exception instead of completing successfully.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Feb 15, 2007 8:51 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Also, you can look at the sample program amqsbcg.

Or the Support Pack MA01, which has the Q utility.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
rbreault
PostPosted: Thu Feb 15, 2007 9:03 am    Post subject: Reply with quote

Novice

Joined: 23 Jan 2007
Posts: 21

Thanks a ton for the information
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » message get
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.