在鼠兔 python 中设置 'x-message-ttl'

set 'x-message-ttl' in pika python

我想使用 pika 将 Rabbitmq 队列的 TTL 设置为 1 秒。 我尝试了以下代码

import ctypes
int32=ctypes.c_int
connection = pika.BlockingConnection(pika.ConnectionParameters(
       host='localhost'))
channel = connection.channel()
this=channel.queue_declare(queue='hello',
                            arguments={'x-message-ttl' : int32(1000)}
                            )

channel.basic_publish(exchange='',
               routing_key='hello',
               body=message)

print this.method.consumer_count

我收到以下错误

Traceback (most recent call last):
  File "rabt.py", line 8, in <module>
    arguments={'x-message-ttl' : int32(1000)}
  File "build\bdist.win32\egg\pika\adapters\blocking_connection.py", line 2397, in queue_declare
  File "build\bdist.win32\egg\pika\channel.py", line 815, in queue_declare
  File "build\bdist.win32\egg\pika\channel.py", line 1312, in _rpc
  File "build\bdist.win32\egg\pika\channel.py", line 1324, in _send_method
  File "build\bdist.win32\egg\pika\connection.py", line 2139, in _send_method
  File "build\bdist.win32\egg\pika\connection.py", line 2119, in _send_frame
  File "build\bdist.win32\egg\pika\frame.py", line 74, in marshal
  File "build\bdist.win32\egg\pika\spec.py", line 1015, in encode
  File "build\bdist.win32\egg\pika\data.py", line 85, in encode_table
  File "build\bdist.win32\egg\pika\data.py", line 153, in encode_value
pika.exceptions.UnsupportedAMQPFieldException: (['\x00\x00', '\x05', 'hello', '\x00', None, '\r', 'x-message-ttl'], c_long(1000))

我正在尝试在 1 秒后将此特定队列中的所有消息设为死信。我能知道如何使用 Pika 设置 TTL 吗?谢谢!

connection = pika.BlockingConnection(pika.ConnectionParameters(
       host='localhost'))
channel = connection.channel()
this=channel.queue_declare(queue='hello',
                            arguments={'x-message-ttl' : 1000}
                            )

你不需要强制转换