Commit 267ba53d authored by Christos Stavrakakis's avatar Christos Stavrakakis

snf-common: Suport 'Queue TTL' in AMQP clients

Extend the AMQP clients to support RabbitMQ's 'Queue TTL' extension, by
passing the 'x-expires' argument when declaring a queue. This argument
controls for how long a queue can be unused before it is automatically
deleted.
parent 1dd1cffe
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -142,7 +142,7 @@ class AMQPHaighaClient():
auto_delete=False, durable=True)
def queue_declare(self, queue, exclusive=False, mirrored=True,
mirrored_nodes='all'):
mirrored_nodes='all', ttl=None):
"""Declare a queue
@type queue: string
......@@ -157,6 +157,8 @@ class AMQPHaighaClient():
the specified nodes, and the master will be the
first node in the list. Node names must be provided
and not host IP. example: [node1@rabbit,node2@rabbit]
@type ttl: int
@param tll: Queue TTL in seconds
"""
......@@ -172,6 +174,9 @@ class AMQPHaighaClient():
else:
arguments = {}
if ttl is not None:
arguments['x-expires'] = ttl * 1000
self.channel.queue.declare(queue, durable=True, exclusive=exclusive,
auto_delete=False, arguments=arguments)
......
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright 2012-2014 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -188,7 +188,7 @@ class AMQPPukaClient(object):
@reconnect_decorator
def queue_declare(self, queue, exclusive=False,
mirrored=True, mirrored_nodes='all',
dead_letter_exchange=None):
dead_letter_exchange=None, ttl=None):
"""Declare a queue
@type queue: string
......@@ -203,6 +203,8 @@ class AMQPPukaClient(object):
the specified nodes, and the master will be the
first node in the list. Node names must be provided
and not host IP. example: [node1@rabbit,node2@rabbit]
@type ttl: int
@param ttl: Queue TTL in seconds
"""
self.log.info('Declaring queue: %s', queue)
......@@ -218,6 +220,9 @@ class AMQPPukaClient(object):
else:
arguments = {}
if ttl is not None:
arguments['x-expires'] = ttl * 1000
if dead_letter_exchange:
arguments['x-dead-letter-exchange'] = dead_letter_exchange
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment