Author |
Message
|
masteringmq |
Posted: Mon Oct 20, 2008 2:11 am Post subject: CorrelationID |
|
|
Master
Joined: 20 Oct 2008 Posts: 200
|
I wrote the code below to put and retrieve messages from a queue. The messages will be put on a remote queue on QM1 and will travel to QM5 local queue QM1.RQSTIN. I have 5 different front end interface build using the java programming language. Each interface will talk to QM1. Now how does the application retrieving the messages in QM5 know which message belongs to which interface and how does the receiving application retrieve all messages associated with a particular interface?. Do I set the correlation ID for the messages on the sending application and at the receiving end retrieve the messages using the correlation ID?. But then how does the receiving application know the correlation ID used by the sending application?.
import com.ibm.mq.*;
public class MQSample
{
private String qManager = "QM1";
private MQQueueManager qMgr;
public static void main(String args[])
{
new MQSample();
}
public MQSample()
{
try
{
//qMgr = new MQQueueManager(qManager);
//int openOptions = MQC.MQOO_OUTPUT ;
//MQQueue MQ1_RQSTIN = qMgr.accessQueue("QM1.RQSTIN",openOptions);
//MQMessage hello_world = new MQMessage();
//hello_world.writeUTF("Hello World!");
//MQPutMessageOptions pmo = new MQPutMessageOptions();
//MQ1_RQSTIN.put(hello_world,pmo);
qMgr = new MQQueueManager("QM5");
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF ;
MQQueue MQ1_RQSTIN = qMgr.accessQueue("QM1.RQSTIN",openOptions);
MQMessage retrievedMessage = new MQMessage();
//retrievedMessage.messageId = hello_world.messageId;
MQGetMessageOptions gmo = new MQGetMessageOptions();
MQ1_RQSTIN.get(retrievedMessage,gmo);
String msg = retrievedMessage.readUTF();
System.out.println(msg);
MQ1_RQSTIN.close();
qMgr.disconnect();
}
catch (MQException ex)
{
System.out.println("A WebSphere MQ error occurred : Completion code " + ex.completionCode + " Reason code " + ex.reasonCode);
}
catch (java.io.IOException ex)
{
System.out.println("An error occurred whilst writing to the message buffer: " + ex);
}
}
} |
|
Back to top |
|
 |
atheek |
Posted: Mon Oct 20, 2008 2:14 am Post subject: |
|
|
 Partisan
Joined: 01 Jun 2006 Posts: 327 Location: Sydney
|
Why can't you have 5 different local queues at QM5 and have the corresponding 5 remote queues at QM1? This helps to keep your interfaces isolated... |
|
Back to top |
|
 |
masteringmq |
Posted: Mon Oct 20, 2008 4:08 am Post subject: |
|
|
Master
Joined: 20 Oct 2008 Posts: 200
|
Because I intend to establish a shared queue. I know that it is possible to have 5 different local queue serving 5 different application. |
|
Back to top |
|
 |
masteringmq |
Posted: Mon Oct 20, 2008 6:45 am Post subject: |
|
|
Master
Joined: 20 Oct 2008 Posts: 200
|
I found the answer  |
|
Back to top |
|
 |
PeterPotkay |
Posted: Mon Oct 20, 2008 7:50 am Post subject: |
|
|
 Poobah
Joined: 15 May 2001 Posts: 7722
|
Is it a secret? Whisper it to us, so the next person with the same problem can benefit. _________________ Peter Potkay
Keep Calm and MQ On |
|
Back to top |
|
 |
thomas2004 |
Posted: Thu Nov 13, 2008 6:59 am Post subject: |
|
|
Novice
Joined: 13 Nov 2008 Posts: 16
|
|
Back to top |
|
 |
amer.abugharbieh |
Posted: Wed Nov 26, 2008 1:13 am Post subject: |
|
|
Newbie
Joined: 25 Nov 2008 Posts: 5
|
i have the same question  |
|
Back to top |
|
 |
samsam007 |
Posted: Thu Nov 27, 2008 9:21 pm Post subject: |
|
|
 Centurion
Joined: 30 Oct 2008 Posts: 107
|
masteringmq wrote: |
I found the answer  |
Hello... I have the same problem. What is your solution? |
|
Back to top |
|
 |
atheek |
Posted: Thu Nov 27, 2008 10:27 pm Post subject: |
|
|
 Partisan
Joined: 01 Jun 2006 Posts: 327 Location: Sydney
|
It is not a good practise to mix different message types into the same queue. If the 5 front end produces 5 different message types it is better to have 5 different queues to process them.
Else if you have identical messages, you can use the correlation id to correlate the response. The receiver application need not be aware from
where the request came in.It has to just copy the message ID in the request to the correlation id in the response and send it back to replyTo Queue in the request.
The sender appln needs to wait for a response in the replyTo Q with a matching correlation id.
Even if the 5 instances of the sender appln shares the same replyTO Queue, only the original sender will wait for a matching correlation ID. |
|
Back to top |
|
 |
|