rabbitAck(knowledging)时,rabbitMQ AlreadyClosedException

时间:2015-11-04 20:08:26

标签: grails groovy rabbitmq

我的groovy代码使用Rabbit Native Plugin作为grails:

def handleMessage(def body, MessageContext context) {
    // With noAck=false, messages must be acknowledged manually with basic.ack.
    boolean noAck = false
    // send Ack on true and nack on false
    if(processMessage(new SensorEvent(body))){
           context.channel.basicAck(context.getEnvelope().getDeliveryTag(),noAck)
    }else{
        context.channel.basicNack(context.getEnvelope().getDeliveryTag(), false, false);

    }
    return ''
}

如果我注释掉执行Ack和Nack的两行代码,一切正常。如果我取消注释basicAck,我会得到以下异常

com.rabbitmq.client.AlreadyClosedException: channel is already closed due to channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - unknown delivery tag 1, class-id=60, method-id=80)
at com.rabbitmq.client.impl.AMQChannel.ensureIsOpen(AMQChannel.java:195)
at com.rabbitmq.client.impl.AMQChannel.transmit(AMQChannel.java:309)
at com.rabbitmq.client.impl.AMQChannel.transmit(AMQChannel.java:303)
at com.rabbitmq.client.impl.ChannelN.basicReject(ChannelN.java:1045)
at com.rabbitmq.client.impl.recovery.RecoveryAwareChannelN.basicReject(RecoveryAwareChannelN.java:72)
at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.basicReject(AutorecoveringChannel.java:354)

我见过使用Subscription.Ack()的建议。 Java / Groovy rabbitMQ中没有Subscription类。

知道为什么我会得到例外吗?

编辑:因为我正在使用Native Plugin,所以我需要创建一个实现接口的消费者

def handleMessage(def body, MessageContext context)

订阅的处理方式为:

 /**
 * Consumer configuration.
 */
static rabbitConfig = [
        "queue": "my.queueName"
]

1 个答案:

答案 0 :(得分:0)

此错误:

  

PRECONDITION_FAILED - 未知交货标签1,

表示您尝试在与收到该消息的频道不同的频道上发送消息。交付标签的每个频道范围