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 Java / JMS » Reading and writing RFH headers using MQJMS API

Post new topic  Reply to topic Goto page Previous  1, 2
 Reading and writing RFH headers using MQJMS API « View previous topic :: View next topic » 
Author Message
smdavies99
PostPosted: Wed Aug 17, 2016 10:31 pm    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

RogerLacroix wrote:


You do know there are easy solutions in Java.


Isn't that rather an oxymoron? Easy and Java in the same sentence?


Yes, I know I'm a but even looking back at some old Coral-66 code made more sense than most Java I see these days.
_________________
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
View user's profile Send private message
fjb_saper
PostPosted: Wed Aug 17, 2016 10:39 pm    Post subject: Reply with quote

Grand High Poobah

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

smdavies99 wrote:

Yes, I know I'm a but even looking back at some old Coral-66 code made more sense than most Java I see these days.

Patience Grasshopper, Patience. With serenity a little wisdom and a few years it will all make sense to you... Of course by then you will have a java device implanted in your body...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
abhay09
PostPosted: Wed Aug 17, 2016 10:54 pm    Post subject: Reply with quote

Acolyte

Joined: 31 May 2016
Posts: 66

RogerLacroix wrote:
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.





While sending message to MQ Queue using MQJMS API, how can i exclude these properties, couldnt get.
Can you pls elaborate?

how can i use regex in this case?
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Thu Aug 18, 2016 8:16 am    Post subject: Reply with quote

Jedi Knight

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

abhay09 wrote:
While sending message to MQ Queue using MQJMS API, how can i exclude these properties, couldnt get.

You can't. Did you read the MQ Knowledge Center?

abhay09 wrote:
Can you pls elaborate?
how can i use regex in this case?

So you want me to write the code for you? In return, you need to purchase a ticket to MQTC v2.0.1.6.

Actually, it is far easier than I thought. Here is the code for the receiving side:
Code:
String propName;
ArrayList<String> myProps = new ArrayList<String>();
props = msg.getPropertyNames("%");
if (props != null)
{
    while (props.hasMoreElements())
    {
       propName = props.nextElement();
       if ( !(propName.startsWith("mcd.")) && !(propName.startsWith("JMS")) )
          myProps.add(propName);
    }
}


Hence, the field myProps will have only the properties you set on the sending side (the MQRFH2 properties will be removed).

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
abhay09
PostPosted: Thu Aug 18, 2016 8:30 am    Post subject: Reply with quote

Acolyte

Joined: 31 May 2016
Posts: 66

RogerLacroix wrote:
abhay09 wrote:
While sending message to MQ Queue using MQJMS API, how can i exclude these properties, couldnt get.

You can't. Did you read the MQ Knowledge Center?

abhay09 wrote:
Can you pls elaborate?
how can i use regex in this case?

So you want me to write the code for you? In return, you need to purchase a ticket to MQTC v2.0.1.6.

Actually, it is far easier than I thought. Here is the code for the receiving side:
Code:
String propName;
ArrayList<String> myProps = new ArrayList<String>();
props = msg.getPropertyNames("%");
if (props != null)
{
    while (props.hasMoreElements())
    {
       propName = props.nextElement();
       if ( !(propName.startsWith("mcd.")) && !(propName.startsWith("JMS")) )
          myProps.add(propName);
    }
}


Hence, the field myProps will have only the properties you set on the sending side (the MQRFH2 properties will be removed).

Regards,
Roger Lacroix
Capitalware Inc.



I think, you got me in wrong way.

I am using MQJMS API.

I can get all Property names via

Message message = consumer.receiveNoWait();
Enumeration en = message.getPropertyNames();

and in that, i can remove JMS/mcd properties.

That i understood, thanks!

My question is actually different.

I am saying , I am creating a JMS Producer and sending message to MQ Queue with it.

JMSProducer producer = context.createProducer();
Message message = context.createTextMessage("hi");
message.setStringProperty("user", "qwe");

Now, with this code JMS Headersa are also attached to msg.

I can suppress RFH headers by
queue.setMessageBodyStyle(WMQConstants.WMQ_MESSAGE_BODY_MQ);

But that also suppressing user defined property.
Now, is there a way to send only custom/userdefined property using MQJMS API to MQ.?

I hope i make it clear this time.

Thanks!
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Thu Aug 18, 2016 8:55 am    Post subject: Reply with quote

Jedi Knight

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

abhay09 wrote:
I think, you got me in wrong way.

It is not me that is having issues but you. You refuse to read what I am saying and you refuse to read the manual (MQ Knowledge Center).

abhay09 wrote:
But that also suppressing user defined property.
Now, is there a way to send only custom/userdefined property using MQJMS API to MQ.?

For the "nth" time, NO.

Since, you refuse to read the manual, let me be absolutely clear: (1) you can send all properties or (2) none.

I don't understand why you don't just think the problem through. I gave you a very workable solution.

Here's another: properly qualify your properties. i.e. "ABHAY.something" If you read the manual, you would know that you can call properties name "ABHAY.abc.blah.some.thing.or.any.thing"
Code:
JMSProducer producer = context.createProducer();
Message message = context.createTextMessage("hi");
message.setStringProperty("ABHAY.user", "qwe");


Then on the receiving side just update my code to be:
Code:
String propName;
ArrayList<String> myProps = new ArrayList<String>();
props = msg.getPropertyNames("ABHAY.%");
if (props != null)
{
    while (props.hasMoreElements())
    {
       propName = props.nextElement();
       myProps.add(propName);
    }
}


What is so difficult about thinking things through?

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
abhay09
PostPosted: Thu Aug 18, 2016 10:27 am    Post subject: Reply with quote

Acolyte

Joined: 31 May 2016
Posts: 66

RogerLacroix wrote:
abhay09 wrote:
I think, you got me in wrong way.

It is not me that is having issues but you. You refuse to read what I am saying and you refuse to read the manual (MQ Knowledge Center).

abhay09 wrote:
But that also suppressing user defined property.
Now, is there a way to send only custom/userdefined property using MQJMS API to MQ.?

For the "nth" time, NO.

Since, you refuse to read the manual, let me be absolutely clear: (1) you can send all properties or (2) none.


I don't understand why you don't just think the problem through. I gave you a very workable solution.

Here's another: properly qualify your properties. i.e. "ABHAY.something" If you read the manual, you would know that you can call properties name "ABHAY.abc.blah.some.thing.or.any.thing"
Code:
JMSProducer producer = context.createProducer();
Message message = context.createTextMessage("hi");
message.setStringProperty("ABHAY.user", "qwe");


Then on the receiving side just update my code to be:
Code:
String propName;
ArrayList<String> myProps = new ArrayList<String>();
props = msg.getPropertyNames("ABHAY.%");
if (props != null)
{
    while (props.hasMoreElements())
    {
       propName = props.nextElement();
       myProps.add(propName);
    }
}




Regards,
Roger Lacroix
Capitalware Inc.


I already read the manual and understood that if I set Message body style as MQ, then all RFH and messagedata will come in JMSBYtesMessage. and on sending it wil not append any JMS RFH header.

COntrol is in our hand to add anythng in JMSBytesMessage,


We can create JMSBYtesmessage and use MQRFH2 mqrfh2 = new MQRFH2(); class

Message msg = context.createBytesMessage();

mqrfh2.setFormat(MQC.MQFMT_RF_HEADER_2); // Following this header will be another rfh2 header
mqrfh2.setFlags(MQC.MQRFH_NO_FLAGS);// Flags
mqrfh2.setNameValueCCSID(1208); // NameValueCCSIDs UTF-8
mqrfh2.setNameValueData(folderBytes);

mqrfh2OutputStream = new ByteArrayOutputStream();
mqrfh2DataOutputStream = new DataOutputStream(mqrfh2OutputStream);
mqrfh2.write(mqrfh2DataOutputStream, encoding,
codedCharactetSetId);
byte[] bytes = mqrfh2OutputStream.toByteArray();
msg.writeBytes(bytes);


by above code we can add anythng in JMSBytesMessage.
folderBytes above here is could be any property.


This way i can send only custom property to MQ Queue,

- I just want to confirm this from you experts as I am new to MQ.
Second thing is other guys said its a wrong approach.

So, one last time can you also confirm without being rude


What is so difficult about thinking things through?

Understood this, will check more with my system.

THanks
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Thu Aug 18, 2016 11:18 am    Post subject: Reply with quote

Jedi Knight

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

abhay09 wrote:
I already read the manual and understood that if I set Message body style as MQ, then all RFH and messagedata will come in JMSBYtesMessage. and on sending it wil not append any JMS RFH header.

Clearly, you do NOT understand because of what you just wrote.

So, you don't understand that JMSMessage == MQRFH2. A message that is created with MQ JMS API is EXACTLY the same as an MQRFH2 message created with MQ classes for Java.

abhay09 wrote:
COntrol is in our hand to add anythng in JMSBytesMessage,

JMSBytesMessage or JMSTextMessage describes the type of message data (not the message - big difference!!!). Message data (of type JMSBytesMessage or JMSTextMessage) does not contain other elements. No properties, no header or anything else. See the JMSMessage aka MQRFH2 screenshot of the breakdown of the message:



abhay09 wrote:
mqrfh2.setFormat(MQC.MQFMT_RF_HEADER_2); // Following this header will be another rfh2 header

Wrong, wrong, wrong. This says that your MQRFH2 message data will contain another MQRFH2 message. i.e. You are chaining messages together.

- If you want JMSBytesMessage then you mqrfh2.setFormat to CMQC.MQFMT_NONE
- If you want JMSTextMessage then you mqrfh2.setFormat to CMQC.MQFMT_STRING

abhay09 wrote:
by above code we can add anythng in JMSBytesMessage.
folderBytes above here is could be any property.

The message data can contain anything you want for JMSBytesMessage. Again, you don't know what you are doing because a MQRFH2 folder is NOT the same thing as NameValueData.

abhay09 wrote:
mqrfh2.setNameValueData(folderBytes);

Clearly, you have not tested this because NameValueData is NOT folder data. Please read NameValueData here. NameValueData is not like the XML folder data. It looks like "A1 123 B1 456 C1 333".

For folder data, you would use setFolder... method(s).

abhay09 wrote:
So, one last time can you also confirm without being rude

You don't read the manual, you don't listen to what people tell you and you wonder why I'm getting annoyed. Now I understand why Homer strangles Bart.



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
Display posts from previous:   
Post new topic  Reply to topic Goto page Previous  1, 2 Page 2 of 2

MQSeries.net Forum Index » IBM MQ Java / JMS » Reading and writing RFH headers using MQJMS API
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.