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 » Unable to get the Depth from Remote QueueManager

Post new topic  Reply to topic
 Unable to get the Depth from Remote QueueManager « View previous topic :: View next topic » 
Author Message
renu_alla
PostPosted: Sun May 21, 2006 6:53 am    Post subject: Unable to get the Depth from Remote QueueManager Reply with quote

Newbie

Joined: 21 May 2006
Posts: 1

Dear All,


I Used the attached program to connect to the Remote QUEUEManager to read the Messages.

THe environment that we are using is

MQ server installed on IBM PSeries Server with Linux OS

MQ Client on Windown Professional

I am running the below program on the windows machine where MQ Client is installed.

when i ran this program on windows machine the queue depth of the QUEUE to which i am connecting to is showing 0
where as when i ran the same program on the Linux machine where MQ server is installed is shows the correct queue depth.

Please guide me what might be the wrong.

Thanks in advance.








/*
* Created on May 21, 2006
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.lmr.ems.fmsreceiver;
import java.io.IOException;
import java.util.Properties;
import com.ibm.mq.MQC;
import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;

/**
* @author 133545
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Receiver {

private static MQQueueManager qMgr= null;
private MQQueue getQueue=null;
private static final String myQueue = "BROKER.FMS.OUTPUT" ; // MQ Out Queue
private static final String errorQueue = "BROKER.ERROR.QUEUE" ; // MQ Error QueueName
private MQQueue browseQueue=null;
// MQConnection Properties
private static final String qMgr1= "WBRK_QM1" ; // MQ QueueManager Name
private static final String channel="BROKER.SVRCON.CHNL"; //SYSTEM.DEF.SVRCONN;
private static final String transport="MQSeries"; // MQ Protocol
private static final int port=1416; // MQ QueueManager port
private static final String hostname ="10.10.11.94"; // MQ Server IP

private final int OpenQtogetOptions =MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_INQUIRE ;
private final int getMessageOptions=MQC.MQGMO_WAIT | MQC.MQGMO_FAIL_IF_QUIESCING | MQC.MQGMO_SYNCPOINT;
private final int OpenQtoBrowseOptions=MQC.MQOO_BROWSE| MQC.MQOO_INQUIRE;
private String strMessage = null;
private String tagValue = null;
//MQ Get Options Object.
MQGetMessageOptions gmo = null;
private final int WAIT_INTERVAL=10000;
private int openOptions = 0;


/**
* Constructoe to initialize the object
*/
public Receiver()throws Exception{
System.out.println("In Construction 1");
gmo = new MQGetMessageOptions();
System.out.println("In Construction 2");
gmo.waitInterval =WAIT_INTERVAL;
System.out.println("In Construction 3");
getMQConnection();
System.out.println("In Construction 4");
// getDBConnection();
System.out.println("In Construction 5");
}


/**
* start method polls on the local queue, gets the message and
* process the message.
* @Param args arguments
* @Return void
*/
public void start()throws Exception {
try{
try{
// open Q to browse
openQToBrowse(myQueue,qMgr1,null,null);
System.out.println("In start() 2");
// fMSInterfaceDAO = new FMSInterfaceDAO(conn);
System.out.println("In start() 3");
// parser = new ParseResponse();
System.out.println("In start() 4");

}catch(MQException me){
me.printStackTrace();
}catch (IOException ie){
ie.printStackTrace();

}
while(true){
System.out.println("IN While True ");
try{

while(browseQueue.getCurrentDepth() > 0){
System.out.println("IN get Queue Depth ");
strMessage = getMessageFromQ();
System.out.println("Message from Queue is ==>" + strMessage);
qMgr.commit();
}//end of while
System.out.print(".");
Thread.sleep(2000);
}catch(MQException me){
me.printStackTrace();
qMgr.backout();
}finally{
// fMSInterfaceDAO.reInitializeDTO();

}
}//end of outer while
}//End of outer Try Stmt
catch(Exception ex){
ex.printStackTrace();
throw ex;
} finally{
MQFinalize();
}
}//End of Start Method

/**
*This Method will get the Message from the Queue
*@Return void
*@throw throws MQException,IOException
*/
private String getMessageFromQ() throws MQException,IOException
{
String strMsg=null;
openQToGet(myQueue,qMgr1,null,null);
try
{
MQMessage getMessage = new MQMessage();
gmo.options=getMessageOptions;
getQueue.get(getMessage, gmo);
int length = getMessage.getMessageLength();
// strMsg = getMessage.readUTF();
strMsg = getMessage.readString(length);

}catch(MQException MQEx)
{
if ((MQEx.completionCode == MQException.MQCC_FAILED)&&(MQEx.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE))
{
}else
throw MQEx;
}
getQueue.close();
return strMsg;
}//End of getMessageFromQ Method.

/**
* start method polls on the local queue, gets the message and
* process the message.
* @Param args arguments
* @Return void
*/

public void openQToBrowse(String queue, String qManager,String dynamicQ,String userId) throws MQException, IOException {

openOptions=OpenQtoBrowseOptions;
System.out.println("OpenQtoBrowseOptions ====> "+OpenQtoBrowseOptions);

browseQueue = qMgr.accessQueue(queue,openOptions,
qManager, // default q manager
dynamicQ, // no dynamic q name
userId); // no alternate user id

System.out.println("OpenQtoBrowseOptions ====> 2");
}//End of openQToBrowse Method.

/**
* start method polls on the local queue, gets the message and
* process the message.
* @Param args arguments
* @Return void
*/

public void openQToGet(String queue, String qManager,String dynamicQ,String userId ) throws MQException, IOException {

openOptions=OpenQtogetOptions;
getQueue = qMgr.accessQueue(queue,openOptions,
qManager, // default q manager
dynamicQ, // no dynamic q name
userId); // no alternate user id

}//End of openQToGet Methos



/**
* start method polls on the local queue, gets the message and
* process the message.
* @Param args arguments
* @Return void
*/

private void getMQConnection()throws MQException,Exception
{
try{
Properties properties = new Properties();
properties.put("hostname", hostname);
properties.put("transport", transport);
properties.put("channel", channel);
properties.put("port", new Integer(port));
System.out.println("In getMQConnection 1");
// qMgr = new MQQueueManager(qMgr1,properties);
qMgr = new MQQueueManager(qMgr1);
System.out.println("In getMQConnection 2");
}catch(NumberFormatException ExNfe){
ExNfe.printStackTrace();
throw ExNfe;
}catch(MQException ExMq){
ExMq.printStackTrace();
throw ExMq;
}catch (Exception Ex){
throw Ex;
}

}//End of getMQConnection Method.


/**
Mehtod:MQFinalize
* This method finalizes all the MQ related objects.
* @ return void
*/
private void MQFinalize()
{
try
{
if(qMgr!= null){
qMgr.disconnect();
qMgr.close();
}
}//try
catch(MQException ignore)
{
ignore.printStackTrace();
//IGNORE THE EXCEPTION
}
}


/**
* @param args
*/
public static void main(String[] args) {
try{
Receiver receiver = new Receiver();
receiver.start();
}catch(Exception ex){
ex.printStackTrace();
}
}






}
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sun May 21, 2006 7:02 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Any application action based on queue depth is a misguided conception of the MQ patterns.

Queue depth contains uncommitted messages, queue depth contains messages that are not in a gettable state.

If you want to process messages on a queue as soon as they hit you will have to either trigger or put a message listener onto the queue.
You should always process until receiving a 2033 (no more messages on queue matching criteria) or until the JMS receive returns a null message.

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Unable to get the Depth from Remote QueueManager
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.