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 » [SOLVED]Connection to QueueManager

Post new topic  Reply to topic
 [SOLVED]Connection to QueueManager « View previous topic :: View next topic » 
Author Message
scar
PostPosted: Tue Apr 27, 2010 5:46 am    Post subject: [SOLVED]Connection to QueueManager Reply with quote

Centurion

Joined: 23 Jun 2004
Posts: 145

Env : MQ V6, AIX 5.3,java 1.4

We need to process the messages as soon as we receive them, and we will get a message every 10min or so.

We have a triggered process to kick a java program to pick up the message as soon as it arrives on the queue.

My question is how to keep the connection to the queue manager open with out closing the queues for a long time, instead of connecting to the QMGR and opening the queue when ever a message is put on the queue.

Any help is appreciated.

Thanks.


Last edited by scar on Thu Apr 29, 2010 6:48 am; edited 1 time in total
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Apr 27, 2010 7:48 am    Post subject: Re: Connection to QueueManager Reply with quote

Grand High Poobah

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

scar wrote:
Env : MQ V6, AIX 5.3,java 1.4

We need to process the messages as soon as we receive them, and we will get a message every 10min or so.

We have a triggered process to kick a java program to pick up the message as soon as it arrives on the queue.

My question is how to keep the connection to the queue manager open with out closing the queues for a long time, instead of connecting to the QMGR and opening the queue when ever a message is put on the queue.

Any help is appreciated.

Thanks.


Look at the JMS model with a MessageListener (MDB type).
Or run a loop with MQGET with wait....

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
scar
PostPosted: Wed Apr 28, 2010 12:10 pm    Post subject: Reply with quote

Centurion

Joined: 23 Jun 2004
Posts: 145

I am using a while loop.

after processing the first message its not picking up the next messages.
this is what the code does:
read message
call storeprocedure
get response
write the response to outbound queue.

its giving the following exception

MQJE001: Completion Code 2, Reason 2033
com.ibm.mq.MQException: MQJE001: Completion Code 2, Reason 2033
at com.ibm.mq.MQQueue.get(MQQueue.java:1041)
at LSTP_Receit.main(LSTP_Receit.java:136)


But there are a bunch of messges in the Queue.

Plese see the code below

try
{

System.out.println("************ Start Processing "+new java.util.Date().toString()+"**********");
//Connection to the QMGR
mqQMGR = getQMGRConnection(strQMGR);
System.out.println("mqQMGR.toStrings = "+mqQMGR.toString());
//Open the INBOUND Queue
mqInbounbQueue = openQueue(strInbounbQueue ,mqQMGR);
// Open the BACKOUT Queue
mqBackoutQueue = openQueueforWriting(strBackoutQueue ,mqQMGR);
//Open the OUTBOUND Queue
mqOutboundQueue = openQueueforWriting(strOutboundQueue ,mqQMGR);
// Set up an MQ options object. Specify syncpoint to allow backout
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_SYNCPOINT;
// Same as MQGMO_DEFAULT
gmo.waitInterval = INITQ_WAIT_INTERVAL;
//get database connection
Class.forName(dbDriver);
dbCon = createdbConnection(dbConnectString,dbUser,dbPwd);
// Pull the message off the queue.
String strMsg = "";
while(mqInbounbQueue.getCurrentDepth() > 0)
{
try
{
System.out.println("Number of Messages = "+mqInbounbQueue.getCurrentDepth());
System.out.println("Getting the Message");
try
{
mqInbounbQueue.get(retrievedMessage, gmo);
}
catch(Exception e)
{
e.printStackTrace();
}
System.out.println("Got the Message");
int intBckOutCount = retrievedMessage.backoutCount;
if(intBckOutCount > 1)
{
System.out.println("Write the message to the backout queue");
WritetoQueue(mqBackoutQueue,mqQMGR,retrievedMessage);
}
else
{
System.out.println("Process the message");
strCorrelID = retrievedMessage.correlationId.toString();
strMsg =retrievedMessage.readString(retrievedMessage.getMessageLength());
System.out.println("Message = "+strMsg);
StringReader reader1 = new StringReader(strMsg);
String output1=null;
Reader reader=null;
String esbReq = "ias_esb_request";
proc_stmt = dbCon.prepareCall("{ call ias_xml_example(?,?,?) }");
proc_stmt.setCharacterStream(1,reader1, strMsg.length());
proc_stmt.setString(2,esbReq);
proc_stmt.registerOutParameter(3, OracleTypes.VARCHAR);
rs = proc_stmt.executeQuery();
output1 = proc_stmt.getString(3);
System.out.println(proc_stmt.getString(3) );
//format the response
outboundMessage.writeString(output1);
//write to outbound queue
WritetoQueue(mqOutboundQueue,mqQMGR,outboundMessage);
}
}
catch(Exception exe)
{
exe.printStackTrace();
//Write Message to Backout Queue and commit
try{WritetoQueue(mqBackoutQueue,mqQMGR,retrievedMessage);}catch(Exception ex){ex.printStackTrace();}
try{mqQMGR.commit();}catch(Exception ex){ex.printStackTrace();}
}
}

// Now Commit message to MQSeries Queue.
mqQMGR.commit();
dbCon.commit();
//Close the Queues
mqInbounbQueue.close();
mqOutboundQueue.close();
mqBackoutQueue.close();
//Disconnect from the queue manager
mqQMGR.disconnect();
try{dbCon.commit();dbCon.close();}catch(Exception Ex){Ex.printStackTrace();}

}
catch(Exception e)
{
e.printStackTrace();
//Write Message to Backout Queue
//try{WritetoQueue(mqBackoutQueue,mqQMGR,retrievedMessage);}catch(Exception ex){ex.printStackTrace();}
try{mqQMGR.commit();}catch(Exception ex){ex.printStackTrace();}
//try{mqBackoutQueue.close();}catch(Exception ex){ex.printStackTrace();}
//Close the Queue s
try{mqInbounbQueue.close();}catch(Exception ex){ex.printStackTrace();}
try{mqOutboundQueue.close();}catch(Exception ex){ex.printStackTrace();}
try{mqBackoutQueue.close();}catch(Exception ex){ex.printStackTrace();}
//Disconnect from the queue manager
try{mqQMGR.disconnect();}catch(Exception ex){ex.printStackTrace();}
//Close the database connection
try{dbCon.close();}catch(Exception Ex){Ex.printStackTrace();}

}
}

///////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////

public static MQQueueManager getQMGRConnection(String strQueueManager)
{
final int INITQ_WAIT_INTERVAL = 120000; // 2 minutes.
// Create a connection to the queue manager
MQQueueManager mqQueueManager = null;
MQEnvironment.hostname = "xxxxxxxxxxxxxx";
MQEnvironment.port = 1414;
MQEnvironment.channel = "SYSTEM.DEF.SVRCONN";
try
{
System.out.println("Creating QMGR Object");
mqQueueManager = new MQQueueManager(strQueueManager);
System.out.println("Done Creating QMGR Object");
}
catch (MQException mqex)
{
mqex.printStackTrace();
System.out.println("**************************");
}
return mqQueueManager;
}
public static MQQueue openQueue(String strInputQueue ,MQQueueManager mqQueueManager)
{
//int openInputOptions = MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_INQUIRE + MQC.MQOO_SET;
int openInputOptions = MQC.MQOO_INPUT_AS_Q_DEF
+ MQC.MQOO_INQUIRE
+ MQC.MQOO_OUTPUT
+ MQC.MQOO_SET;
// Open the input queue.
MQQueue mqInputQueue = null;
try
{
mqInputQueue = mqQueueManager.accessQueue(strInputQueue, openInputOptions,
null, // default q manager
null, // no dynamic q name
null); // no alternate user id
}
catch (MQException mqex)
{
mqex.printStackTrace();
}
return mqInputQueue;
}
public static MQQueue openQueueforWriting(String strInputQueue ,MQQueueManager mqQueueManager) throws Exception
{
int openInputOptions = MQC.MQOO_OUTPUT | MQC.MQOO_SET_IDENTITY_CONTEXT;

// Open the input queue.
MQQueue mqInputQueue = null;
try
{
mqInputQueue = mqQueueManager.accessQueue(strInputQueue, openInputOptions,
null, // default q manager
null, // no dynamic q name
null); // no alternate user id
}
catch (MQException mqex)
{
mqex.printStackTrace();
throw mqex;
}
return mqInputQueue;
}

public static boolean WritetoQueue(MQQueue mqqueue,MQQueueManager QMGR,MQMessage retrievedMessage) throws Exception
{
try
{
System.out.println("Writin to Queue");
retrievedMessage.backoutCount=0;
retrievedMessage.putApplicationName="LSTP_Receit";
retrievedMessage.userId="LSTP_ADMIN";
// Specify the message options; Accept the defaults; same as MQPMO_DEFAULT
MQPutMessageOptions pmo = new MQPutMessageOptions();
pmo.options = MQC.MQPMO_SET_IDENTITY_CONTEXT;
// Put the message on the queue
mqqueue.put(retrievedMessage, pmo);
// Close the queue...
//mqqueue.close();
}
catch(Exception e)
{
throw e;
}
return true;
}

}
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Apr 28, 2010 12:47 pm    Post subject: Reply with quote

Grand High Poobah

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

Before processing the MQGET in each iteration of the loop you must reset the values in the MQMD for messageId and correlationId. Use the constants MQC.MQID_NONE and MQC.MQCI_NONE.

The response you get is correct. The system tries to get the second message with messageId and correlId and returns no messages matching...

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
scar
PostPosted: Thu Apr 29, 2010 5:33 am    Post subject: Reply with quote

Centurion

Joined: 23 Jun 2004
Posts: 145

Its Working. Thanks a lot.
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 » [SOLVED]Connection to 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.