【问题标题】:set 'x-message-ttl' in pika python在 pika python 中设置'x-message-ttl'
【发布时间】:2017-01-12 01:08:57
【问题描述】:

我想使用 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 吗?谢谢!

【问题讨论】:

    标签: python-2.7 rabbitmq pika


    【解决方案1】:
    connection = pika.BlockingConnection(pika.ConnectionParameters(
           host='localhost'))
    channel = connection.channel()
    this=channel.queue_declare(queue='hello',
                                arguments={'x-message-ttl' : 1000}
                                )
    

    你不需要演员表

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-27
      • 1970-01-01
      相关资源
      最近更新 更多