简体   繁体   English

如何将任何InputStream发送到JMS Queue?

[英]How to send any InputStream to JMS Queue?

It is not sending it because InputStream is not Serializable. 它不发送它,因为InputStream不可序列化。 Is there any option to do this? 有什么选择吗? Different InputStreams will contain different sources to read from so it's better if I can send InputStream directly to JMS queue. 不同的InputStreams将包含不同的源以供读取,因此最好将InputStream直接发送到JMS队列。

You cannot send a stream, you have to "materialize" it before: 您无法发送流,必须先“实现”它:

  1. Read the stream into a byte array 将流读入字节数组
  2. Use a BytesMessage : See writeBytes 使用BytesMessage :请参阅writeBytes

As an alternative have a look at this BytesMessageOutputStream : This way you should be able to stream, however the BytesMessage probably needs to buffer anyway. 作为替代方案,请查看此BytesMessageOutputStream :这样,您应该可以流式传输,但是BytesMessage可能仍然需要缓冲。

An inputstream generally points to some resource. 输入流通常指向某些资源。 This resource might not be available to the consumer of your queue. 队列的使用者可能无法使用此资源。

You can convert your inputstream to a byte[] which represents the loaded resource and send it that way. 您可以将输入流转换为代表已加载资源的byte[]并以这种方式发送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM