AMQP twisted tap

Asked by DarkAnthey

Hello everybody. How can I create AMQP connection with twisted .tap.

I try the following. But it does not work:

from twisted.application import service
from my_service import Organizer
from twisted.internet.protocol import ClientCreator
from txamqp.client import TwistedDelegate
from txamqp.contrib.thrift.protocol import ThriftAMQClient
import txamqp.spec

from twisted.internet import reactor

def makeService(config):
    application = service.Application('Server')
    spec = txamqp.spec.load(config['qspec'])
    delegate = TwistedDelegate()
    return ClientCreator(reactor, ThriftAMQClient, delegate, config['qvhost'], spec).connectTCP(config['qhost'], int(config['qport']))

Question information

Language:
English Edit question
Status:
Answered
For:
txAMQP Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Juan Carlos (juan-ferrer) said :
#1

makeService needs to return an object that implements IService. Just create a service object and have makeService return that object, and inside that object instantiate your AMQP client and then reactor.connectXXX it.

Revision history for this message
Tim Hughes (thughes) said :
#2

I think this may be what you are after

<verbatim>
from twisted.application import service
#from my_service import Organizer
from twisted.internet.protocol import ClientCreator
from txamqp.client import TwistedDelegate
from txamqp.contrib.thrift.protocol import ThriftAMQClient
import txamqp.spec
from zope.interface import implements
from twisted.internet import reactor

config ={
        'qspec': 'specs/standard/amqp0-8.xml',
        'qvhost': '/',
        'qhost': 'localhost',
        'qport': '5672',
        }

class ThriftAMQPService():
    implements(service.IService)
    def __init__(self, config):
        spec = txamqp.spec.load(str(config['qspec']))
        delegate = TwistedDelegate()
        self = ClientCreator(reactor, ThriftAMQClient, delegate, config['qvhost'], spec).connectTCP(config['qhost'], int(config['qport']))

def makeService(config):
    serv = ThriftAMQPService(config)
    return serv

application = service.Application('Server')
service = makeService(config)
</verbatim>

Can you help with this problem?

Provide an answer of your own, or ask DarkAnthey for more information if necessary.

To post a message you must log in.