首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

12.3 使用ActiveMQ 源

2013-12-22 
12.3 使用ActiveMQ 流ensure that only one consumer will be reading the stream at a time. We read the

12.3 使用ActiveMQ 流

ensure that only one consumer will be reading the stream at a time. We read the

ActiveMQ InputStream and then write it to a FileOutputStream to reassemble the

file on disk. Note that we expect the end of the file to be denoted by the end of the

stream (or -1).

?

在上面的示例代码中,我们创建了一个ActiveMQConnection,并再此基础上创建了一个

Input-Stream使用一个队列作为消费者. 需要注意的是,我们在队列名称后面加上了

"?consumer.exclusive=true"了创建一个排他性的消息消费者.这样做是为了确保同一

时刻只有一个消费者可以读取流.读取了ActiveMQ的InputStream后,将其写入到

FileOutputStream中以便重新组装流并写入到磁盘文件中.注意,我们希望通过流的末

尾(或者读取到-1)来确定文件的结尾.

?

You can use streams with topics too—though if a consumer for a topic starts partway

through the delivery of a stream, it won’t receive any data that was sent before it

was started.

?

你也可以在主题中使用流--但,如果消息消费者在流已经开始传送后的中途启动,则该消费者将不会

收到任何在它启动之前就已经发送过的任何数据.

?

ActiveMQ breaks the stream into manageable chunks of data and sends each

chunk of data as a separate message. This means that you have to be careful when

using them, because if the message consumer should fail partway through reading the

InputStream, there’s currently no way to replay the messages already consumed by

the failed message consumer.

?

ActiveMQ将流分成可管理的数据块然后将所有的数据块作为独立的消息发送.这就意味着你在使用

流时必须十分小心.因为如果消息消费者在读取InputStream的中途失效了,则是前期的消息消费者已经

读取的消费无法重现了.

?

ActiveMQ streams are useful for transferring large payloads, though you’ll need to

think about how an application using ActiveMQ streams should handle failure scenarios.

There’s an alternative and more robust method of sending large payloads: using

blob messages, which we cover in the next section.

?

ActiveMQ流对于传输大尺寸负载来说十分有用,尽管你需要仔细思考,以应对使用ActiveMQ流的应用程序的失效场景.

对于发送给大尺寸负载来说还有一种更加健壮的替代方法,即使用二进制消息,我们将在下一节中介绍.

?

热点排行