有没有一种方法可以把一个大文件放到JMS队列中,而不把整个文件加载到内存中?假设文件大小为100MB,我可以将其流式输入和输出队列,还是必须将整个字节数组加载到内存中?
发布于 2012-01-24 04:11:53
JMS不直接支持这一点。但是也有一些支持JMS的实现,比如支持传递流的Apache ActiveMQ。有关详细信息,请参阅ActiveMQ站点上的this page。
发布于 2012-01-24 04:25:20
您可以做的是将Apache Camel与您的消息代理结合使用。
利用企业集成模式here,您可以将文件存放在中央存储中。然后,消息(声明的标头和引用)将像普通消息一样通过代理发送。然后,在传递消息时,可以再次拾取该文件。
例如:
<route>
<from uri="direct:start"/>
<pipeline>
<to uri="bean:checkLuggage"/>
<to uri="mock:testCheckpoint"/>
<to uri="bean:dataEnricher"/>
<to uri="mock:result"/>
</pipeline>
</route>
其中checkLuggage
如下所示:
public static final class CheckLuggageBean {
public void checkLuggage(Exchange exchange, @Body String body, @XPath("/order/@custId") String custId) {
// store the message body into the data store, using the custId as the claim check
dataStore.put(custId, body);
// add the claim check as a header
exchange.getIn().setHeader("claimCheck", custId);
// remove the body from the message
exchange.getIn().setBody(null);
}
}
dataEnricher
看起来像这样:
public static final class DataEnricherBean {
public void addDataBackIn(Exchange exchange, @Header("claimCheck") String claimCheck) {
// query the data store using the claim check as the key and add the data
// back into the message body
exchange.getIn().setBody(dataStore.get(claimCheck));
// remove the message data from the data store
dataStore.remove(claimCheck);
// remove the claim check header
exchange.getIn().removeHeader("claimCheck");
}
}
https://stackoverflow.com/questions/8977819
复制相似问题