Author |
Message
|
inditrozen |
Posted: Tue Oct 06, 2009 7:50 am Post subject: javax.jms api for writing and MQSeries api for reading |
|
|
Newbie
Joined: 06 Oct 2009 Posts: 3
|
Hi All,
Requirement is to write the pdf file to the Queue using javax.jms api.and read from the environment where MQQueueSeries API is avaiable.
If I try to read the message I get some additional text in addition to the written string.
Here are the code samples. Here I have tried writing the simple String to the Queue.
Writing to the Queue.
jndiContext = new InitialContext();
queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup(JMS_FACTORY);
replyQueue = (Queue) jndiContext.lookup(JMS_QUEUE_REPLY);
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(replyQueue);
queueConnection.start();
ObjectMessage msg = queueSession.createObjectMessage();
String str = "Some message";
msg.setObject(str);
queueSender.send(msg);
Reading from the queue.
MQMessage mqMsg = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
mqQueue.get(mqMsg, gmo);
int len = mqMsg.getDataLength();
byte[] message = new byte[len];
mqMsg.readFully(message, 0, len);
String result = new String(message)
Result String shows me something like this.
RFH ä ¸ ¸
<mcd><Msd>jms_object</Msd></mcd> ˜
<jms><Dst>queue://QUEUE_DETAILS?expiry=300000&persistence=1</Dst><Tms>1254843772899</Tms><Exp>1254844072899</Exp><Dlv>1</Dlv></jms>
ˆ t
Some message
I consider the part before the String "Some message" is some header. How can I seperate it from my String.
Thanks in advance looking forward for answer.
Best Regards
Prasad |
|
Back to top |
|
 |
Vitor |
Posted: Tue Oct 06, 2009 7:59 am Post subject: Re: javax.jms api for writing and MQSeries api for reading |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
inditrozen wrote: |
I consider the part before the String "Some message" is some header. How can I seperate it from my String.
|
The "some header" is the WMQ representation of the JMS header, included automatically because you've written the message using a JMS method.
You have 2 options:
- have the application that reads the message ignore the header; it's a known format (base WMQ calls it an RFH2) and it contains (among other things) it's own length
- have the sending application omit the header by specifying the message is for a non-JMS receipient.
Up to you which end you fix. The Java manuals & Application Programming Reference contain all the information you need. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Oct 06, 2009 8:09 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
The fastest way to fix this is to specify in the JNDI layer that your destination is of type targetClient=1 or use targetClient = MQ... depending on the JNDI type provider you used.
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
inditrozen |
Posted: Wed Oct 07, 2009 6:04 am Post subject: |
|
|
Newbie
Joined: 06 Oct 2009 Posts: 3
|
Thanks for the tip.
Putting targetclient=MQ has changed the message string as following. Still there is something else in the begining of the message. It does not look like JMS Header.
Please see below.
¬à ur [B¬óøTà xp Some Message
How can I get rid of that?
My requirement is to write zip file using JMS api to the MQQueue and read the message(zip file) using MQQueueSeries API. With the code in the original post, am I on the correct path?
Best Regards
Prasad |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Oct 07, 2009 6:33 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
What is the difference between an ObjectMessage, a BytesMessage, and a TextMessage?
Which one did you send?
Which one contains text data that can be simply displayed when you print it?
Which one is most suited to containing mixed content like a PDF document or a Zip file? |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Oct 07, 2009 7:33 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Additionally... What makes you think that the content of the zip file you put to the message should be readable in clear text?  _________________ MQ & Broker admin |
|
Back to top |
|
 |
inditrozen |
Posted: Thu Oct 08, 2009 1:52 am Post subject: |
|
|
Newbie
Joined: 06 Oct 2009 Posts: 3
|
Thanks for the reponses.
@mqjeff :- Using ByteMessage solved the problem. Thanks for the tip.
@fjb_saper:- Using targetclient solve the problem so thanks for that. Regarding clear text, I never though of reading the zip file as a clear text. If you look at the code sample there I was writing a plain string to the queue and wanted to read it as a clear text. It was just done for testing. My final requirement was to write a zip file to the queue and read it on the other side and save it as a zip file on file system.
Now everything is working except files bigger than 5 MB. I get reason code 2030. Here I think Queue Admin will have to change some settings.
Thanks and Regds
Prasad |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Oct 08, 2009 1:56 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You may also find it challenging to understand when the zip file is "ready" to be read.
This is a very good reason for using something like MQFTE instead of writing it yourself. |
|
Back to top |
|
 |
|