Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set 'x-message-ttl' in pika python

I want to set the TTL to 1 sec for a Rabbitmq queue using pika. I tried the following code

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

I am getting the following error

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))

I am trying to dead-letter all the messages in this particular queue after 1 sec. Can I know how to set the TTL using Pika? Thanks!

like image 322
Kvik Avatar asked Sep 04 '16 13:09

Kvik


1 Answers

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

you don't need the cast

like image 106
Gabriele Santomaggio Avatar answered Oct 31 '22 08:10

Gabriele Santomaggio