Connection Pooling in Java application for interacting with WebsphereMQ

S

Sanjeev

I have following infrastruture at my site.

1> Machine #1 has below
- Websphere MQSeries 6.0 (client setup - Slim Client)
- OS = Windows 2003
- i/p address : 10.1.11.10
- Tomcat web server 5.5
- No Websphere Application Server.

2> Machine #2 has below
- Websphere MQSeries 6.0 (Server setup)
- OS = Windows 2003
- i/p address : 10.1.11.21
- Queue Manager Name : qMngr
- Queue Name (client will put the message) : toServerQ
- Queue Name (client will get the message) : fromServerQ

- I have developed the web application in Tomcat web server 5.5 using
MQ base classes for accessing the Websphere MQ.
- Since it is web application there can be atleast 25 request at
time.
i.e. when client#1 request data from queue he must get data related
to client#1 only not other than client#1.
- For accessing the websphere MQ, I am using websphere MQ base classes
in Client mode. (Not JMS)

==>>>> Source Code as follows

Class MQInterface (Servlet) is used for getting the web request from
user and reply the response in html format.
------------------------------------------------------------------------------------------------------

public class MQInterface extends HttpServlet {

protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String Output = "";
System.out.println("!! Entered into Banking Servlet !!");
String requestParam = request.getParameter("OPRN_CODE");

if (requestParam.equalsIgnoreCase("GET_NAME_DETAIL")){

String id = request.getParameter("id");
Output = MQDataObject().getNameDetail(id);

return Output;
}
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(Output);
}

Class MQDataObject is used for getting and putting data(message) into
Websphere MQ.
------------------------------------------------------------------------------------------------------

public class MQDataObject {
private String hostname = "10.1.11.21";
private String channel = "Chnl1";
private String qManager = "qMngr1";
private MQQueueManager qMgr;
private ISISSSLAdaptor ssl;
private ISISConfigHelper ConfigHelper;
private String Output;

public MQDataObject(){
MQEnvironment.hostname = hostname;
MQEnvironment.channel = channel;

MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES_CLIENT);
MQEnvironment.sslCipherSuite =
"SSL_RER_WERH_3KIUD_EQW_CRT_SSA";

try{
ssl = new DEMOSSLAdaptor("DEMOSSLAdaptor.config");
ConfigHelper = new
ISISConfigHelper("MQConnection.config");
}catch(Exception exception){
System.out.println("Exception Details => " + exception);
}
}
public String getNameDetail(String sendMessage){
....
....

MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES_CLIENT);

String msgText = "";
try
{
....
....

// Create a connection to the Queue Manager.
qMgr = new MQQueueManager(qManager);

// Set up the options on the queue we wish to open
int openOutOptions = MQC.MQOO_OUTPUT;

// Specify the queue to open and open option
MQQueue sendingQueue =
qMgr.accessQueue("toServerQ",openOutOptions,null,null,null);

// Define the MQ message and write some text in UTF
format
MQMessage sendingMessage = new MQMessage();
sendingMessage.writeUTF(sendMessage);

// Specify the message options..
MQPutMessageOptions pmo = new MQPutMessageOptions();

// Put message on the queue
sendingQueue.put(sendingMessage,pmo);

// Close Sending Queue
sendingQueue.close();

// Receiving the message back

// Wait for 5 seconds to get reply from receiving queue
Thread.sleep(5000);

// Set up the options on receiving queue we wish to open
int openInOptions = MQC.MQOO_INPUT_AS_Q_DEF |
MQC.MQOO_OUTPUT;
MQQueue receivingQueue =
qMgr.accessQueue("fromServerQ",openInOptions,null,null,null);

MQMessage receivingMessage = new MQMessage();

// Set and Get the message options
MQGetMessageOptions gmo = new MQGetMessageOptions();

// Receiving the message off the queue.
receivingQueue.get(receivingMessage,gmo);

// Get the message from the receiving queue.
msgText =
receivingMessage.readStringOfByteLength(receivingMessage.getMessageLength());

// Close Receiving Queue
receivingQueue.close();

// Close a connection to the Queue Manager.
qMgr.disconnect();

// Parse the received message using parser.
String output = new IFXXMLParser().runExample(msgText);

}
catch (MQException mqex){
System.out.println("MQ Error : " + mqex);
}
catch (Exception ex){
System.out.println("General Error : " + ex);
}
return Output;
}
}

The message for sending the receiving is in XML format.

Could any one help me following in questions.

1> Since there is 30 request at time so for improve the performance
and resources I need to do connection pooling.
How can I achieve this using base classes.
2> While retrieving (getting) the message for particular request how
can I identify the response message.
i.e. when client#1 request data from queue he must get data related
to client#1 only not other than client#1.
because In above scenario there are separate queues for getting the
message and putting the message.

I have read the tutorial on connection pulling but I am little
confused.


Thanking in Advance
Sanjeev
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top