txsrv: Message-based Twisted Services
I've started work on txsrv, a Python library that aims to make developing message-based services in Twisted easy.
The code is still pretty rough, but might be of interest to someone hacking on AMQP-based Twisted services.
Sample Usage
Create a new service and change to the project directory.
$ txsrv create mytest $ cd mytestEdit the
mytest.conffile so that thespec_fileoption is valid.[connection:amqp] type = amqp host = localhost port = 5672 vhost = / user = guest password = guest spec_file = /usr/share/amqp/amqp.0-8.xml [handler:hello] connection = amqp exchange = hello routing_key = defaultEdit the
mytest.pyfile so that it prints the message body twice.import txsrv class Service(txsrv.Service): @txsrv.handler('hello') def hello(self, message): print message.body * 2 class ServiceMaker(txsrv.ServiceMaker): tapname = 'mytest' description = 'A mytest txsrv example.' service_type = ServiceStart the
mytestservice and send a message to thehelloexchange.$ twistd -n mytest -c mytest.conf 2010-09-12 00:41:10-0400 [-] Log opened. 2010-09-12 00:41:10-0400 [-] twistd 10.1.0 (/usr/bin/python 2.6.4) starting up. 2010-09-12 00:41:10-0400 [-] reactor class: twisted.internet.selectreactor.SelectReactor. 2010-09-12 00:41:10-0400 [-] Starting factory <txsrv.protocol.amqp.AmqpFactory instance at 0x2cce950> 2010-09-12 00:41:10-0400 [AmqpProtocol,client] hellohello