how to use two execute queues for one servlet

for eg: i have only one servlet A , which can process two types of requests. i would like to pass first kind of request to one execute queue(probably default execute queue weblogic.kernel.Default) and second type of request to second excute queue.

Please help me !

Thanks Sudhakar

Andrea Gazzarini

Ranch Hand

Posts: 125

posted 9 years ago

What does it mean "two kinds of requests"? If, for example, the difference is in the url pattern you can declare two different servlets with the same class as below :

when ever there is request to servlet, in the request object we have parameter called BEAN. servlet reads this parameter from the request object and create a object for with that parameter eg: //Here WBean is a generic Bean WBean wb = null;String targetName = (String)request.getAttribute("Bean"); wb = (WBean)beanFactory.createObject(targetName);

Than it is going to call the following function to process the request. wb.processRequest(request, response ,beanFactory).

Currently we divided these beans into to two categories. One set of beans is for saving data and another set of beans is to retrieve the data. by default all these requests are going through the default web logic queue.

so we are planning to send the request to default queue if it is for saving the data (first category). Otherwise send the request to another queue(new execute queue)( second category).

can you please help us , whether we can setup two execute queues in this scenario.

Thanks sudhakar

Andrea Gazzarini

Ranch Hand

Posts: 125

posted 9 years ago

Hi Sudhakar, simply : you can't do that with your actual design!

The container is not able to make a distinction between two requests with the same url pattern. This is your scenario : you are calling the same servlet using a different value for a request parameter :

http//host ort/app/servlet?BEAN=A http//host ort/app/servlet?BEAN=B

what is written after the name of the servlet is called the query string and is not part of the identifier used in the url-pattern declaration.

now, since your bean are (I suppose) normal POJO, there's no container interposition so after a thread is executing your servlet you can't ask to the container another thread for executing a POJO.

Here's one suggestion:

1) Take the value of the BEAN parameter and create a jms TextMessage with it; 2) Create a temporaryQueue (ex: incomingResponseQueue)and send the message to a previously declared jms queue (ex: incomingRequestsQueue) with the setJMSReplyTo property set to the temporary queue; 3) An MDB detaches the message from the incomingRequestQueue, takes the name of the bean and create a valid instance using the ObjectFactory. 4) The MDB executes the bean and send the response as a ObjectMessage to incomingResponseQueue. 5) The servlet consume the message from the incomingResponseQueue.

Something like this:

***** Servlet code ******

**** MDB CODE ****

now, you have solved the first part of the problem : you can execute your beans in a separated executing thread. How you can distinguish the bean for updating and for retrieving data?

1) You can deploy twice the MDB (with two different names) on two different jms queues and assign to each of them a different execute queue. This could be done with some kind of configuration in the web.xml. (for example a mapping between bean name --> destination Queue) In this way the servlet must act as a router / dispatcher between the two queues / MDB.

2) If the names of the beans follow some kind of naming convention and starting from the name you can understand the category of it you can deploy twice the MDB (with two different names) on THE SAME jsm queues and assign to them a corrispondent message selector. In this way the servlet must put the bean name also in a string property of the jms message.

here i am confused about the last part ------------------------------------------------- How you can distinguish the bean for updating and for retrieving data?

1) You can deploy twice the MDB (with two different names) on two different jms queues and assign to each of them a different execute queue. This could be done with some kind of configuration in the web.xml. (for example a mapping between bean name --> destination Queue) In this way the servlet must act as a router / dispatcher between the two queues / MDB.

2) If the names of the beans follow some kind of naming convention and starting from the name you can understand the category of it you can deploy twice the MDB (with two different names) on THE SAME jms queues and assign to them a correspondent message selector. In this way the servlet must put the bean name also in a string property of the jms message. ----------------------------------------------------------------

can you explain little bit more about this (specially point 1 )

Andrea Gazzarini

Ranch Hand

Posts: 125

posted 9 years ago

Hi, suppose you have four beans. A,B,C,D. A and B are for retrieving data, while B and C for updating. Well, as I wrote you have two choices :

1) Using servlet deployment descriptor. Using init params you must declare inside the Deployment descriptor all the beans divided by category. Something like this:

Now, you servlet looks like this:

2) Using message selector. In this scenario you have only one queue and two MDB. The first MDB (for updating) has a message selector like this :

beanName IN ('A','B')

while the second one (for retrieving data) has the following message selector:

beanName IN ('C','D')

Now your servlet doesn't need to know the kind of request so in your service / doGet / doPost method :

That's all...the container will route the message to the appropriate MDB (using the message selector).