为什么我的 RabbitMQ 频道不断关闭?
我正在调试一些使用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());
}
我在尝试块中找不到任何似乎关闭RabbitMQ通道的代码。是否有任何情况下可以隐式关闭通道?
编辑:我应该注意,已经关闭的异常是由发布内部的调用抛出的。basicPublish