鼠兔添加 headers 到 nack 响应

pika add headers to nack response

我正在使用

修改鼠兔 headers
properties.headers = {
     'myheader': myheader
}

但我正在与 delivery_tag

channel.basic_nack(delivery_tag=delivery_tag, requeue=False)

如何将带有 headers 的更新属性传递给 ack 和 nack 响应函数?或者鼠兔的做法是什么?

摘自 pika docs 说您拼写错误 basic_nck... 只是问题错误还是您的实际问题?

def basic_nack(self, delivery_tag=None, multiple=False, requeue=True):
        """This method allows a client to reject one or more incoming messages.
        It can be used to interrupt and cancel large incoming messages, or
        return untreatable messages to their original queue.

        :param integer delivery-tag: int/long The server-assigned delivery tag
        :param bool multiple: If set to True, the delivery tag is treated as
                              "up to and including", so that multiple messages
                              can be acknowledged with a single method. If set
                              to False, the delivery tag refers to a single
                              message. If the multiple field is 1, and the
                              delivery tag is zero, this indicates
                              acknowledgement of all outstanding messages.
        :param bool requeue: If requeue is true, the server will attempt to
                             requeue the message. If requeue is false or the
                             requeue attempt fails the messages are discarded or
                             dead-lettered.

        """
        self._raise_if_not_open()
        return self._send_method(
            spec.Basic.Nack(delivery_tag, multiple, requeue))

很抱歉,但据我所知,basic_nack(或basic_ack)不可能修改headers。问题是 modified 消息将被放入死信 queue 中,而新消息具有更新的 ID。

L-

正确的是basic_nack不能改变headers。

这样做的方法是根本不使用 NACK,而是生成 return 一条 'new' 消息(这只是您正在处理的当前消息,但是添加新的headers)。

根据 AMQP 规范,NACK 似乎基本上是这样做的。

所以我的逻辑是在成功时使用 basic_ack,在失败时使用更新的 headers 来生成消息。在我的例子中,我 'redirect' 将新消息发送到死信 queue 绑定到的死信交换。