Author |
Message
|
Alteo |
Posted: Mon Jan 14, 2008 10:27 am Post subject: Correlation Id and Message Id with C language |
|
|
Newbie
Joined: 14 Jan 2008 Posts: 5
|
Hello!
I'm feeding a queue using the MQPUT C funtion. I've set the MQPMO_NEW_MSG_ID and the MQPMO_NEW_CORREL_ID options so the Correlation Id and the Message Id are generated by MQ. At last, I would like to use Correlation Id and Message Id to retrieve a specific message (entering them manually).
However, when I read Correlation Id and Message Id with printf, it always displays something like "AMQ QM_FWRK1D Ga9", which does not work to retrieve a message.
Here is the code I use :
unsigned char *MessageID; /* message ID */
unsigned char *CorrelationID; /* correlation ID */
...
pmo.Options |= MQPMO_NEW_MSG_ID;
pmo.Options |= MQPMO_NEW_CORREL_ID + MQRO_PASS_CORREL_ID;
MessageID = MQMI_NONE;
CorrelationID = MQCI_NONE;
memcpy(md.MsgId, MessageID, sizeof(md.MsgId) );
memcpy(md.CorrelId, CorrelationID, sizeof(md.CorrelId) );
MQPUT(Hcon, /* connection handle */
Hobj, /* object handle */
&md, /* message descriptor */
&pmo, /* default options (datagram) */
messlen, /* message length */
mq_message, /* message buffer */
&CompCode, /* completion code */
&Reason); /* reason code */
printf("Message ID after launch: %s\n", md.MsgId);
printf("Correlation ID after launch: %s\n", md.CorrelId);
How can I then get the Correlation Id and the Message Id and use them in another process?
Thanks for your help.
Regard.
Alteo |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Jan 14, 2008 10:38 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Quote: |
unsigned char *MessageID; /* message ID */
unsigned char *CorrelationID; /* correlation ID */ |
You should really read your documentation and the programmer's manual.
Who ever told you that the data type would be unsigned char???  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Alteo |
Posted: Tue Jan 15, 2008 1:24 am Post subject: |
|
|
Newbie
Joined: 14 Jan 2008 Posts: 5
|
fjb_saper wrote: |
You should really read your documentation and the programmer's manual.
Who ever told you that the data type would be unsigned char???  |
Well... Correlation Id and Message Id are MQBYTE24-typed. And MQBYTE24 is actually MQBYTE[24].
According to MQ include files, MQBYTE type is defined as:
typedef unsigned char MQBYTE;
That's why I used an unsigned char* to set a string as Correlation Id and Message Id. |
|
Back to top |
|
 |
bower5932 |
Posted: Tue Jan 15, 2008 2:25 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
"unsigned char" doesn't mean that the field will be a readable string. If you are interested in using the fields, you'll have to use memcpy to get at them. |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Jan 15, 2008 3:04 am Post subject: Re: Correlation Id and Message Id with C language |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Alteo wrote: |
How can I then get the Correlation Id and the Message Id and use them in another process? |
Despite the fact that you're not using MQBYTEs properly...
What do you mean by "another process"?
Also, what do you mean by "how can I get"? Did the code you showed not print anything? Or did it print something you didn't like the looks of? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Alteo |
Posted: Tue Jan 15, 2008 5:00 am Post subject: |
|
|
Newbie
Joined: 14 Jan 2008 Posts: 5
|
bower5932 wrote: |
"unsigned char" doesn't mean that the field will be a readable string. If you are interested in using the fields, you'll have to use memcpy to get at them. |
That's the point. Since it is another program that has to use the Correlation Id and Message Id, I cannot memcpy them. The only way I thought of was to parse them as strings and pass them to the other program.
But actually, I found out. To retrieve the Correlator Id, I do something like :
for (i = 0 ; i < MQ_CORREL_ID_LENGTH ; i++)
printf("%02x",md.CorrelId[i] );
Then, I have a string like "414d5120etc..." on the console.
And to feed the CorrelId (through hard code):
unsigned char* CorrelationID = "\x41\x4d\x51\x20etc...";
memcpy(md.CorrelId, CorrelationID, sizeof(md.CorrelId)); |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Jan 15, 2008 5:04 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Why are you bothering with another process? That seems like a lot of extra work.
In a standard request/reply paradigm, you would send your request and wait for the reply in the same program, with the same MQ connection. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
bower5932 |
Posted: Tue Jan 15, 2008 5:18 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
Alteo wrote: |
And to feed the CorrelId (through hard code) |
I can't imagine a situation where you would hard code the correlation id. I can't even remember a situation where I needed to know what the id was. It is generated uniquely by WMQ and that was good enough for me.
As jefflowrey said, this looks like a lot of extra work. What are you trying to do? |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jan 15, 2008 5:21 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Alteo wrote: |
And to feed the CorrelId (through hard code):
|
It might work, but it's not exactly going to scale is it.....?
I also wonder/worry that this is all to keep messages on a queue and retrieve them hours/days/weeks later with this hard coded value. If so, it's not a good idea to use a queue like this; put the values in a database where they belong. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Jan 15, 2008 5:28 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Huh.
I missed that bit about "hard code".
Just use argv and pass the correlID string on the cmd line...
Or, a whole lot better - don't use another process. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Alteo |
Posted: Tue Jan 15, 2008 5:35 am Post subject: |
|
|
Newbie
Joined: 14 Jan 2008 Posts: 5
|
jefflowrey wrote: |
Why are you bothering with another process? That seems like a lot of extra work.
In a standard request/reply paradigm, you would send your request and wait for the reply in the same program, with the same MQ connection. |
Actually, the thing is that I have two MQ clients. The first one sends a message that the second one reads. But it has to read it using the Correlation Id and Message Id given as parameters. Since those are two programs that are called by the user, it was not possible to set an MQBYTE-types variable manually. |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jan 15, 2008 5:39 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Alteo wrote: |
The first one sends a message that the second one reads. But it has to read it using the Correlation Id and Message Id given as parameters. |
Why?
If these applications are started by a user (odd but ok), and Application A sends a message to Application B, why does the user who starts Application B need that particular message? What's the connection?
I'm really struggling to see your requirement here. If Application A is doing something, and then notifying Application B that it's user needs to do something, it wouldn't need the message ids to do that.
More details please.  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue Jan 15, 2008 5:52 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
E verything you say seems like exactly the wrong way to do things.
There's no need to specify an exact MsgId and CorrelId for a general purpose MQ get. You can just ask for "the next message on the queue". Then MsgId and CorrelID will be populated after a successful GET.
The only time you need to know a MsgId and/or CorrelID before a Get is when you need to be able to get only a specific message. And this should only be done in a request/reply scenario, from the requesting side, in order to match up the reply with the outbound request.
If you really, really think you need to have the second process pull the message by CorrelID/MsgID... then use two queues - one that holds the actual data, and one that holds a message that says "the actual data is identified with this CorrelID/MsgID". Then the second process can read every message off the second queue, and use that information to get the messages from the first queue.
But that's a ridiculous way to do things. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Alteo |
Posted: Tue Jan 15, 2008 5:54 am Post subject: |
|
|
Newbie
Joined: 14 Jan 2008 Posts: 5
|
Vitor wrote: |
Alteo wrote: |
The first one sends a message that the second one reads. But it has to read it using the Correlation Id and Message Id given as parameters. |
Why?
If these applications are started by a user (odd but ok), and Application A sends a message to Application B, why does the user who starts Application B need that particular message? What's the connection?
I'm really struggling to see your requirement here. If Application A is doing something, and then notifying Application B that it's user needs to do something, it wouldn't need the message ids to do that.
More details please.  |
Ok, let's settle the very whole thing. Forget everything above, I will start from the beginning.
I have two distant applications, A and B, which communicate each other through MQ. A has to request B for some task, then B answers back to A with the task result. In order to retrieve easily any response for any task, B sets the CorrelId and the MsgId of the response to the ones it found in the request.
I'm not responsible for A's development, but I would like to test B's behaviour about the CorrelId and the MsgId. I then developped a test program that sends a request, and another test program that reads the response. Then, I sent a request, getting CorrelId and MsgId. After that, I tried to retrieve the response using the values I got, to make sure it really works.
Since it never worked, I was pretty sure that I did not feed the CorrelId and MsgId correctly. That's why I wanted to know how to read it and how to set it manually. |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jan 15, 2008 5:59 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Alteo wrote: |
In order to retrieve easily any response for any task, B sets the CorrelId and the MsgId of the response to the ones it found in the request.
|
Typically you'd only set the CorrelId. This allows you to separate request & response messages by different message ids, and also allows you to send multiple replies. If you ever needed to (rework is a pain). It's also more usual to use the MsgId of the request as the CorrelId of the reply (hence the field names) to save work in the sending application, but that's just more usual and in your situation it doesn't sound like you have control over the sending application logic.
So I mention this more to add value for future searchers.
Alteo wrote: |
Since it never worked, I was pretty sure that I did not feed the CorrelId and MsgId correctly. That's why I wanted to know how to read it and how to set it manually. |
I'd go with jefflowrey's suggestion and pass it as a parameter as it's just a test harness. Save all that recompilation. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
|