Colin Watson has proposed merging lp:~cjwatson/python-oops-amqp/accept-kombu 
into lp:python-oops-amqp.

Commit message:
Accept kombu connection factories.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/python-oops-amqp/accept-kombu/+merge/431426

The `kombu` library is a higher-level messaging library that can use `amqp` 
(among others) as transports, with a very similar API to `amqp`.  It's useful 
to be able to drop it in as a replacement, mainly because it supports automatic 
failover between multiple brokers.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of 
lp:~cjwatson/python-oops-amqp/accept-kombu into lp:python-oops-amqp.
=== modified file 'NEWS'
--- NEWS	2022-10-03 10:14:05 +0000
+++ NEWS	2022-10-12 13:23:24 +0000
@@ -3,12 +3,14 @@
 
 Changes and improvements to oops-amqp, grouped by release.
 
-0.1.1
+0.2.0
 -----
 
 - Switch from buildout to tox. (Colin Watson)
 - Switch to declarative setup.cfg. (Colin Watson)
 - Port test suite to pytest. (Colin Watson)
+- Accept connection factories that return ``kombu`` connections, as an
+  alternative to ``amqp``. (Colin Watson)
 
 0.1.0
 -----

=== modified file 'oops_amqp/publisher.py'
--- oops_amqp/publisher.py	2018-03-12 11:48:55 +0000
+++ oops_amqp/publisher.py	2022-10-12 13:23:24 +0000
@@ -45,11 +45,11 @@
             inherit_id=False):
         """Create a publisher.
 
-        :param connection_factory: A callable which creates an amqplib
-            Connection when called. This is used to create connections - one
-            per thread which OOPS publishing happens in. This is because
-            amqplib is not threadsafe and recommends not sharing connections
-            across threads.
+        :param connection_factory: A callable which creates an
+            `amqp.Connection` or a `kombu.Connection` when called. This is
+            used to create connections - one per thread which OOPS
+            publishing happens in. This is because amqplib is not threadsafe
+            and recommends not sharing connections across threads.
         :param exchange_name: The name of the exchange to publish to.
         :param routing_key: The routing key for messages.
         :param inherit_id: If True any 'True' 'id' in an OOPS report is

=== modified file 'oops_amqp/receiver.py'
--- oops_amqp/receiver.py	2018-03-12 11:48:55 +0000
+++ oops_amqp/receiver.py	2022-10-12 13:23:24 +0000
@@ -45,9 +45,9 @@
         """Create a Receiver.
 
         :param config: An oops.Config to republish the OOPS reports.
-        :param connection_factory: An amqplib connection factory, used to make
-            the initial connection and to reconnect if that connection is
-            interrupted.
+        :param connection_factory: An `amqp.Connection` or
+            `kombu.Connection` factory, used to make the initial connection
+            and to reconnect if that connection is interrupted.
         :param queue_name: The queue to listen for reports on.
         """
         self.config = config

=== modified file 'oops_amqp/utils.py'
--- oops_amqp/utils.py	2018-03-12 11:48:55 +0000
+++ oops_amqp/utils.py	2022-10-12 13:23:24 +0000
@@ -20,6 +20,10 @@
 import socket
 
 from amqp.exceptions import ConnectionError
+try:
+    from kombu.exceptions import OperationalError
+except ImportError:
+    OperationalError = None
 
 __all__ = [
     'amqplib_error_types',
@@ -32,6 +36,8 @@
 # However you should catch amqplib_error_types and post-filter with
 # is_amqplib_connection_error.
 amqplib_connection_errors = (socket.error, ConnectionError)
+if OperationalError is not None:
+    amqplib_connection_errors += (OperationalError,)
 # A tuple to reduce duplication in different code paths. Lists the types of
 # exceptions legitimately raised by amqplib when the AMQP server goes down.
 # Not all exceptions *will* be such errors - use is_amqplib_connection_error to

=== modified file 'setup.cfg'
--- setup.cfg	2022-10-03 10:14:05 +0000
+++ setup.cfg	2022-10-12 13:23:24 +0000
@@ -36,6 +36,7 @@
 
 [options.extras_require]
 test =
+    kombu
     pytest
     rabbitfixture
     six

=== modified file 'tests/conftest.py'
--- tests/conftest.py	2022-10-03 10:14:05 +0000
+++ tests/conftest.py	2022-10-12 13:23:24 +0000
@@ -17,6 +17,7 @@
 from functools import partial
 
 import amqp
+import kombu
 import pytest
 from rabbitfixture.server import RabbitServer
 
@@ -52,15 +53,25 @@
         rabbit.cleanUp()
 
 
-@pytest.fixture
-def connection_factory(rabbit):
-    return partial(
-        amqp.Connection,
-        host="%s:%s" % (rabbit.config.hostname, rabbit.config.port),
-        userid="guest",
-        password="guest",
-        virtual_host="/",
-    )
+@pytest.fixture(params=["amqp", "kombu"])
+def connection_factory(rabbit, request):
+    if request.param == "amqp":
+        return partial(
+            amqp.Connection,
+            host="%s:%s" % (rabbit.config.hostname, rabbit.config.port),
+            userid="guest",
+            password="guest",
+            virtual_host="/",
+        )
+    else:
+        return partial(
+            kombu.Connection,
+            hostname=rabbit.config.hostname,
+            userid="guest",
+            password="guest",
+            virtual_host="/",
+            port=rabbit.config.port,
+        )
 
 
 @pytest.fixture

_______________________________________________
Mailing list: https://launchpad.net/~launchpad-reviewers
Post to     : launchpad-reviewers@lists.launchpad.net
Unsubscribe : https://launchpad.net/~launchpad-reviewers
More help   : https://help.launchpad.net/ListHelp

Reply via email to