我们有从Rabbit队列读取的Clojure代码。我们想容忍RabbitMQ服务器短暂停机的情况,例如在重新启动的情况下(sudo service rabbitmq-server restart)。

在Langohr中似乎有some provision for reconnecting。我们修改了示例clojurewerkz.langohr.examples.recovery.example1(Gist here)。与已发布的示例之间的细微差别包括连接参数和lb/publish调用的删除(因为我们正在使用外部源填充数据)。

我们可以成功地使用队列中的数据,并等待更多消息。但是,当我们重新启动RMQ时(通过托管RabbitMQ的VM上的上述sudo命令),将引发以下异常:

Caught an exception during connection recovery!
java.io.IOException
    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
    at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:378)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:516)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:545)
    at com.novemberain.langohr.Connection.recoverConnection(Connection.java:166)
    at com.novemberain.langohr.Connection.beginAutomaticRecovery(Connection.java:115)
    at com.novemberain.langohr.Connection.access$000(Connection.java:18)
    at com.novemberain.langohr.Connection$1.shutdownCompleted(Connection.java:93)
    at com.rabbitmq.client.impl.ShutdownNotifierComponent.notifyListeners(ShutdownNotifierComponent.java:75)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:573)
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; reason: java.io.EOFException
    at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
    at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
    at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343)
    at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:321)
    ... 8 more
Caused by: java.io.EOFException
    at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:273)
    at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95)
    at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:131)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:533)

Langohr提供的预期重启机制似乎在启动时就被破坏了。在这些“硬”重启的情况下,是否有替代模式是首选的吗?另外,我想我们必须实现连接监视并自己重试。任何建议将是最欢迎的。

最佳答案

我们曾经看到过这样的堆栈跟踪,但是在Langohr 2.9.0中我们不再看到它们。重新启动后,clojure客户端重新连接,消息再次开始流动。

我们正在使用默认值,这些默认值已打开连接和拓扑覆盖,如下所示:

(infof "Automatic recovery enabled? %s" (rmq/automatic-recovery-enabled? connection))
(infof "Topology recovery enabled? %s" (rmq/automatic-topology-recovery-enabled? connection))

关于clojure - 如何忍受Langohr中RabbitMQ的重启?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23278332/

10-10 02:34