You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by A K <ma...@gmail.com> on 2019/08/29 09:04:58 UTC

Need help to fix "javax.jms.MessageNotReadableException: Message body is write-only"

Hi Timothy And Team,



I posted below details through web ui
http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html  but
latest comment and new topic is not reflecting on UI. I think, there is
some issue on UI.

#######


We are having one issue, so need your to help to fix this issue.

As per your suggestion on issue -
http://qpid.2158936.n2.nabble.com/Better-way-to-handle-MessageNotWriteableException-Message-is-currently-read-only-td7684002.html
,

i am creating JMSMessage again whenever producer failed to send message.

For achieving this scenario, i need to extract(read) message content from
original JMS message. While extracting message content for
JmsBytesMessage/JmsStreamMessage,  i am getting error
"javax.jms.MessageNotReadableException: Message body is write-only".

I also did similar testing for JmsTextMessage, JmsMapMessage,
JmsObjectMessage but there is no issue in these type of messages. We are
having issue only for JmsStreamMessage and JmsBytesMessage.

I did testing with "qpid-jms-client-0.40.0", "qpid-jms-client-0.43.0" and
"qpid-jms-client-0.45.0". Having same issue in all three of jars.

Please find attached error stack trace “JmsBytesMessage_Error.txt” and
“JmsStreamMessage_Error.txt”.

How To reproduce this issue ? – I did testing with ServiceBus.
1. First send message to Queue
2. Disable Queue/topic
3. Enable Queue/topic
4. Send message again which will throw error
“javax.jms.MessageNotReadableException: Message body is write-only”

Please find below code snippet for JmsBytesMessage

try {
        sendMessage(message);
} catch (IllegalStateException illegalStateException) {
        // Reset Producer due to Idle TimeOut after 10m
        resetProducer();

        Message recreatedMessage = reCreateMessage(message);
        sendMessage(recreatedMessage);
}

Public Message reCreateMessage(Message message){
        byte[] content = getMessageContent(message);

        BytesMessage bMsg = session.createBytesMessage();
        bMsg.writeBytes(content);

        return bMsg;
}

Public byte[] getMessageContent(Message message){
        BytesMessage message = (JmsBytesMessage)message;
        byte[] bytes = new byte[(int) message.getBodyLength()];
        message.readBytes(bytes);
        return bytes;
}



Please let me know if you need any details.

Regards,
Abhishek Kumar

Re: Need help to fix "javax.jms.MessageNotReadableException: Message body is write-only"

Posted by Robbie Gemmell <ro...@gmail.com>.
Unlike the other message types, BytesMessage and StreamMessage
instances can be write-only at a given point, and are upon creation
for send, so I think you need to call reset() if you want to read them
in this case:

https://docs.oracle.com/javaee/7/api/javax/jms/BytesMessage.html
https://docs.oracle.com/javaee/7/api/javax/jms/StreamMessage.html

Robbie

On Thu, 29 Aug 2019 at 10:05, A K <ma...@gmail.com> wrote:
>
> Hi Timothy And Team,
>
>
>
> I posted below details through web ui http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html  but latest comment and new topic is not reflecting on UI. I think, there is some issue on UI.
>
> #######
>
>
> We are having one issue, so need your to help to fix this issue.
>
> As per your suggestion on issue - http://qpid.2158936.n2.nabble.com/Better-way-to-handle-MessageNotWriteableException-Message-is-currently-read-only-td7684002.html,
>
> i am creating JMSMessage again whenever producer failed to send message.
>
> For achieving this scenario, i need to extract(read) message content from original JMS message. While extracting message content for JmsBytesMessage/JmsStreamMessage,  i am getting error "javax.jms.MessageNotReadableException: Message body is write-only".
>
> I also did similar testing for JmsTextMessage, JmsMapMessage, JmsObjectMessage but there is no issue in these type of messages. We are having issue only for JmsStreamMessage and JmsBytesMessage.
>
> I did testing with "qpid-jms-client-0.40.0", "qpid-jms-client-0.43.0" and "qpid-jms-client-0.45.0". Having same issue in all three of jars.
>
> Please find attached error stack trace “JmsBytesMessage_Error.txt” and “JmsStreamMessage_Error.txt”.
>
> How To reproduce this issue ? – I did testing with ServiceBus.
> 1. First send message to Queue
> 2. Disable Queue/topic
> 3. Enable Queue/topic
> 4. Send message again which will throw error “javax.jms.MessageNotReadableException: Message body is write-only”
>
> Please find below code snippet for JmsBytesMessage
>
> try {
>         sendMessage(message);
> } catch (IllegalStateException illegalStateException) {
>         // Reset Producer due to Idle TimeOut after 10m
>         resetProducer();
>
>         Message recreatedMessage = reCreateMessage(message);
>         sendMessage(recreatedMessage);
> }
>
> Public Message reCreateMessage(Message message){
>         byte[] content = getMessageContent(message);
>
>         BytesMessage bMsg = session.createBytesMessage();
>         bMsg.writeBytes(content);
>
>         return bMsg;
> }
>
> Public byte[] getMessageContent(Message message){
>         BytesMessage message = (JmsBytesMessage)message;
>         byte[] bytes = new byte[(int) message.getBodyLength()];
>         message.readBytes(bytes);
>         return bytes;
> }
>
>
>
> Please let me know if you need any details.
>
> Regards,
> Abhishek Kumar
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: Need help to fix "javax.jms.MessageNotReadableException: Message body is write-only"

Posted by Timothy Bish <ta...@gmail.com>.
On 8/29/19 5:04 AM, A K wrote:
>
> Hi Timothy And Team,
>
> I posted below details through web ui 
> http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html  but 
> latest comment and new topic is not reflecting on UI. I think, there 
> is some issue on UI.
>
> #######
>
>
> We are having one issue, so need your to help to fix this issue.
>
> As per your suggestion on issue - 
> http://qpid.2158936.n2.nabble.com/Better-way-to-handle-MessageNotWriteableException-Message-is-currently-read-only-td7684002.html,
>
> i am creating JMSMessage again whenever producer failed to send message.
>
> For achieving this scenario, i need to extract(read) message content 
> from original JMS message. While extracting message content for 
> JmsBytesMessage/JmsStreamMessage,  i am getting error 
> "javax.jms.MessageNotReadableException: Message body is write-only".
>
The information provided isn't enough to come to any conclusion on what 
may be going on with the state of the message.  I'd suggest gathering 
some logging and AMQP frame traces when you reproduce this to aid in 
seeing what the client is doing and what the conditions are that cause 
the message to not be in a readable state.  See the logging docs: 
http://qpid.apache.org/releases/qpid-jms-0.45.0/docs/index.html#logging

You could also try and create a simple reproducer using the existing 
client unit tests as a model.  There was a test case added for 
QPIDJMS-457 that covered the scenario in that issue where the message 
was not restored to readable.

https://github.com/apache/qpid-jms/blob/master/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java#L3124


> I also did similar testing for JmsTextMessage, JmsMapMessage, 
> JmsObjectMessage but there is no issue in these type of messages. We 
> are having issue only for JmsStreamMessage and JmsBytesMessage.
>
> I did testing with "qpid-jms-client-0.40.0", "qpid-jms-client-0.43.0" 
> and "qpid-jms-client-0.45.0". Having same issue in all three of jars.
>
> Please find attached error stack trace “JmsBytesMessage_Error.txt” and 
> “JmsStreamMessage_Error.txt”.
>
> How To reproduce this issue ? – I did testing with ServiceBus.
> 1. First send message to Queue
> 2. Disable Queue/topic
> 3. Enable Queue/topic
> 4. Send message again which will throw error 
> “javax.jms.MessageNotReadableException: Message body is write-only”
>
> Please find below code snippet for JmsBytesMessage
>
> try {
> sendMessage(message);
> } catch (IllegalStateException illegalStateException) {
>       // Reset Producer due to Idle TimeOut after 10m
> resetProducer();
>
>       Message recreatedMessage = reCreateMessage(message);
> sendMessage(recreatedMessage);
> }
>
> Public Message reCreateMessage(Message message){
>       byte[] content = getMessageContent(message);
>
>       BytesMessage bMsg = session.createBytesMessage();
> bMsg.writeBytes(content);
>
>       return bMsg;
> }
>
> Public byte[] getMessageContent(Message message){
>       BytesMessage message = (JmsBytesMessage)message;
>       byte[] bytes = new byte[(int) message.getBodyLength()];
> message.readBytes(bytes);
>       return bytes;
> }
>
> Please let me know if you need any details.
>
> Regards,
> Abhishek Kumar
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org


-- 
Tim Bish