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 » Connection Pooling using Base Classes for java

Post new topic  Reply to topic
 Connection Pooling using Base Classes for java « View previous topic :: View next topic » 
Author Message
sanjeev1982
PostPosted: Tue May 27, 2008 11:42 pm    Post subject: Connection Pooling using Base Classes for java Reply with quote

Newbie

Joined: 27 May 2008
Posts: 2

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)


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


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
Back to top
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Wed May 28, 2008 3:00 am    Post subject: Reply with quote

Grand High Poobah

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

sanjeev1982 wrote:
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.

  1. You need to set up your pool as a singleton and as a servlet.
    Remember as well to release the resources on destroy()
  2. You need to implement the request/reply model.
    The reply is usually identified uniquely by its correlationId which is usually the msgId or CorrelationId of the requesting msg.


However in my opinion you'd be better served using a J2EE appserver with JNDI, and an MDB. (better scalability, better pooling etc...)
Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
sanjeev1982
PostPosted: Mon Jun 02, 2008 10:37 pm    Post subject: Reply with quote

Newbie

Joined: 27 May 2008
Posts: 2

Thanks for suggestion.

Could you provide me sample code for Singletone pool.

please find below sample code

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;
}
}
Back to top
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Tue Jun 03, 2008 3:18 am    Post subject: Reply with quote

Grand High Poobah

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

The Using java manual perfectly addresses the MQPooling in java base.
As for the use of a singleton in a servlet there are enough tutorials on the web

Again let me stress the better model being a J2EE app. This may not be in your realm of possibilities if you are running a IIS... but then I would expect you to use c# and not java...

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 » Connection Pooling using Base Classes for java
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.