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 API Support » Set MessageID and CorrelationID

Post new topic  Reply to topic Goto page 1, 2  Next
 Set MessageID and CorrelationID « View previous topic :: View next topic » 
Author Message
URPradhan
PostPosted: Sat May 14, 2011 4:35 am    Post subject: Set MessageID and CorrelationID Reply with quote

Novice

Joined: 05 May 2011
Posts: 14

Hi Friends

Again another question from a beginner.

I'm only sending messages to a queue and I need to set a "user defined" message id+correlation id each time to the messages before sending. The ImqMessage has inherited member functions to do the same, which require an object of ImqBinary. Now, How to create an object of ImqBinary with my user defined message id ?

Thank you.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sat May 14, 2011 5:49 am    Post subject: Re: Set MessageID and CorrelationID Reply with quote

Grand High Poobah

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

URPradhan wrote:
Hi Friends

Again another question from a beginner.

I'm only sending messages to a queue and I need to set a "user defined" message id+correlation id each time to the messages before sending. The ImqMessage has inherited member functions to do the same, which require an object of ImqBinary. Now, How to create an object of ImqBinary with my user defined message id ?

Thank you.


There is no harm in being a beginner. This said, best practice tells you that it is a really bad idea to have a user defined message Id. The pattern you want to look up here is "anonymous identifier". This means you let the system create the Id for you. You can then use the Id to identify the message, but you'll only know the Id after the message has been put to the queue. The same goes for creating a correlation Id. The system will also ensure that the values created are unique. You may use the messageId as correlationId, or just pass through and existing correlationId.

Now if you explain more about your requirement, maybe we can give you some way to work it right. In general, I would push back on a request for a user defined messageId or correlationId. If it needs logic, this should have been packed either into the message body, or its user defined properties (as opposed to system defined properties).

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
URPradhan
PostPosted: Sun May 15, 2011 10:15 pm    Post subject: Reply with quote

Novice

Joined: 05 May 2011
Posts: 14

OK. Lets keep aside the MessageID.

What about the Correlation ID ? Hope we can set it to any value for example: 1000 (decimal number). Now how to set this number as correlation id ?
Back to top
View user's profile Send private message
bruce2359
PostPosted: Mon May 16, 2011 4:54 am    Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9469
Location: US: west coast, almost. Otherwise, enroute.

Search google for 'imqbinary' or 'imqbinary+example' or 'imqbinary+sample' or you could refer to the WMQ Using c++ manual.
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Mon May 16, 2011 7:09 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Or simply STOP trying to use the C++ APIs for MQ.

There's no specific reason to use them unless you happen to WANT to, and no specific reason to go to great lengths to make them do things that it's a lot easier to do in the plain MQ API.

And there's absolutely no requirement to use C++ APIs from a C++ program.
Back to top
View user's profile Send private message
gbaddeley
PostPosted: Mon May 16, 2011 3:48 pm    Post subject: Reply with quote

Jedi Knight

Joined: 25 Mar 2003
Posts: 2538
Location: Melbourne, Australia

URPradhan wrote:
OK. Lets keep aside the MessageID.

What about the Correlation ID ? Hope we can set it to any value for example: 1000 (decimal number). Now how to set this number as correlation id ?


You can set CorrelId to any value you like, MQ does not care. Use the normal programming techniques for moving a typed variable to an array of 24 bytes, with padding if required.

Remember to consider processor architectures. Storing an integer in CorrelId on one platform may not be compatible with another platform. eg. Intel to/from just about everything else.
_________________
Glenn
Back to top
View user's profile Send private message
mvic
PostPosted: Mon May 16, 2011 4:32 pm    Post subject: Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

gbaddeley wrote:
Remember to consider processor architectures. Storing an integer in CorrelId on one platform may not be compatible with another platform.

You only need to "remember" this if you are treating your MsgId or CorrelId unusually - eg. storing integer values in them.

(Though I concede that, in answer to the question asked, this is reasonable advice).

IMHO, by far the best approach is to let MQ generate MsgId and CorrelId automatically for you, and treat them as opaque "blobs" of data.
Back to top
View user's profile Send private message
URPradhan
PostPosted: Mon May 16, 2011 5:12 pm    Post subject: Reply with quote

Novice

Joined: 05 May 2011
Posts: 14

Actually, as we know the transmission of mq messages happen in asynchronous mode.

But the requirement is that, the messages MUST be read from queue as the order they have been sent.

So to ensure the proper order of message while reading from queue, we are banking upon the CorrelationID, which will be set with an incremental sequence number and the target application will pick-up the messages with next higher CorrelationID exist on the queue.

Does MQ series guaranty the order of the message delivery?
In other words, does it guaranty the FIFO delivery?
Again the target application MUST read the messages in order.

If so then we can remove the dependency to use a correlationid.
Back to top
View user's profile Send private message
bruce2359
PostPosted: Mon May 16, 2011 5:49 pm    Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9469
Location: US: west coast, almost. Otherwise, enroute.

URPradhan wrote:

Does MQ series guaranty the order of the message delivery?

Yes, and no; it depends.

This subject is well documented in the WMQ Application Programming Guide.

Please do some research.
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
URPradhan
PostPosted: Tue May 17, 2011 2:11 am    Post subject: Reply with quote

Novice

Joined: 05 May 2011
Posts: 14

bruce2359 wrote:
URPradhan wrote:

Does MQ series guaranty the order of the message delivery?

Yes, and no; it depends.

This subject is well documented in the WMQ Application Programming Guide.

Please do some research.


Thank you for your help.

But after reading the relevant section in the programming guide, I understood is that the safer way to ensure proper order is to include a SEQUENCE number in the message body. And for my application I'm doing the same but setting the CorrelationId from the sequence number.
My sequence number is a 32-bit unsigned integer which would be max 10 char length. But CorrelationId is a 24 char length array. So I have to pad the leading zeros to the sequence number. Hope I'm on right path
Back to top
View user's profile Send private message
mvic
PostPosted: Tue May 17, 2011 2:27 am    Post subject: Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

URPradhan wrote:
My sequence number is a 32-bit unsigned integer which would be max 10 char length. But CorrelationId is a 24 char length array. So I have to pad the leading zeros to the sequence number. Hope I'm on right path

Sounds reasonable.

MQ can give you message ordering, but you have to be careful to implement your qmgr and channels correctly - eg. no dead letter queues allowed, no parallel paths in the topology. With get-by-correlid (assuming I understood your description correctly) you can obtain the assurance you need in the application, and save the need to be so careful in qmgr and channels implementation.

The only downside is that performance of get-by-correlid is a little less than the performance of a simple get. But it is not much less.

As to what you put in the MQMD.Correlid, it's entirely up to you. You appear to suggest encoding your sequence number in text (ASCII).. this will help avoid any integer encoding issues (Big Endian / Little Endian) that were referred-to earlier.

Hope it goes well.
Back to top
View user's profile Send private message
rekarm01
PostPosted: Tue May 17, 2011 3:06 pm    Post subject: Re: Set MessageID and CorrelationID Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

URPradhan wrote:
But CorrelationId is a 24 char length array.

Actually, CorrelationId is a 24-byte array.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue May 17, 2011 8:12 pm    Post subject: Reply with quote

Grand High Poobah

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

Quote:
As to what you put in the MQMD.Correlid, it's entirely up to you. You appear to suggest encoding your sequence number in text (ASCII).. this will help avoid any integer encoding issues (Big Endian / Little Endian) that were referred-to earlier.

But it raises other concerns as the correlId is a byte array and even if the content is text it NEVER gets translated from one CCSID to another.
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
gbaddeley
PostPosted: Thu May 19, 2011 5:16 pm    Post subject: Reply with quote

Jedi Knight

Joined: 25 Mar 2003
Posts: 2538
Location: Melbourne, Australia

URPradhan wrote:
Actually, as we know the transmission of mq messages happen in asynchronous mode.

But the requirement is that, the messages MUST be read from queue as the order they have been sent.

So to ensure the proper order of message while reading from queue, we are banking upon the CorrelationID, which will be set with an incremental sequence number and the target application will pick-up the messages with next higher CorrelationID exist on the queue.

That technique will work, but use a WaitInterval on MQGET, and cater for the possibility that messages might be missing or out of sequence. A suggestion is that the app should keep a table of missing message sequence numbers and periodically try to get them.

Quote:
Does MQ series guaranty the order of the message delivery?
In other words, does it guaranty the FIFO delivery?

No.
_________________
Glenn
Back to top
View user's profile Send private message
PeterPotkay
PostPosted: Fri May 20, 2011 3:53 am    Post subject: Reply with quote

Poobah

Joined: 15 May 2001
Posts: 7722

gbaddeley wrote:
and cater for the possibility that messages might be missing or out of sequence.

or duplicate messages (duplicated by the sending app for whatever reason)

gbaddeley wrote:
Quote:
Does MQ series guaranty the order of the message delivery?
In other words, does it guaranty the FIFO delivery?

No.

It does when certain, rather restrictive and not necessarily wise conditions are met.
_________________
Peter Potkay
Keep Calm and MQ On
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » IBM MQ API Support » Set MessageID and CorrelationID
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.