Author |
Message
|
abhay09 |
Posted: Wed Aug 10, 2016 7:11 pm Post subject: Reading and writing RFH headers using MQJMS API |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
HI,
I am using MQJMS API for MQ Queue connection and message flows.
I am wondering how can I read RFH2 headers using MQJMS API or any property in <usr> folder using MQJMS API.
Also, how to write again back RFH2 in message using MQJMS API.
Please provide some insight or any running example, how can we read/write RFH2 headers using MQJMS API.
We do have many examples on net using MQ java API, but want it for MQJMS as of now.
My current approach:
https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_8.0.0/com.ibm.mq.dev.doc/q032360_.htm
Set the WMQ_MESSAGE_BODY property of the destination to WMQ_MESSAGE_BODY_MQ, to receive all the message body data in the JMSBytesMessage.
this is gviing me message in Bytes Message then using MQHRF2 classes to get all headers.
MQHeaderIterator it = new MQHeaderIterator(in, msg.getStringProperty("JMS_IBM_Format"),
msg.getIntProperty("JMS_IBM_Encoding"),
msg.getIntProperty(WMQConstants.JMS_IBM_MQMD_CODEDCHARSETID));
MQRFH2 mqrfh2 = null;
Now, with this approach it get iterate headers and get the message and header data.
is this correct method?
Its urgent, any help would be appreciated.
Thanks! |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Aug 11, 2016 5:23 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Wrong approach. By default, if you have not specified it differently the properties get put into an RFH2 header.
You have set the property: WMQ_MESSAGE_BODY_MQ which tells MQ to suppress the RFH2...
Set the property WMQ_MESSAGE_BODY_JMS instead.
Then in JMS you can just set the message property or get the message property from the message object...
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
abhay09 |
Posted: Thu Aug 11, 2016 11:39 pm Post subject: |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
Thanks for the reply.
But, it will not suppress the RFH header instead will include RFH or any other header in JmsBytesMessage
IBM site :https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_8.0.0/com.ibm.mq.dev.doc/q032360_.htm
You can access the complete IBM® MQ message data within an application using IBM MQ classes for JMS. To access all the data, the message must be a JMSBytesMessage. The body of the JMSBytesMessage includes any MQRFH2 header, any other IBM MQ headers, and the following message data.
Please let me know can I use this method,
if not, pls suggest some method.
My requirement:
I have a system.
user can send message to MQ queue via my system and user has option to amend any of RFH header in between via my system..
Now, if user send any of RFh header message to my system to get delivered to MQ, then i must read all RFH header and amend any if he wants to add in between , then write again all RFH to message and send to MQ Queue.
this all should be done via MQJMS API.
Please suggest any better way than what i m doing.
Please help!!
Thanks! |
|
Back to top |
|
 |
smdavies99 |
Posted: Thu Aug 11, 2016 11:47 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Have you tried the suggested solution?
You may learn more that way instead of waiting for replies here.
Quote: |
Please let me know can I use this method, |
So what is stopping you from trying this out? If it does not work then you have made that discovery for yourself or is it because the moon is not made of cheese ? _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
abhay09 |
Posted: Thu Aug 11, 2016 11:48 pm Post subject: |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
FYI:
Following code is used by my system
sample code for parsing MQHRF2 headers and separating body is:
BytesMessage msg = (JmsBytesMessageImpl) message;
byte[] readBytes = new byte[(int) (msg.getBodyLength())];
msg.readBytes(readBytes);
byteArrayInputStream = new ByteArrayInputStream(readBytes);
in = new DataInputStream(byteArrayInputStream);
MQHeaderIterator it = new MQHeaderIterator(in, msg.getStringProperty("JMS_IBM_Format"),
msg.getIntProperty("JMS_IBM_Encoding"),
msg.getIntProperty(WMQConstants.JMS_IBM_MQMD_CODEDCHARSETID));
MQRFH2 mqrfh2 = null;
while (it.hasNext()) {
MQHeader item = (MQHeader) it.next();
if(item instanceof MQRFH2){
mqrfh2 = (MQRFH2) item;
String [] elements = mqrfh2.getFolderStrings();
}
}
return it.getBodyAsBytes(); |
|
Back to top |
|
 |
abhay09 |
Posted: Fri Aug 12, 2016 12:35 am Post subject: |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
smdavies99 wrote: |
Have you tried the suggested solution?
You may learn more that way instead of waiting for replies here.
Quote: |
Please let me know can I use this method, |
So what is stopping you from trying this out? If it does not work then you have made that discovery for yourself or is it because the moon is not made of cheese ? |
I have tried this, it is working also.
But just want to confirm from the experts
Please suggest! |
|
Back to top |
|
 |
abhay09 |
Posted: Tue Aug 16, 2016 11:00 pm Post subject: |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
Guys, Pls confirm once.
With my approach, I am always getting JMS_IBM_MQMD_FORMAT as MQRHF2 even for String message,
Please help! |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Aug 17, 2016 12:43 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
abhay09 wrote: |
Guys, Pls confirm once.
With my approach, I am always getting JMS_IBM_MQMD_FORMAT as MQRHF2 even for String message,
Please help! |
Again you're approaching this the wrong way.
Retrieve the message as a JMSMessage. The payload as you have seen is kept separate from the RFH. The information you should look for is passed as named properties.
So in your code look for the properties in the message and you will get a mix of JMS properties inherent to the system and user properties (named properties).
Example: for having set...
Code: |
//sender side
msg.setStringProperty("color", "blue");
producer.send(msg);
//receiver side
String mycolor = msg.getStringProperty("color");
System.out.println("Color=" + mycolor);
......
Color=blue |
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
abhay09 |
Posted: Wed Aug 17, 2016 4:07 am Post subject: |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
fjb_saper wrote: |
abhay09 wrote: |
Guys, Pls confirm once.
With my approach, I am always getting JMS_IBM_MQMD_FORMAT as MQRHF2 even for String message,
Please help! |
Again you're approaching this the wrong way.
Retrieve the message as a JMSMessage. The payload as you have seen is kept separate from the RFH. The information you should look for is passed as named properties.
So in your code look for the properties in the message and you will get a mix of JMS properties inherent to the system and user properties (named properties).
Example: for having set...
Code: |
//sender side
msg.setStringProperty("color", "blue");
producer.send(msg);
//receiver side
String mycolor = msg.getStringProperty("color");
System.out.println("Color=" + mycolor);
......
Color=blue |
Have fun  |
Hi,
Thanks for the reply.
Let me explain you my system.
My system will read message from MQ queue and parse all user defined properties to xml and put same message and properties to different queue.
in between user has option to manipulate the xml (created above) to put in queue.
I can get message as JMS message and getting all properties.
Understood that it has message.getPropertyNames() to get all properties.
Now question is :
1.) how can I get properties defined in <usr> folder, means how can i get the custom properties defined by user.
user can add anything and my application should parse all user properties and create XML.
i am not able figure out how can i get only user defined properties using message.getPropertyNames() method.
2.) Also, when my system send message to queue, i want to override JMSDestination/JMSDeliveryMode/JMSTimestamp etc. to be same as what i read earlier from queue. How can i achieve this as creating producer and sending message is overriding all JMs properties to current queue, want it to be same as i read earlier.
Pls let me know for any information
Pls Pls help, its very urgent. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Aug 17, 2016 9:50 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
As specified with message.getPropertyNames() you get a mix of system properties and user properties.
It should not be overly hard for you as a java programmer to create a means of separating both...
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Vitor |
Posted: Wed Aug 17, 2016 9:57 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
abhay09 wrote: |
I am not able figure out how can i get only user defined properties using message.getPropertyNames() method. |
Don't ask me - I'm assuming my worthy (and Java skilled) associate is right about everything
abhay09 wrote: |
Also, when my system send message to queue, i want to override JMSDestination/JMSDeliveryMode/JMSTimestamp etc. to be same as what i read earlier from queue. How can i achieve this as creating producer and sending message is overriding all JMs properties to current queue, want it to be same as i read earlier. |
Don't JMS (as a standard and not as the IBM implementation of said standard) disallow that? In the same way MQ allows you to set a msg id but JMS does not? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
abhay09 |
Posted: Wed Aug 17, 2016 10:39 am Post subject: |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
fjb_saper wrote: |
As specified with message.getPropertyNames() you get a mix of system properties and user properties.
It should not be overly hard for you as a java programmer to create a means of separating both...
Have fun  |
OK, yeah can do that using some rules.
Can you pls solve my last issue in this:
Is there a way to send message to MQ queue using MQJMS API, that will suppress JMS headers but allow to send user defined properties.
like, added;
message.setStringProperty("user","1");
Now, want only this property as Named property in MQ queue, no JMS headers.
I tred using queue.setTargetClient(WMQConstants.WMQ_TARGET_DEST_MQ);
this is suppressing all RF2 headers.
Please let me know any way to achieve this?
Many thanks! |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Aug 17, 2016 10:44 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You don't know if it's suppressing MQRFH2 headers.
You only know that the tool you are using to read the message isn't showing you MQRFH2 headers. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
abhay09 |
Posted: Wed Aug 17, 2016 10:48 am Post subject: |
|
|
Acolyte
Joined: 31 May 2016 Posts: 66
|
mqjeff wrote: |
You don't know if it's suppressing MQRFH2 headers.
You only know that the tool you are using to read the message isn't showing you MQRFH2 headers. |
I checked with code also,
same userdefined property isn;t coming via JMS Consumer.
is there any method to send only user defined property and suppress JMS headers using MQJMS API?
pls help |
|
Back to top |
|
 |
RogerLacroix |
Posted: Wed Aug 17, 2016 12:56 pm Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
abhay09 wrote: |
Code: |
queue.setTargetClient(WMQConstants.WMQ_TARGET_DEST_MQ); |
is there any method to send only user defined property and suppress JMS headers using MQJMS API? |
So you want to have your cake and eat it too!! Not gonna happen.
WMQ_TARGET_DEST_MQ explicitly tells MQ to ONLY send message data and to strip away all properties.
You do know there are easy solutions in Java. Just use regex class and exclude everything that beginnings with 'mcd.' and 'JMS'. Hence, everything left is what you set.
Regards,
Roger Lacroix
Capitalware Inc. _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
|