我正在调试一些使用Apache POI的Java代码从Microsoft Office文档中提取数据。偶尔遇到一个大文件,当内存不足时,POI会崩溃。此时,它尝试将错误发布到RabbitMQ,以便其他组件可以知道此步骤失败并采取适当的操作。但是,当它尝试发布到队列时,它会得到一个com.rabbitmq.client.AlreadyClosedException(干净的连接关闭;原因:尝试使用封闭的通道)。
这是错误处理程序代码:
try {
//Extraction and indexing code
}
catch(Throwable t) {
// Something went wrong! We'll publish the error and then move on with
// our lives
System.out.println("Error received when indexing message: ");
t.printStackTrace();
System.out.println();
String error = PrintExc.format(t);
message.put("error", error);
if(mime == null) {
mime = "application/vnd.unknown";
}
message.put("mime", mime);
publish("IndexFailure", "", MessageProperties.PERSISTENT_BASIC, message);
}
为了完整,这里是发布方法:
private void publish(String exch, String route,
AMQP.BasicProperties props, Map message) throws Exception{
chan.basicPublish(exch, route, props,
JSONValue.toJSONString(message).getBytes());
}
在try块中找不到关闭RabbitMQ通道的任何代码。有什么情况可以暗示关闭频道?
编辑:我应该注意,AlreadyClosedException是由publish中的basicPublish调用抛出的。