Skip to content

Commit

Permalink
Merge pull request #1069 from abompard/twisted-tests
Browse files Browse the repository at this point in the history
Add tests for the Twisted adapter
  • Loading branch information
lukebakken committed Jul 31, 2018
2 parents f5eca96 + 00a781d commit 90b1d84
Show file tree
Hide file tree
Showing 11 changed files with 1,944 additions and 694 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Pika provides the following adapters
- BlockingConnection - enables blocking, synchronous operation on top of library for simple usage
- SelectConnection - fast asynchronous adapter without 3rd-party dependencies
- TornadoConnection - adapter for use with the Tornado IO Loop http://tornadoweb.org
- TwistedConnection - adapter for use with the Twisted asynchronous package http://twistedmatrix.com/
- TwistedProtocolConnection - adapter for use with the Twisted asynchronous package http://twistedmatrix.com/

Multiple Connection Parameters
------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/twisted_example.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Twisted Consumer Example
========================
Example of writing a consumer using the :py:class:`Twisted connection adapter <pika.adapters.twisted_connection.TwistedConnection>`::
Example of writing a consumer using the :py:class:`Twisted connection adapter <pika.adapters.twisted_connection.TwistedProtocolConnection>`::

# -*- coding:utf-8 -*-

Expand Down
6 changes: 3 additions & 3 deletions docs/modules/adapters/twisted.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ Twisted Connection Adapter
==========================
.. automodule:: pika.adapters.twisted_connection

.. autoclass:: pika.adapters.twisted_connection.TwistedConnection
.. autoclass:: pika.adapters.twisted_connection.TwistedProtocolConnection
:members:
:inherited-members:

.. autoclass:: pika.adapters.twisted_connection.TwistedProtocolConnection
.. autoclass:: pika.adapters.twisted_connection.TwistedChannel
:members:
:inherited-members:

.. autoclass:: pika.adapters.twisted_connection.TwistedChannel
.. autoclass:: pika.adapters.twisted_connection.ClosableDeferredQueue
:members:
:inherited-members:
12 changes: 7 additions & 5 deletions examples/twisted_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import pika
from pika import spec
from pika import exceptions
from pika.adapters import twisted_connection

from twisted.internet import protocol
Expand All @@ -35,6 +34,7 @@

PREFETCH_COUNT = 2


class PikaService(service.MultiService):
name = 'amqp'

Expand Down Expand Up @@ -89,10 +89,12 @@ def read(self, exchange, routing_key, callback):
@inlineCallbacks
def setup_read(self, exchange, routing_key, callback):
"""This function does the work to read from an exchange."""
if not exchange == '':
if exchange:
yield self.channel.exchange_declare(exchange=exchange, exchange_type='topic', durable=True, auto_delete=False)

self.channel.queue_declare(queue=routing_key, durable=True)
yield self.channel.queue_declare(queue=routing_key, durable=True)
if exchange:
yield self.channel.queue_bind(queue=routing_key, exchange=exchange)

(queue, consumer_tag,) = yield self.channel.basic_consume(queue=routing_key, auto_ack=False)
d = queue.get()
Expand Down Expand Up @@ -156,11 +158,11 @@ def buildProtocol(self, addr):
return self.client

def clientConnectionLost(self, connector, reason):
log.msg('Lost connection. Reason: %s' % reason, system=self.name)
log.msg('Lost connection. Reason: %s' % reason.value, system=self.name)
protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)

def clientConnectionFailed(self, connector, reason):
log.msg('Connection failed. Reason: %s' % reason, system=self.name)
log.msg('Connection failed. Reason: %s' % reason.value, system=self.name)
protocol.ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)

def send_message(self, exchange = None, routing_key = None, message = None):
Expand Down
2 changes: 1 addition & 1 deletion pika/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
from pika.adapters import BlockingConnection
from pika.adapters import SelectConnection
from pika.adapters import TornadoConnection
from pika.adapters import TwistedConnection
from pika.adapters import TwistedProtocolConnection

from pika.adapters.utils.connection_workflow import AMQPConnectionWorkflow
4 changes: 1 addition & 3 deletions pika/adapters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
adapter that implements select, kqueue, poll and epoll.
- adapters.tornado_connection.TornadoConnection: Connection adapter for use
with the Tornado web framework.
- adapters.twisted_connection.TwistedConnection: Connection adapter for use
- adapters.twisted_connection.TwistedProtocolConnection: Connection adapter for use
with the Twisted framework
"""
Expand All @@ -32,9 +32,7 @@
TornadoConnection = None

try:
from pika.adapters.twisted_connection import TwistedConnection
from pika.adapters.twisted_connection import TwistedProtocolConnection
except ImportError:
TwistedConnection = None
TwistedProtocolConnection = None

0 comments on commit 90b1d84

Please sign in to comment.