Topic
  • 6 replies
  • Latest Post - ‏2013-04-19T16:19:06Z by fjb_saper
SystemAdmin
SystemAdmin
8523 Posts

Pinned topic Generate message id.

‏2013-04-02T20:21:27Z |
How do i create a unique message id?

my get method:

mqQueue.Get(mqMsg);
string messageID = Convert.ToString(mqMsg.MessageId);
string correlationID = Convert.ToString(mqMsg.CorrelationId);

my put method:

mqMsg.CorrelationId = System.Text.Encoding.UTF8.GetBytes(correlationID);
mqQueue.Put(mqMsg, mqPutMsgOpts);

My message id is empty when i put it over the export queue. How do i generate unique message ids via mq client?
Updated on 2013-04-05T01:26:45Z at 2013-04-05T01:26:45Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    8523 Posts

    Re: Generate message id.

    ‏2013-04-03T22:29:07Z  
    Message Id & Correl Id are 24 byte fields that can't be reliably converted to strings, unless you convert it to a hex string representation using 48 characters.

    MQ can generate a unique Message Id as a result of putting a message to a queue with a zero Message Id. This is the preferrred method of using Message Ids. A Correl Id is usually generated by an application copying a unique Message Id.
  • SystemAdmin
    SystemAdmin
    8523 Posts

    Re: Generate message id.

    ‏2013-04-04T16:42:52Z  
    Message Id & Correl Id are 24 byte fields that can't be reliably converted to strings, unless you convert it to a hex string representation using 48 characters.

    MQ can generate a unique Message Id as a result of putting a message to a queue with a zero Message Id. This is the preferrred method of using Message Ids. A Correl Id is usually generated by an application copying a unique Message Id.
    I am sending anything for message id, i am getting the same correlation id whatever is passed for that particular message.

    How do i generate unique message ids from MQ?

    My message id is in this format.

    MsgId=AMQ MYQUEUETEST O†6=(/³Y
  • SystemAdmin
    SystemAdmin
    8523 Posts

    Re: Generate message id.

    ‏2013-04-04T16:43:30Z  
    Message Id & Correl Id are 24 byte fields that can't be reliably converted to strings, unless you convert it to a hex string representation using 48 characters.

    MQ can generate a unique Message Id as a result of putting a message to a queue with a zero Message Id. This is the preferrred method of using Message Ids. A Correl Id is usually generated by an application copying a unique Message Id.
    I am NOT sending anything for message id, i am getting the same correlation id whatever is passed for that particular message.

    How do i generate unique message ids from MQ?

    My message id is in this format.

    MsgId=AMQ MYQUEUETEST O†6=(/³Y
  • SystemAdmin
    SystemAdmin
    8523 Posts

    Re: Generate message id.

    ‏2013-04-05T01:26:45Z  
    I am NOT sending anything for message id, i am getting the same correlation id whatever is passed for that particular message.

    How do i generate unique message ids from MQ?

    My message id is in this format.

    MsgId=AMQ MYQUEUETEST O†6=(/³Y
    >MsgId=AMQ MYQUEUETEST O†6=(/³Y

    That looks like a unique Message Id to me, although you should never try to display this as a string, as it will contain unprintable characters. Notice that the last few characters are strange. Normally if someone needs to post a printable a Message Id, they convert it to the 48 hex digit representation, as used by MQ Explorer etc.
  • Morag Hughson
    Morag Hughson
    140 Posts

    Re: Generate message id.

    ‏2013-04-18T17:40:34Z  

    If your message ID is empty when you do the MQPUT then the queue manager will generate a unique message ID for you. From the Message IDs you have demonstrated on earlier posts, they do indeed appear to be the queue manager generated format, so it seems like you are indeed generating unique Message IDs. I'm guessing that something made you think you were not however, perhaps you could tell us why you thought you were not generating unique IDs?

  • fjb_saper
    fjb_saper
    190 Posts

    Re: Generate message id.

    ‏2013-04-19T16:19:06Z  

    It has been said above but you may not have paid enough attention to it.

    MQMSGID IS NOT A STRING. The native form is byte[24] and will contain values that cannot be cast to char...

    If you need a String, it is commonly represented as the HEX value of the byte array.