|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
No tags in StreamMessage |
« View previous topic :: View next topic » |
Author |
Message
|
ramzi |
Posted: Thu Apr 20, 2006 12:12 am Post subject: No tags in StreamMessage |
|
|
 Novice
Joined: 16 Aug 2004 Posts: 19 Location: France
|
Hi all,
I'm currently trying to send big files into MQ and I don't want to load a 5Mo String into a TextMessage.
To load the file in a smart way, I use the JMSStreamMessage and it works fine. Here's the code:
Code: |
JMSStreamMessage message = (JMSStreamMessage)session.createStreamMessage();
// Ecriture avec BufferedReader
FileReader fileReader = new FileReader("file/test.txt");
BufferedReader reader = new BufferedReader(fileReader);
StringBuffer sb = new StringBuffer();
String s = null;
while ((s = reader.readLine()) != null)
message.writeString(s);
fileReader.close();
reader.close();
sender = session.createSender(queue);
sender.send(message);
|
Unfortunately the JMSStreamMessage adds <stream> and <elt> in the message text. Here's a sample of the body:
Code: |
<stream><elt>Hello World</elt>
<elt>afzlzejezjlezkjrezlkrjelkjerlkejzrlkjrlklkjlkzjerlkzjelkjrzr</elt>
<elt>zerzelkrjzelkrjzlekjrelkr:;f!:ze;f!z;fùmzefzemflkf</elt>
<elt>zefml,lsn,dlsjflkzejlkzejrzlkj</elt></stream> |
My problem is that I don't want those tags.
Is there any way to avoid the StreamMessage adding those tags?
Any tips will be highly appreciated !!
Cheeers,
Ramzi |
|
Back to top |
|
 |
briancop |
Posted: Thu Apr 20, 2006 12:23 am Post subject: |
|
|
 Apprentice
Joined: 04 Apr 2005 Posts: 28 Location: Hursley, UK
|
It looks to me like you don't want to use StreamMessage. The idea of a StreamMessage is that it contains a sequence of formatted elements, each of which is identified as having a particular type. e.g. a stream of String, Int, String, Long, Float, Float, ByteArray, String, String.
If you want a straight sequence of bytes, you have 2 choices: TextMessage (where you need to load all the text into a single character array and set this as your text body, which you say you want to avoid, understandably). TextMessages have the advantage that they can undergo codepage conversion if required. Or BytesMessage (completely unformatted - MQ and JMS make no assumptions about, or modifications to, the byte stream). You don't get any codepage conversion etc., but you can load the message body in chunks, typically using writeBytes(), or perhaps writeUTF() if the string is in UTF8.
From your description, it would seem that a BytesMessage populated by a sequence of writeBytes() calls would do the trick. At the receiving application, get the message as a BytesMessage and read the body in chunks using a sequence of readBytes() calls, keeping going until the readBytes() call tells you it has read less than the specified buffer size, which indicates that it has run out of bytes to read. |
|
Back to top |
|
 |
ramzi |
Posted: Thu Apr 20, 2006 12:37 am Post subject: Thanks |
|
|
 Novice
Joined: 16 Aug 2004 Posts: 19 Location: France
|
Thanks Brian, I'll try to test with ByteMessage using writeUTF() and readUTF() |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|