本文介绍了为什么我的RabbitMQ频道会继续关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试一些使用Apache POI从Microsoft Office文档中提取数据的Java代码。有时,当内存不足时,它会遇到大文档和POI崩溃。此时,它会尝试将错误发布到RabbitMQ,以便其他组件可以知道此步骤失败并采取适当的操作。但是,当它尝试发布到队列时,它会得到 com.rabbitmq.client.AlreadyClosedException(清除连接关闭;原因:尝试使用已关闭的通道)

I'm debugging some Java code that uses Apache POI to pull data out of Microsoft Office documents. Occasionally, it encounter a large document and POI crashes when it runs out of memory. At that point, it tries to publish the error to RabbitMQ, so that other components can know that this step failed and take the appropriate actions. However, when it tries to publish to the queue, it gets a com.rabbitmq.client.AlreadyClosedException (clean connection shutdown; reason: Attempt to use closed channel).

这是错误处理程序代码:

Here's the error handler code:

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);
}

为了完整性,这是发布方法:

For completeness, here's the publish method:

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频道。在任何情况下都可以隐式关闭频道吗?

I can't find any code within the try block that appears to close the RabbitMQ channel. Are there any circumstances in which the channel could be closed implicitly?

编辑:我应该注意到<$ c抛出了AlreadyClosedException $ c> basicPublish 在发布内部调用。

EDIT: I should note that the AlreadyClosedException is thrown by the basicPublish call inside publish.

推荐答案

AMQP频道因频道错误而关闭。可能导致频道错误的两个常见问题:

An AMQP channel is closed on a channel error. Two common things that can cause a channel error:


  • 尝试将邮件发布到不存在的交易所

  • 尝试发布一条消息,其中立即标志设置没有具有活动消费者集的队列

我将研究在您尝试使用以捕获关闭事件并看看是什么导致了它。

I would look into setting up a ShutdownListener on the channel you're trying to use to publish a message using the addShutdownListener() to catch the shutdown event and look at what caused it.

这篇关于为什么我的RabbitMQ频道会继续关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:22