How to add delay in rabbitmq

inside producer class have to add delay, for example:

class MyProducer(Producer):
    # is also my routing key:"myrabbit.taskqueue")
    connection_id = "myrabbit"
    exchange = "myrabbit"
    serializer = "application/x-python-serialize"

    #adding delay code starts here
    queue = "myrabbit.taskqueue.wait" #add .wait with the task queue id

    queue_arguments = {
        "x-dead-letter-exchange": "", 
        "x-dead-letter-routing-key": "myrabbit.taskqueue", #is the task queue id defined in buildout
        "x-message-ttl": 60000,  # 60s poll for autopublish
    routing_key = "myrabbit.taskqueue.wait" #same here add .wait with buildout task queue id
    #adding delay code ends here
    auto_declare = True
    durable = True

You see inside code the bold lines should be added for rabbitmq delay You have to replace zitelab.taskqueue with your queue name

here in this example it will delay 60 second after each message is sent. you can increase ofcourse but decreasing will give error as in buildout minimum is set 60 second via this config: keepalive 60

Another way is to add this code until you get the object from uuid

from plone.uuid.interfaces import IUUID

_uuid = IUUID(self)
# Try waiting in case of transaction failed by Nazrul
_start_time = time.time()
while True:
    _obj = uuidToObject(_uuid)
    if _obj:
        # Transaction OK, so no more wait
    if 4 < int(time.time() - _start_time):
        # @Todo: currently we will wait not more than 5 seconds

Then after this code publish the message if you are doing it in producer side.

And if you are waiting in consumer side then you can use this code in consumer function


Work is fun!

Tagged with: , , , , , , , , ,
Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

All content provided on this "" blog is for informational purposes only. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner of [] will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.
February 2015
« Jan   Apr »

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 23 other followers

%d bloggers like this: