Author |
Message
|
dareurdream |
Posted: Wed May 28, 2008 2:12 am Post subject: Using Dynamic Queues |
|
|
Newbie
Joined: 28 May 2008 Posts: 5
|
Hi,
I have developed an application server(JMS) which takes messages from MQ then processes it and then sends back the response to the MQ from where the client( again developed by myself ) takes it back.
Till now I was using queues which were created before the application starts.
But now I want that my client(base java) application sends request to a queue which is existing but the response now comes back through a dynamic temporary queue.
Now, I have the following questions:-
1) What changes are required in my client, so that it sends messages to a queue which is present but then waits on a dynamic queue to get back the response?
2) Do I need to change my server code to post response to a dynamic queue?
I would appreciate if anyone can share code sample for using dynamic queue. I have tried to find code sample for the same, but in vain.
Thanks & Regards,
Lakshay
|
|
Back to top |
|
 |
fjb_saper |
Posted: Wed May 28, 2008 3:41 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Do not change the server code.
On the client open a MODEL queue. This will give you the name of the temporary queue (inspect the queue object returned by the open queue call). Put that name into the reply to queue. You do not want to close the queue until you have stopped waiting for any and all responses to be put there. Remember you cannot send persistent messages to a temporary dynamic queue.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
dareurdream |
Posted: Wed May 28, 2008 4:08 am Post subject: |
|
|
Newbie
Joined: 28 May 2008 Posts: 5
|
Thanks for the reply.
Do I need to open the MODEL queue while sending the request also or only while getting the response I have to open it. Then how do I pass this queue name to the accessQueue method.
One more thing, if I don't change my server code then how will it understand where to post the response.
I would appreciate if you could give a sample code.
Thanks & Regards,
Lakshay |
|
Back to top |
|
 |
exerk |
Posted: Wed May 28, 2008 4:34 am Post subject: |
|
|
 Jedi Council
Joined: 02 Nov 2006 Posts: 6339
|
Logic dictates that you have to open the MODEL first, or you will not have a REPLY-TO-QUEUE name to insert into the Request. _________________ It's puzzling, I don't think I've ever seen anything quite like this before...and it's hard to soar like an eagle when you're surrounded by turkeys. |
|
Back to top |
|
 |
dareurdream |
Posted: Wed May 28, 2008 5:00 am Post subject: |
|
|
Newbie
Joined: 28 May 2008 Posts: 5
|
Thanks for the post guys.
Given below is an extract of the major stuff from my code. Request you to look at it and suggest the required changes
private MQMessage sendMessageToQueue(String request) throws IOException, MQException {
MQMessage result = new MQMessage();
result.format = MQC.MQFMT_STRING;
result.messageType = 1;
result.expiry = 30 * 10;
result.correlationId = null;
result.persistence = MQC.MQPER_NOT_PERSISTENT;
result.writeString(request);
if ("true".equals(broker.getMqUseDynamicResponseQueue())) {
result.replyToQueueName = createDynamicResponseQueue();
} else {
result.replyToQueueName = broker.getMqResponseQueueName();
}
MQPutMessageOptions putMessageOptions = new MQPutMessageOptions();
putMessageOptions.options = MQC.MQPMO_NO_SYNCPOINT | MQC.MQPMO_DEFAULT_CONTEXT;
requestQueue = queueManager.accessQueue(broker.getMqRequestQueueName(), MQC.MQOO_OUTPUT, null, null, null);
requestQueue.put(result, putMessageOptions);
requestQueue.close();
return result;
}
private String createDynamicResponseQueue() {
try {
int openOptions = MQC.MQOO_INPUT_SHARED;
String responseQueueName =
broker.getMqResponseQueueName() + ("true".equals(broker.getMqUseDynamicResponseQueue()) ? ".*" : "");
responseQueue = queueManager.accessQueue("LIQAPI.MODEL.RSP", openOptions, null, responseQueueName, null);
dynamicResponseQueueName = responseQueue.name;
} catch (MQException exception) {
}
return dynamicResponseQueueName;
}
private String getMessageFromQueue(MQMessage requestQueue) throws IOException, MQException {
int openOptions = MQC.MQOO_INPUT_SHARED;
String responseQueueName =
broker.getMqResponseQueueName() + ("true".equals(broker.getMqUseDynamicResponseQueue()) ? ".*" : "");
String response = null;
MQMessage responseMessage = new MQMessage();
responseMessage.correlationId = MQC.MQMI_NONE;
if (requestQueue != null) {
responseMessage.correlationId = requestQueue.messageId;
}
MQGetMessageOptions getMessageOptions = new MQGetMessageOptions();
getMessageOptions.options = MQC.MQGMO_NO_SYNCPOINT | MQC.MQGMO_WAIT;
getMessageOptions.waitInterval = MQC.MQWI_UNLIMITED;
responseQueue = queueManager.accessQueue(dynamicResponseQueueName, openOptions);
responseQueue.get(responseMessage, getMessageOptions);
responseQueue.close();
response = responseMessage.readString(responseMessage.getMessageLength());
return response;
}
Thanks
Lakshay |
|
Back to top |
|
 |
dareurdream |
Posted: Thu May 29, 2008 5:51 am Post subject: |
|
|
Newbie
Joined: 28 May 2008 Posts: 5
|
Any suggestions on the code. I being new to MQ is not able to find out where the problem is. |
|
Back to top |
|
 |
bower5932 |
Posted: Thu May 29, 2008 6:09 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
|
Back to top |
|
 |
dareurdream |
Posted: Thu May 29, 2008 9:12 pm Post subject: |
|
|
Newbie
Joined: 28 May 2008 Posts: 5
|
Guys my server program is in jms, where as my client program is in base java. And it not possible for me to change both of them to work on jms. So request you to suggest some programs which i can refer that can help me on the client side and server side as well. |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat May 31, 2008 7:55 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
You have to know a thing or two about dynamic response queues.
Dynamic response queues are not suited for receiving PERSISTENT messages. You should get those from a static queue.
At first glance I see nothing wrong in your program. Can you please confirm that your response is not persistent?
I would however suggest that you start with messages without expiry until you have a good handle on the model: i.e. find them in the DLQ before they expire etc...
 _________________ MQ & Broker admin |
|
Back to top |
|
 |
|