Merge lp:~cjwatson/python-oops-amqp/accept-kombu into lp:python-oops-amqp

Proposed by Colin Watson
Status: Merged
Merged at revision: 27
Proposed branch: lp:~cjwatson/python-oops-amqp/accept-kombu
Merge into: lp:python-oops-amqp
Diff against target: 140 lines (+38/-18)
6 files modified
NEWS (+3/-1)
oops_amqp/publisher.py (+5/-5)
oops_amqp/receiver.py (+3/-3)
oops_amqp/utils.py (+6/-0)
setup.cfg (+1/-0)
tests/conftest.py (+20/-9)
To merge this branch: bzr merge lp:~cjwatson/python-oops-amqp/accept-kombu
Reviewer Review Type Date Requested Status
Andrey Fedoseev (community) Approve
Review via email: mp+431426@code.launchpad.net

Commit message

Accept kombu connection factories.

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Andrey Fedoseev (andrey-fedoseev) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2022-10-03 10:14:05 +0000
3+++ NEWS 2022-10-12 13:23:24 +0000
4@@ -3,12 +3,14 @@
5
6 Changes and improvements to oops-amqp, grouped by release.
7
8-0.1.1
9+0.2.0
10 -----
11
12 - Switch from buildout to tox. (Colin Watson)
13 - Switch to declarative setup.cfg. (Colin Watson)
14 - Port test suite to pytest. (Colin Watson)
15+- Accept connection factories that return ``kombu`` connections, as an
16+ alternative to ``amqp``. (Colin Watson)
17
18 0.1.0
19 -----
20
21=== modified file 'oops_amqp/publisher.py'
22--- oops_amqp/publisher.py 2018-03-12 11:48:55 +0000
23+++ oops_amqp/publisher.py 2022-10-12 13:23:24 +0000
24@@ -45,11 +45,11 @@
25 inherit_id=False):
26 """Create a publisher.
27
28- :param connection_factory: A callable which creates an amqplib
29- Connection when called. This is used to create connections - one
30- per thread which OOPS publishing happens in. This is because
31- amqplib is not threadsafe and recommends not sharing connections
32- across threads.
33+ :param connection_factory: A callable which creates an
34+ `amqp.Connection` or a `kombu.Connection` when called. This is
35+ used to create connections - one per thread which OOPS
36+ publishing happens in. This is because amqplib is not threadsafe
37+ and recommends not sharing connections across threads.
38 :param exchange_name: The name of the exchange to publish to.
39 :param routing_key: The routing key for messages.
40 :param inherit_id: If True any 'True' 'id' in an OOPS report is
41
42=== modified file 'oops_amqp/receiver.py'
43--- oops_amqp/receiver.py 2018-03-12 11:48:55 +0000
44+++ oops_amqp/receiver.py 2022-10-12 13:23:24 +0000
45@@ -45,9 +45,9 @@
46 """Create a Receiver.
47
48 :param config: An oops.Config to republish the OOPS reports.
49- :param connection_factory: An amqplib connection factory, used to make
50- the initial connection and to reconnect if that connection is
51- interrupted.
52+ :param connection_factory: An `amqp.Connection` or
53+ `kombu.Connection` factory, used to make the initial connection
54+ and to reconnect if that connection is interrupted.
55 :param queue_name: The queue to listen for reports on.
56 """
57 self.config = config
58
59=== modified file 'oops_amqp/utils.py'
60--- oops_amqp/utils.py 2018-03-12 11:48:55 +0000
61+++ oops_amqp/utils.py 2022-10-12 13:23:24 +0000
62@@ -20,6 +20,10 @@
63 import socket
64
65 from amqp.exceptions import ConnectionError
66+try:
67+ from kombu.exceptions import OperationalError
68+except ImportError:
69+ OperationalError = None
70
71 __all__ = [
72 'amqplib_error_types',
73@@ -32,6 +36,8 @@
74 # However you should catch amqplib_error_types and post-filter with
75 # is_amqplib_connection_error.
76 amqplib_connection_errors = (socket.error, ConnectionError)
77+if OperationalError is not None:
78+ amqplib_connection_errors += (OperationalError,)
79 # A tuple to reduce duplication in different code paths. Lists the types of
80 # exceptions legitimately raised by amqplib when the AMQP server goes down.
81 # Not all exceptions *will* be such errors - use is_amqplib_connection_error to
82
83=== modified file 'setup.cfg'
84--- setup.cfg 2022-10-03 10:14:05 +0000
85+++ setup.cfg 2022-10-12 13:23:24 +0000
86@@ -36,6 +36,7 @@
87
88 [options.extras_require]
89 test =
90+ kombu
91 pytest
92 rabbitfixture
93 six
94
95=== modified file 'tests/conftest.py'
96--- tests/conftest.py 2022-10-03 10:14:05 +0000
97+++ tests/conftest.py 2022-10-12 13:23:24 +0000
98@@ -17,6 +17,7 @@
99 from functools import partial
100
101 import amqp
102+import kombu
103 import pytest
104 from rabbitfixture.server import RabbitServer
105
106@@ -52,15 +53,25 @@
107 rabbit.cleanUp()
108
109
110-@pytest.fixture
111-def connection_factory(rabbit):
112- return partial(
113- amqp.Connection,
114- host="%s:%s" % (rabbit.config.hostname, rabbit.config.port),
115- userid="guest",
116- password="guest",
117- virtual_host="/",
118- )
119+@pytest.fixture(params=["amqp", "kombu"])
120+def connection_factory(rabbit, request):
121+ if request.param == "amqp":
122+ return partial(
123+ amqp.Connection,
124+ host="%s:%s" % (rabbit.config.hostname, rabbit.config.port),
125+ userid="guest",
126+ password="guest",
127+ virtual_host="/",
128+ )
129+ else:
130+ return partial(
131+ kombu.Connection,
132+ hostname=rabbit.config.hostname,
133+ userid="guest",
134+ password="guest",
135+ virtual_host="/",
136+ port=rabbit.config.port,
137+ )
138
139
140 @pytest.fixture

Subscribers

People subscribed via source and target branches

to all changes: