English 中文(简体)
如何在JMS活性MQ Artemis中获取一个星号的信息?
原标题:How to get the body of a byte message in JMS ActiveMQ Artemis?

我有一条从JMS的电文中获取信息的法典,但我不理解,如果信息是灵丹妙的,如何将其转化为<条码>。

connectQueueBrowser();
Enumeration<Message> messageEnumeration =  queueBrowser.getEnumeration();
ArrayList<Message> messages = new ArrayList<>();
while (messageEnumeration.hasMoreElements()){
   messages.add(messageEnumeration.nextElement());
}
System.out.println(messages.get(0).getBody(String.class));

这是我发现的错误:

javax.jms.MessageFormatException: Body not assignable to class java.lang.String

但是,当我显示身体信息时,我就错了。

问题回答

如果您寄送了“JMS BytesMessage,则您可使用 only usegetBody with byte [].},例如:

System.out.println(messages.get(0).getBody(byte[].class));

If you ve serialized a Java String into the BytesMessage using something like this:

bytesMessage.writeBytes(myString.getBytes(StandardCharsets.UTF_8));

Then you ll be able to deserialize that String from the BytesMessage using something like this:

byte[] myBytes = new byte[(int)bytesMessage.getBodyLength()];
bytesMessage.readBytes(myBytes);      
String myString = new String(myBytes, StandardCharsets.UTF_8);




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签