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 » General IBM MQ Support » Getting MessageID From Message

Post new topic  Reply to topic Goto page 1, 2  Next
 Getting MessageID From Message « View previous topic :: View next topic » 
Author Message
Robert_11
PostPosted: Mon Jan 07, 2019 5:09 am    Post subject: Getting MessageID From Message Reply with quote

Newbie

Joined: 07 Jan 2019
Posts: 6

Hai All,

Iam Trying to Post message into MQ Topic with C# code i.e.

Code:


 public const String messageString = "TestMessage";
 messageForPut = new MQMessage();
 messageForPut.WriteString(messageString.Trim());
queueManager.Put(destType, null, queueManagerName, topicString, messageForPut, queuePutMessageOptions);



Iam sucessfully able to Publish the message using Topic . But what i want to do is log message id once the topic is published its data to its subscritptions

can any one suggest does i get MessagedID or Correlation id after i published one message using topic.


Thankk you.
Back to top
View user's profile Send private message
Vitor
PostPosted: Mon Jan 07, 2019 5:37 am    Post subject: Re: Getting MessageID From Message Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Robert_11 wrote:
But what i want to do is log message id once the topic is published its data to its subscritptions


Firstly, why? What value would this give you? If you're trying to log the fact you've sent the message, I would put it to you that some of the business data would be more useful.

Secondly, and a little pedantically, the fact that you've published the data does not prove any of subscribers have received it or will ever receive it. For example, if you have a default (non-durable) publication and one of the subscribers happens to be disconnected at the time of publication it will never receive the published data.

Robert_11 wrote:
can any one suggest does i get MessagedID or Correlation id after i published one message using topic.


Try the message descriptor object post-publication.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
hughson
PostPosted: Mon Jan 07, 2019 12:30 pm    Post subject: Re: Getting MessageID From Message Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1914
Location: Bay of Plenty, New Zealand

Robert_11 wrote:
Iam sucessfully able to Publish the message using Topic . But what i want to do is log message id once the topic is published its data to its subscritptions

can any one suggest does i get MessagedID or Correlation id after i published one message using topic.


Bear in mind that the Message ID of the message published to EACH subscription is different in each case. There is no single Message ID you could log that would match what the subscriptions receive. There is a Message ID returned to the publisher on completion of the put to the topic, in case the application relied upon the Message ID as a unique identifier to be use for something, but it is not the Message ID of any of the subscriber messages.

The Correlation ID however, can be the one the subscribers receive IFF they request to see the publishers Correlation ID. You cannot know that from the publishing application, but if you ask MQ to make a Correlation ID for you MQPMO_NEW_CORREL_ID, then you can get that upon return of the put to the topic, and if your subscribers request it, they will also get it.

Could you say a little more about WHY you want to to this, in case you are trying to do something that is better solved another way?

Cheers,
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software


Last edited by hughson on Mon Jan 07, 2019 7:36 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
RogerLacroix
PostPosted: Mon Jan 07, 2019 3:35 pm    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3252
Location: London, ON Canada

First, read Victor and Morag's responses very carefully and understand how Pub/Sub works in the MQ world.

Secondly, assuming you understand my 1st point, then your question boils down to a simple Java question (not really an MQ question). Every programmer should have a toolkit (aka code snippets) of simple utilities to do things like conversion between types.

In your case, you want to convert from a byte array (i.e. byte[]) to a Hexadecical String (i.e. 414D5120424D5150202020202020202087154E55039EBB23).

Here's a code snippet that you can add to your toolkit:

Code:
msg = new MQMessage();
msg.WriteString("This is a test message.");
qMgr.Put(destType, null, qMgrName, topicString, msg, pmo);

System.out.println("MessageId: " + bytesToHex(msg.messageId));
System.out.println("correlationId: " + bytesToHex(msg.correlationId));


/**
 * Convenience method to convert a byte array to a hex string.
 *
 * @param data the byte[] to convert
 * @return String the converted byte[]
 */
public String bytesToHex(byte[] data)
{
   StringBuffer buf = new StringBuffer();
   for (int i = 0; i < data.length; i++)
      buf.append(byteToHex(data[i]));

   return buf.toString();
}

/**
 * Convenience method to convert a byte to a hex string.
 *
 * @param data the byte to convert
 * @return String the converted byte
 */
public String byteToHex(byte data)
{
   final String HEX = "0123456789ABCDEF";
   int hi = (data & 0xF0) >> 4;
   int lo = (data & 0x0F);

   return "" + HEX.charAt(hi) + HEX.charAt(lo);
}


Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
Robert_11
PostPosted: Mon Jan 07, 2019 10:27 pm    Post subject: Re: Getting MessageID From Message Reply with quote

Newbie

Joined: 07 Jan 2019
Posts: 6

Thanks All,

Morag Wrote:
Quote:

There is a Message ID returned to the publisher on completion of the put to the topic.

I am looking for this solution how Message ID is returned back on a successful PUT. Could you guide me how can we extract the ID back.

Morag Wrote:
Quote:

Could you say a little more about WHY you want to to this


Our clients wants to know if the Publish to the topic was successful. As for queue we can get MSG ID back confirming the delivery to the queue. The same way how can we get to know if the publish went successful.


Regards
Robert


Last edited by Robert_11 on Tue Jan 08, 2019 1:05 am; edited 1 time in total
Back to top
View user's profile Send private message
hughson
PostPosted: Tue Jan 08, 2019 1:02 am    Post subject: Re: Getting MessageID From Message Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1914
Location: Bay of Plenty, New Zealand

Robert_11 wrote:
Quote:

Could you say a little more about WHY you want to to this


Our clients wants to know if the Publish to the topic was successful. As for queue we can get MSG ID back confirming the delivery to the queue. The same way how can we get to know if the publish went successful.


Sorry to labour the point, but what EXACTLY do you mean by the publish being successful? Here are a few things I can imagine you might mean, but I am curious EXACTLY which one you want.

  1. The Publish completed successfully regardless of how many subscribers (i.e. could be zero)
  2. The Publish completed successfully and there was at least one subscriber, regardless of delivery
  3. The Publish completed successfully and the messages were delivered to the subscriber queue and not to the DLQ (which would mean possible late delivery)
  4. The Publish completed successfully and the subscriber has consumed the message
  5. Something else.
You can do something for each of the items in the list, and none of them mean pulling the Message ID from the returned MQPUT call.

P.S. Message ID does not confirm delivery of message to the queue (depending on your setup, for example a remote Q).

Cheers,
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
Robert_11
PostPosted: Tue Jan 08, 2019 1:16 am    Post subject: Re: Getting MessageID From Message Reply with quote

Newbie

Joined: 07 Jan 2019
Posts: 6

Morag wrote:
Quote:

  1. The Publish completed successfully regardless of how many subscribers (i.e. could be zero)
  2. The Publish completed successfully and there was at least one subscriber, regardless of delivery


can u provide me solution how to achieve 1 and 2 statements.

Thanks,
Robert
Back to top
View user's profile Send private message
hughson
PostPosted: Tue Jan 08, 2019 2:02 am    Post subject: Re: Getting MessageID From Message Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1914
Location: Bay of Plenty, New Zealand

Robert_11 wrote:
can u provide me solution how to achieve 1 and 2 statements.

  1. The Publish completed successfully regardless of how many subscribers (i.e. could be zero)
    Check the return code is zero.

  2. The Publish completed successfully and there was at least one subscriber, regardless of delivery
    Use option MQPMO_WARN_IF_NO_SUBS_MATCHED and check for a completion code of MQCC_WARNING and a reason code of MQRC_NO_SUBS_MATCHED.
Cheers,
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
Robert_11
PostPosted: Tue Jan 08, 2019 3:49 am    Post subject: Re: Getting MessageID From Message Reply with quote

Newbie

Joined: 07 Jan 2019
Posts: 6

Morag wrotes:
Quote:

  1. The Publish completed successfully regardless of how many subscribers (i.e. could be zero)
    Check the return code is zero.


Code:

private String topicName = "DATA";
public const String topicString = "DATA";
 destForGet = queueManager.AccessTopic(topicName1, topicObject, MQC.MQTOPIC_OPEN_AS_PUBLICATION, openOptionsForGet);

                messageForPut = new MQMessage();
                messageForPut.CharacterSet = 1208;
                messageForPut.Format = MQC.MQFMT_STRING;
                messageForPut.WriteString(messageString.Trim());           
                queuePutMessageOptions = new MQPutMessageOptions();
                queueManager.Put(destType, null, queueManagerName, topicString, messageForPut, queuePutMessageOptions);
            string token = Convert.ToString(destForGet.CompletionCode);
                if (destForGet.CompletionCode == 0)
                {
                     strReturn = "Message published to the Topic Successfully" + "_" + token;
                     Console.WriteLine(strReturn);
                }
                else
                {
                    string code = destForGet.ReasonCode + "_" + destForGet.ReasonName;
                    strReturn = "Message Publishing failed in Topic" + "_" + code;
                    Console.WriteLine(strReturn);
                 
                }             

But if I used to get CompletionCode queuePutMessageOptions.Options = MQC.MQCC_WARNING; iam getting exception like MQRC_OPTION_ERROR.and i removed that statement and i got completion code as '0' and even if topic Name and topicString wrong also it gives '0' only.
can u suggest me some code to get completion code '0' for sucess PUT and '1' for it fails to PUT.

Thanks,
Robert
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Jan 08, 2019 6:01 am    Post subject: Re: Getting MessageID From Message Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Robert_11 wrote:
Our clients wants to know if the Publish to the topic was successful. As for queue we can get MSG ID back confirming the delivery to the queue. The same way how can we get to know if the publish went successful.


Note that the excellent advice Morag gave here:

hughson wrote:
Use option MQPMO_WARN_IF_NO_SUBS_MATCHED and check for a completion code of MQCC_WARNING and a reason code of MQRC_NO_SUBS_MATCHED


will only indicate if there are no subscribers to a given topic. It doesn't prove that the publication was received by any particular given subscriber.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Jan 08, 2019 6:06 am    Post subject: Re: Getting MessageID From Message Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Robert_11 wrote:
But if I used to get CompletionCode queuePutMessageOptions.Options = MQC.MQCC_WARNING; iam getting exception like MQRC_OPTION_ERROR.and i removed that statement and i got completion code as '0


Because that's not an option, as indicated by the MQCC name. Options are named MQPMO.

You really need to read up on MQ basics.

Robert_11 wrote:
even if topic Name and topicString wrong also it gives '0' only.


Because there's no such thing as a "wrong" topic name. A topic name is whatever you call it. If you use a name that doesn't match what you've agreed (for example a finger problem), you'd get the warning Morag states (and you don't need to set an option to get it).

Robert_11 wrote:
can u suggest me some code to get completion code '0' for sucess PUT and '1' for it fails to PUT.


No. Because that's not how MQ works. If the PUT works, you get a 0. If it fails, you get a 2 and if there's a warning you get a one and there are MQCC constants for each of these as you've discovered.

Thanks,
Robert[/quote]
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Jan 08, 2019 6:11 am    Post subject: Re: Getting MessageID From Message Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Robert_11 wrote:
Our clients wants to know if the Publish to the topic was successful.


Taking a step back, does your client mean "successful" to be:

1. the publication was successfully registered
2. the published data successfully reached all of the subscribers

For situation 1, an MQC.MQCC_SUCCESSFUL from the PUT does that.
For situation 2, you're doing it wrong. As Morag again quite rightly pointed out

Quote:
Message ID does not confirm delivery of message to the queue


or indeed delivery to the subscriber if it's using a dynamic rather than an administrative subscription.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
hughson
PostPosted: Tue Jan 08, 2019 2:57 pm    Post subject: Re: Getting MessageID From Message Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1914
Location: Bay of Plenty, New Zealand

Robert_11 wrote:
But if I used to get CompletionCode queuePutMessageOptions.Options = MQC.MQCC_WARNING; iam getting exception like MQRC_OPTION_ERROR.and i removed that statement and i got completion code as '0' and even if topic Name and topicString wrong also it gives '0' only.
can u suggest me some code to get completion code '0' for sucess PUT and '1' for it fails to PUT.

Don't set the MQC.MQCC_WARNING into queuePutMessageOptions.Options!!

You need to place the PMO option I gave you into queuePutMessageOptions.Options

Code:
queuePutMessageOptions.Options = MQC.MQPMO_WARN_IF_NO_SUBS_MATCHED


Then you need to check for the CompletionCode (destForGet.CompletionCode) being zero or being MQC.MQCC_WARNING.

If you get MQC.MQCC_WARNING and destForGet.ReasonCode is MQC.MQRC_NO_SUBS_MATCHED then you know there were no subscribers at the time you published your message.

If you're trying to catch the use of the "wrong" topic and one way to tell is that there is no-one subscribed on the "wrong" topic, then that would give you a non-zero Completion Code.

If you want to return either zero or one, map any non-zero value for Completion Code into one for your return value.

MQ's Completion Codes are as follows:-
  • MQCC_OK = 0
  • MQCC_WARNING = 1
  • MQCC_FAILED = 2
Cheers,
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
Robert_11
PostPosted: Thu Jan 10, 2019 8:56 pm    Post subject: Re: Getting MessageID From Message Reply with quote

Newbie

Joined: 07 Jan 2019
Posts: 6

Quote:

If you're trying to catch the use of the "wrong" topic and one way to tell is that there is no-one subscribed on the "wrong" topic, then that would give you a non-zero Completion Code.


But if i had gives wrong topic name also it gives zero Completion Code.

I had used code like below.

Quote:

destForGet = queueManager.AccessTopic(topicName1, topicObject, MQC.MQTOPIC_OPEN_AS_PUBLICATION, openOptionsForGet);
int token=destForGet.CompletionCode;


can u suggest me how can i get Completion Code as 2,if wrong topic.
Back to top
View user's profile Send private message
hughson
PostPosted: Thu Jan 10, 2019 11:33 pm    Post subject: Re: Getting MessageID From Message Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1914
Location: Bay of Plenty, New Zealand

Robert_11 wrote:
Quote:

If you're trying to catch the use of the "wrong" topic and one way to tell is that there is no-one subscribed on the "wrong" topic, then that would give you a non-zero Completion Code.


But if i had gives wrong topic name also it gives zero Completion Code.

I had used code like below.

Quote:

destForGet = queueManager.AccessTopic(topicName1, topicObject, MQC.MQTOPIC_OPEN_AS_PUBLICATION, openOptionsForGet);
int token=destForGet.CompletionCode;


can u suggest me how can i get Completion Code as 2,if wrong topic.

As I said earlier, if you use MQPMO_WARN_IF_NO_SUBS_MATCHED then that would be a way to get a non-zero Completion Code if you used the wrong topic. It will give you an MQCC_WARNING (value 1) but that would be good enough I'm sure.

Have you tried this yet?

Cheers,
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » General IBM MQ Support » Getting MessageID From Message
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.