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 » javax.jms api for writing and MQSeries api for reading

Post new topic  Reply to topic
 javax.jms api for writing and MQSeries api for reading « View previous topic :: View next topic » 
Author Message
inditrozen
PostPosted: Tue Oct 06, 2009 7:50 am    Post subject: javax.jms api for writing and MQSeries api for reading Reply with quote

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&amp;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
View user's profile Send private message
Vitor
PostPosted: Tue Oct 06, 2009 7:59 am    Post subject: Re: javax.jms api for writing and MQSeries api for reading Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Tue Oct 06, 2009 8:09 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
inditrozen
PostPosted: Wed Oct 07, 2009 6:04 am    Post subject: Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Wed Oct 07, 2009 6:33 am    Post subject: Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Wed Oct 07, 2009 7:33 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
inditrozen
PostPosted: Thu Oct 08, 2009 1:52 am    Post subject: Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Thu Oct 08, 2009 1:56 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » javax.jms api for writing and MQSeries api for reading
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.