【发布时间】:2012-01-12 17:03:42
【问题描述】:
我正在调试一些使用 Apache POI 从 Microsoft Office 文档中提取数据的 Java 代码。偶尔会遇到大文档,内存不足时POI崩溃。此时,它会尝试将错误发布到 RabbitMQ,以便其他组件可以知道此步骤失败并采取适当的措施。但是,当它尝试发布到队列时,它会得到一个com.rabbitmq.client.AlreadyClosedException (clean connection shutdown; reason: Attempt to use closed channel)。
这是错误处理程序代码:
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<String, Object> message) throws Exception{
chan.basicPublish(exch, route, props,
JSONValue.toJSONString(message).getBytes());
}
我在 try 块中找不到任何似乎关闭 RabbitMQ 通道的代码。有没有可以隐式关闭通道的情况?
编辑:我应该注意,AlreadyClosedException 是由发布内部的basicPublish 调用引发的。
【问题讨论】:
-
你是如何解决这个问题的?