AMQP and Twisted

In one of my pet projects I’ve been using Twisted and txamqp. I use Twisted’s twistd to launch the service but unfortunately txamqp doesn’t come with any examples of how to use it with twistd. So I wrote a factory and protocol which makes it trivial to use txamqp with twistd. I haven’t tested it extensively but it appears to survive losing the connection to the AMQP server and reconnecting. I’m far from a Twisted expert though so please let me know if this isn’t the way it supposed to be done.

You can find the code in my Git repository.





9 responses to “AMQP and Twisted”

  1. Erick Tryzelaar Avatar
    Erick Tryzelaar

    Hello Dan! Is there a url that I can clone with git expose? Your project page mentions that I could go to, but the web server is giving me a 403/Forbidden error.

  2. Dan Siemon Avatar

    Oops. Fixed. You can now clone with the following:

    git clone

  3. Simon de Haan Avatar


    Thanks for the example code. There’s a small bug in your code which causes it to always default to the ‘/’ vhost even if specified otherwise.

    Line 169 should read: self.vhost = vhost or '/' instead of '/' or vhost.

    cheers! smn

    1. Dan Siemon Avatar

      Thanks Simon. I’ve fixed this in the repository.

  4. Tim Hughes Avatar

    Thanks Dan,

    I was working on writing something similar and when trying to work it all out I discovered this. It has helped with my understanding and is much more complete than mine so I am adapting to to suit my needs. While doing this is noticed a little bug where you are always using the method args instead of your defaults even if there is nothing passed into the __init__ method .

    I think line 180 should read
    reactor.connectTCP(, self.port, self.self)

  5. Tim Hughes Avatar

    Sorry that should be
    reactor.connectTCP(, self.port, self)

    1. Dan Siemon Avatar

      Thanks. I’ve committed this fix. If you make any other improvements please let me know.

  6. […] while ago I put some code online that makes using txamqp with twistd […]

  7. Dan Siemon Avatar

    Anyone using this code please read this post.

Leave a Reply

Your email address will not be published. Required fields are marked *