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 <[email protected]> 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: [email protected] > For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
