|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Java client reading DLQ |
« View previous topic :: View next topic » |
Author |
Message
|
mqdude70 |
Posted: Thu Nov 13, 2003 10:11 am Post subject: Java client reading DLQ |
|
|
 Apprentice
Joined: 13 Nov 2003 Posts: 28
|
Hi,
I need to browse the messages in the dead letter queue using a java app in from one solaris box messages are created in another solaris box. Any inputs will be appreciated. _________________ Thanks,
-MQdude70 |
|
Back to top |
|
 |
lash |
Posted: Thu Nov 13, 2003 10:58 am Post subject: |
|
|
 Apprentice
Joined: 14 May 2003 Posts: 47
|
use dead letter queue handler, by this u can browse the dead letter queue.
cheers |
|
Back to top |
|
 |
bower5932 |
Posted: Thu Nov 13, 2003 11:06 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
Check out the runmqdlq command in the System Administration Guide. |
|
Back to top |
|
 |
clindsey |
Posted: Thu Nov 13, 2003 1:45 pm Post subject: |
|
|
Knight
Joined: 12 Jul 2002 Posts: 586 Location: Dallas, Tx
|
If you really need a java app, give this a try. It will show the msgid, correlId, destination q, destinatin qm, and reason code. You can start with this and add more function if you need it.
Charlie
Code: |
import java.lang.*;
import java.io.*;
import com.ibm.mq.*;
public class ShowDLQ {
private static String myQmgr = null;
private static String myQueue = null;
private static String myHostname = null;
private String myChannel = "SYSTEM.DEF.SVRCONN";
private int myPort = 1414;
public ShowDLQ() {
}
/**********************************************************************/
/* Constructor to read command line arguments (if they were supplied) */
/* Syntax: java ShowDLQ -q DLQname -qm QMGRName
/**********************************************************************/
public ShowDLQ(String[] args) {
this(); /* call the default constructor */
/**********************************/
/* Get the command-line arguments */
/**********************************/
for ( int i=0; i<args.length; i++ ) {
String arg = args[i].toLowerCase();
if ( arg.equals("-qm") ) {
if ( i+1<args.length ) {
myQmgr = args[++i];
}
else {
System.out.println("didn't specify qmgr, exiting");
return;
}
}
else if ( arg.equals("-q") ) {
if ( i+1<args.length ) {
myQueue = args[++i];
}
else {
System.out.println("didn't specify queue, exiting");
return;
}
}
else if ( arg.equals("-h") ) {
if ( i+1<args.length ) {
myHostname = args[++i];
}
}
else if ( arg.equals("-c") ) {
if ( i+1<args.length ) {
myChannel = args[++i];
}
}
else if ( arg.equals("-p") ) {
if ( i+1<args.length ) {
myPort = Integer.parseInt(args[++i]);
}
}
else {
System.out.println( "Unknown argument: " + arg );
}
}
if (myHostname != null) {
MQEnvironment.hostname = myHostname;
MQEnvironment.channel = myChannel;
MQEnvironment.port = myPort;
}
System.out.println("Qmgr : " + myQmgr);
System.out.println("Queue : " + myQueue);
System.out.println("Hostname: " + myHostname);
System.out.println("Channel : " + myChannel);
System.out.println("Port : " + myPort);
}
/********************************************************/
/* This method does the actually browsing of the queue. */
/********************************************************/
public void myDLQHandler() {
MQQueueManager qMgr = null;
MQQueue browseQueue = null;
int j = 0; /* used as a message counter */
System.out.println("\nShowDLQ.java - starts here");
System.out.println("**************************");
MQException.log = null; /* don't print out any exceptions */
try {
/*****************************/
/* Create a queue manager */
/*****************************/
qMgr = new MQQueueManager(myQmgr);
/****************************************/
/* Open the queue in browse mode. */
/****************************************/
int openOptions = MQC.MQOO_BROWSE;
browseQueue = qMgr.accessQueue(myQueue, openOptions, null, null, null);
System.out.println("\n OPEN - '" + myQueue + "'\n\n");
/*****************************************************************/
/* Loop through the queue browsing the messages that are on it. */
/*****************************************************************/
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = gmo.options + MQC.MQGMO_BROWSE_NEXT;
MQMessage myMessage = new MQMessage();
while (true) {
myMessage.clearMessage();
myMessage.correlationId = MQC.MQCI_NONE;
myMessage.messageId = MQC.MQMI_NONE;
browseQueue.get(myMessage, gmo);
j = j + 1;
System.out.println(" GET of message number " + j);
System.out.print(" MsgId : ");
dumpHexId(myMessage.messageId);
System.out.print(" CorrelId : ");
dumpHexId(myMessage.correlationId);
/**************************************************************/
/* Start extracting parts of the MQDLH message */
/* */
/**************************************************************/
myMessage.readString(4); // read the struct id
myMessage.readInt(); // read the version
int reason = myMessage.readInt();
System.out.println(" Reason Code: " + reason);
String destQ = myMessage.readString(48);
String destQm = myMessage.readString(48);
System.out.println(" Destination Queue Name: " + destQ);
System.out.println(" Destination Queue Mgr: " + destQm);
System.out.println("\n");
}
}
catch (MQException ex) {
if (ex.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE) {
System.out.println(" No more messages");
}
else {
System.out.println("MQ error: Completion code " +
ex.completionCode + " Reason code " + ex.reasonCode);
}
}
catch (java.io.IOException ex) {
System.out.println("An IO error occurred: " + ex);
}
try {
browseQueue.close();
System.out.println(" CLOSE of queue");
qMgr.disconnect();
System.out.println(" DISCONNECT from queue manager");
}
catch (MQException ex) {
System.out.println("MQ error: Completion code " +
ex.completionCode + " Reason code " + ex.reasonCode);
}
System.out.println("**************************");
System.out.println("ShowDLQ.java finished");
}
/****************************************************/
/* Some of the MQ Ids are actually byte strings and */
/* need to be dumped in hex format. */
/****************************************************/
static void dumpHexId(byte[] myId) {
System.out.print("X'");
for (int i=0; i < myId.length; i++) {
char b = (char)(myId[i] & 0xFF);
if (b < 0x10) {
System.out.print("0");
}
System.out.print((String)(Integer.toHexString(b)).toUpperCase());
}
System.out.println("'");
}
/****************************/
/* main program entry point */
/****************************/
public static void main( String[] args ) {
ShowDLQ dlq = new ShowDLQ(args);
/******************************************/
/* Check that all arguments were entered. */
/******************************************/
if ( (myQmgr==null)
|| (myQueue==null) ) {
System.out.println("Usage:");
System.out.println("java ShowDLQ -qm QMGR -q DLQ <-h HOSTNAME -c CHANNEL -p PORT>");
System.out.println("where -QMGR is the queue manager name");
System.out.println(" -DLQ is the dead letter queue name");
System.out.println(" -HOSTNAME (optional) is the hostname");
System.out.println(" -CHANNEL (optional) is the svrconn channel");
System.out.println(" -PORT (optional) is the listener port");
}
else {
dlq.myDLQHandler();
}
}
}
|
Last edited by clindsey on Fri Nov 14, 2003 9:04 am; edited 1 time in total |
|
Back to top |
|
 |
mqdude70 |
Posted: Fri Nov 14, 2003 8:09 am Post subject: |
|
|
 Apprentice
Joined: 13 Nov 2003 Posts: 28
|
Thanks Guys! _________________ Thanks,
-MQdude70 |
|
Back to top |
|
 |
RogerLacroix |
Posted: Sun Nov 16, 2003 10:06 pm Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
|
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
|
|
|
|