Author |
Message
|
rbreault |
Posted: Wed Feb 14, 2007 10:52 am Post subject: message get |
|
|
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 |
|
 |
jefflowrey |
Posted: Wed Feb 14, 2007 11:08 am Post subject: |
|
|
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 |
|
 |
rbreault |
Posted: Wed Feb 14, 2007 11:27 am Post subject: |
|
|
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 |
|
 |
jefflowrey |
Posted: Wed Feb 14, 2007 12:02 pm Post subject: |
|
|
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 |
|
 |
rbreault |
Posted: Wed Feb 14, 2007 1:46 pm Post subject: |
|
|
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 |
|
 |
jefflowrey |
Posted: Wed Feb 14, 2007 2:02 pm Post subject: |
|
|
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 |
|
 |
rbreault |
Posted: Wed Feb 14, 2007 2:57 pm Post subject: |
|
|
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 |
|
 |
jefflowrey |
Posted: Wed Feb 14, 2007 3:36 pm Post subject: |
|
|
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 |
|
 |
jefflowrey |
Posted: Thu Feb 15, 2007 8:51 am Post subject: |
|
|
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 |
|
 |
rbreault |
Posted: Thu Feb 15, 2007 9:03 am Post subject: |
|
|
Novice
Joined: 23 Jan 2007 Posts: 21
|
Thanks a ton for the information |
|
Back to top |
|
 |
|