Beispiel #1
0
 def setUp(self):
     super(AMQPumpTest, self).setUp()
     delegate = TwistedDelegate()
     spec = load(DEFAULT_SPEC)
     self.client = AMQClient(delegate, "/", spec, clock=Clock())
     self.transport = AMQPump()
     self.transport.connect(self.client)
Beispiel #2
0
 def __init__(self, reactor, username='******', password='******', 
                             vhost='/', spec_path=spec_path_def):
     self.reactor = reactor
     self.username = username
     self.password = password
     self.vhost = vhost
     self.spec= spec.load(spec_path)
     self.connector = None
Beispiel #3
0
 def setUp(self):
     super(AMQClientTest, self).setUp()
     self.delegate = TwistedDelegate()
     self.clock = Clock()
     self.heartbeat = 1
     self.protocol = AMQClient(
         self.delegate, "/", load(DEFAULT_SPEC), clock=self.clock,
         heartbeat=self.heartbeat)
     self.transport = AMQPump(Logger())
     self.transport.connect(self.protocol)
Beispiel #4
0
 def __init__(self, manager, username='******', password='******', vhost='/'):
     """
     """
     manager.node = self # might be cleaner to just pass NodeContainer
     #instance to NodeManager, treating NodeContainer like reactor...
     self.manager = manager
     self.username = username
     self.password = password
     self.vhost = vhost
     self.spec = spec.load(SPEC_PATH)
Beispiel #5
0
 def __init__(self, spec=None, clock=None):
     """
     @param spec: Path to the spec file. Defaults to the standard AMQP 0.9.
     @type spec: L{str} (native string)
     """
     if spec is None:
         spec = DEFAULT_SPEC
     self._spec = load(spec)
     self._clock = clock
     self._vhost = "/"
     self._heartbeat = 0
Beispiel #6
0
    def __init__(self, parent, user, password, vhost=None, logTraffic=False):
        self.parent = parent
        self.user = user
        self.password = password
        self.vhost = vhost or '/'
        self.logTraffic = logTraffic
        spec_file = resource_filename('vigilo.connector', 'amqp0-9-1.xml')
        self.spec = spec.load(spec_file)
        self.delegate = TwistedDelegate()
        self.handlers = []

        self.p = None # The protocol instance.
        self.channel = None # The main channel
Beispiel #7
0
    def start(self):
        spec = load(self.spec)

        delegate = TwistedDelegate()
        self.client = protocol.ClientCreator(
            reactor,
            AMQClient,
            delegate=delegate,
            vhost="/",
            spec=spec).connectTCP(self.host,
                                  self.port)

        self.client.addCallback(self.gotConnection)
        self.client.addErrback(self.errConnection)
Beispiel #8
0
    def __init__(self, reactor, username='******', password='******',
                                vhost='/', delegate=None,
                                spec_path=SPEC_PATH,
                                heartbeat=0):
        self.reactor = reactor
        self.username = username
        self.password = password
        self.vhost = vhost

        # Cache the specs for enormous speedups on subsequent connections
        cache = ConnectionCreator.spec_cache
        if spec_path in cache:
            self.spec = cache[spec_path]
        else:
            self.spec = cache.setdefault(spec_path, spec.load(spec_path))

        self.heartbeat = heartbeat
        if delegate is None:
            delegate = TwistedDelegate()
        self.delegate = delegate
        self.connector = None
Beispiel #9
0
 def __init__(self, amqpConnectionInfo, queueSchema):
     with open(pathjoin(dirname(__file__), 'amqp0-9-1.xml')) as f:
         self.spec = spec.load(f)
         log.debug('Loaded AMQP spec')
     self.connectionInfo = amqpConnectionInfo
     self.queueSchema = queueSchema
     self.vhost = self.connectionInfo.vhost
     self.host = self.connectionInfo.host
     self.port = self.connectionInfo.port
     self.usessl = self.connectionInfo.usessl
     self.delegate = TwistedDelegate()
     self.queues = []
     self.messages = []
     self.p = None
     self._onInitialSend = self._createDeferred()
     self._onConnectionMade = self._createDeferred()
     self._onConnectionLost = self._createDeferred()
     self._onAuthenticated = self._createDeferred()
     self._onConnectionFailed = self._createDeferred()
     self.connector = reactor.connectTCP(self.host, self.port, self)
     self.heartbeat = self.connectionInfo.amqpconnectionheartbeat
Beispiel #10
0
 def __init__(self, amqpConnectionInfo, queueSchema):
     with open(pathjoin(dirname(__file__), 'amqp0-9-1.xml')) as f:
         self.spec = spec.load(f)
         log.debug('Loaded AMQP spec')
     self.connectionInfo = amqpConnectionInfo
     self.queueSchema = queueSchema
     self.vhost = self.connectionInfo.vhost
     self.host = self.connectionInfo.host
     self.port = self.connectionInfo.port
     self.usessl = self.connectionInfo.usessl
     self.delegate = TwistedDelegate()
     self.queues = []
     self.messages = []
     self.p = None
     self._onInitialSend = self._createDeferred()
     self._onConnectionMade = self._createDeferred()
     self._onConnectionLost = self._createDeferred()
     self._onAuthenticated = self._createDeferred()
     self._onConnectionFailed = self._createDeferred()
     self.connector = reactor.connectTCP(self.host, self.port, self)
     self.heartbeat = self.connectionInfo.amqpconnectionheartbeat
def createClient(host='localhost', port=5672):
    """
    Typical setup procedure for txamqp
    """

    spec_path = os.path.abspath('amqp0-8.xml') # assume the demo is run in place
    spec_file = spec.load(spec_path)

    username = '******'
    password = '******'
    vhost = '/'

    delegate = TwistedDelegate()

    def authenticate(conn, username, password):
        """this is a callback handler that returns a deferred
        """
        d = conn.authenticate(username, password)
        d.addCallback(lambda _: conn)
        d.addErrback(handle_error)
        return d

    def handle_error(reason):
        """
        do something useful with the error
        """
        reason.printTraceback()
        return reason

    client_creator = protocol.ClientCreator(reactor, 
                                            AMQClient, 
                                            delegate=delegate, 
                                            vhost=vhost,
                                            spec=spec_file)
    d = client_creator.connectTCP(host, port)
    d.addCallback(authenticate, username, password)
    d.addErrback(handle_error)
    return d
Beispiel #12
0
 def __init__(self, username='******', password='******', 
                     vhost='/', spec_path=spec_path_def):
     self.username = username
     self.password = password
     self.vhost = vhost
     self.spec= spec.load(spec_path)