Author |
Message
|
abhay09 |
Posted: Tue Aug 09, 2016 4:09 am Post subject: MQ Message format changes on setStringProperty |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
Env:
MQ v8.0
Using MQ Java apis to send message to MQ.
I am using MQ Java API to send message to MQ Queue.
//pseudo code
MQEnvironment.hostname = hostname;
MQEnvironment.port = port;
MQEnvironment.channel = channel;
MQQueueManager qMgr = new MQQueueManager(qManager);
// Set up the options on the queue we wish to open
int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF| MQConstants.MQOO_OUTPUT;
MQQueue queue = qMgr.accessQueue(qName, openOptions);
msg.setStringProperty("user", "1");
// Specify the default put message options
MQPutMessageOptions pmo = new MQPutMessageOptions();
// Put the message to the queue
msg.writeUTF("Hello, World! ------ >");
queue.put(msg, pmo);
Now, if I don't setStringProperty then execute this program, then message format in MQ Queue comes out to be MQSTR.
and if I add msg.setStringProperty("user", "1"), then message format changes to MQRFH2.
So, question is how to preserve the format and add String property to MQ Message.
In the end , I want my message to be in MQSTR format in queue and with custom user property.
Any help would be appreciated.
Many Thanks! |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Aug 09, 2016 4:11 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
MQ automatically converts between MQRFH2 and message properties.
Depending on how the queue is configured, and what the program issuing the MQGET wants. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
abhay09 |
Posted: Tue Aug 09, 2016 4:15 am Post subject: |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
That depends on 3rd party client.
they should except the same format.
In between I am adding String property for my logging purpose.
So, how can i preseve the format and add custom properties. |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Aug 09, 2016 4:17 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You're missing what I'm saying.
If the client wants to read the message with an MQRFH2, they can.
If they want to read it with message properties, they can.
MQ will "convert" between these two, based on what the client asks for.
If you are seeing it as an MQRFH2, it's because *whatever you are using to read the message has asked for an MQRFH2*. Not because the message is *any* different. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
tomleend |
Posted: Tue Aug 09, 2016 12:07 pm Post subject: |
|
|
Acolyte
Joined: 24 Jan 2014 Posts: 51
|
When using the MQ classes for Java API, calling a property setter method (such as setStringProperty(...)) on an MQMessageobject will result in the classes for Java inserting an RFH2 header into the message to store that message property. Therefore the message will have the structure:
MQMD
Format : MQHRF2
...
RFH2:
Format : MQSTR
...
<usr>your property here</usr>
Body:
text of message here
This is because headers are chained in MQ messages. The body is still in MQSTR format but before the body is the RFH2 header to store the property or properties.
When a property is not set on an MQMessage object, the format is:
MQMD:
Format : MQSTR
...
Body:
text of message here
Now whether or not the message is actually put to the queue by the queue manager) with the RFH2 header and the property it contains or returned to a consuming application depends on various queue properties (PROPCTRL for instance) and get options. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Aug 09, 2016 7:51 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
If on receipt of the message you don't want to see the RFH header make sure you use MQGMO option MQGMO.PROPERTIES_IN_HANDLE.
Depending on your programming language the impact to the programming model is more or less severe.
Have fun  _________________ MQ & Broker admin
Last edited by fjb_saper on Wed Aug 17, 2016 12:26 am; edited 1 time in total |
|
Back to top |
|
 |
zpat |
Posted: Tue Aug 09, 2016 11:13 pm Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
Try this
mqQueue.setTargetClient(WMQConstants.WMQ_CLIENT_NONJMS_MQ);
Also, don't open an output queue for input. It's bad practice and will prevent the use of a remote queue. _________________ Well, I don't think there is any question about it. It can only be attributable to human error. This sort of thing has cropped up before, and it has always been due to human error. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Aug 10, 2016 3:53 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
|
Back to top |
|
 |
abhay09 |
Posted: Wed Aug 10, 2016 7:07 pm Post subject: |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
Thanks for the replies.
Let me explain my system.
It is abstract system.
User is sending message to MQ queue and getting from same queue via my system.
Now, user sent a message in MQSTR format to my system,
I have added one string property to that message and sent it to MQ.
Now, any 3rd party client , tried to read same messages from that queue.
user knows he sent MQSTR format , so 3rd party client also expects it in MQSTR format.
But , as my system in between added String property it changes format to RFH.
That cause in discrepancy and test case failed.
Now, my question is how can i just add any string property without appending any message structure.
Is there a way ? or 3rd party client need to append its code?
Please help. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Aug 11, 2016 3:43 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
abhay09 wrote: |
Now, my question is how can i just add any string property without appending any message structure. |
Yes, that is your question.
Were any of my answers to this question confusing? _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
abhay09 |
Posted: Thu Aug 11, 2016 11:43 pm Post subject: |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
understood your reply.
But, then how can I prevent it to not convert to MQRHF2.
Please excuse me for stupid question if any , I am new to MQ.
in the end, it want my message to b seen in same format (in MQ explorer) with added sting property to it?
Can it be possible? |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Aug 12, 2016 9:03 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
abhay09 wrote: |
understood your reply.
But, then how can I prevent it to not convert to MQRHF2.
Please excuse me for stupid question if any , I am new to MQ.
in the end, it want my message to b seen in same format (in MQ explorer) with added sting property to it?
Can it be possible? |
Doubt it with MQ Explorer, try RFHUtil(c) instead...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
RogerLacroix |
Posted: Tue Aug 16, 2016 11:49 am Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
Have you ever seen those mobile apps with filters? Same picture just different filters being applied to the picture which gets you different results.
In MQ Explorer, the default view (aka GetMessageOption) for browsing messages is 'as Named Properties'. Which means an MQRFH2 message will be shown with Format=MQSTR and the properties as 'Named Properties'.
Click Window -> Preferences -> MQ Explorer -> Messages and you will see:
Show message properties
- as Named Properties
- as an MQRFH2 structure in message body
- as an MQRFH2 structure in message body, compatible with MQ v6
If you change it to the 2nd or 3rd option, then when you browses messages you will see the standard MQRFH2 message layout.
From a Java coding point of view:
Code: |
MQGetMessageOptions gmo= new MQGetMessageOptions();
gmo.options = CMQC.MQGMO_NO_WAIT + CMQC.MQGMO_BROWSE_NEXT + CMQC.MQGMO_FAIL_IF_QUIESCING;
inQ.get(getMsg, gmo); |
Any message with properties will be retrieved as an MQRFH2 formatted message.
This is how it really looks to MQ:
Code: |
MQGetMessageOptions gmo= new MQGetMessageOptions();
gmo.options = CMQC.MQGMO_PROPERTIES_FORCE_MQRFH2 + CMQC.MQGMO_NO_WAIT + CMQC.MQGMO_BROWSE_NEXT + CMQC.MQGMO_FAIL_IF_QUIESCING;
inQ.get(getMsg, gmo); |
Note: The 'CMQC.MQGMO_PROPERTIES_FORCE_MQRFH2' option which is the default!!!!!
Now if you want to get the message with format=MQSTR and 'Named Properties' then you would do:
Code: |
MQGetMessageOptions gmo= new MQGetMessageOptions();
gmo.options = CMQC.MQGMO_PROPERTIES_IN_HANDLE + CMQC.MQGMO_NO_WAIT + CMQC.MQGMO_BROWSE_NEXT + CMQC.MQGMO_FAIL_IF_QUIESCING;
inQ.get(getMsg, gmo); |
The 'CMQC.MQGMO_PROPERTIES_IN_HANDLE' tells MQ that the application wants MQRFH2 message to be retrieved as a message with format=MQSTR and the properties as 'Named Properties'.
Note: You can do the same thing at a queue level. See the Queue attribute called 'Property control' in the MQ Knowledge Center here for more info.
Regards,
Roger Lacroix
Capitalware Inc. _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
|