Skip to content

Commit 133907e

Browse files
authored
Merge pull request #58 from gmr/consolidate-consumers
Consolidate consumer classes and add Avro support
2 parents 58428bf + 1eefc32 commit 133907e

12 files changed

Lines changed: 320 additions & 336 deletions

docs/api.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ The primary base classes for building message consumers.
66

77
::: rejected.consumer.Consumer
88

9-
::: rejected.consumer.PublishingConsumer
10-
11-
::: rejected.consumer.SmartConsumer
12-
13-
::: rejected.consumer.SmartPublishingConsumer
14-
159
## Exceptions
1610

1711
::: rejected.consumer.ConsumerException

docs/api_consumer.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,3 @@ Consumer
55
:members:
66
:inherited-members:
77
:exclude-members: execute, log_exception, on_confirmation, require_setting, set_channel
8-
9-
.. autoclass:: rejected.consumer.PublishingConsumer
10-
:members:
11-
:inherited-members:
12-
:exclude-members: execute, log_exception, on_confirmation, require_setting, set_channel

docs/api_smart_consumer.rst

Lines changed: 0 additions & 12 deletions
This file was deleted.

docs/consumer.rst

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@
22

33
Consumer API
44
============
5-
The :py:class:`Consumer <rejected.consumer.Consumer>` and
6-
:py:class:`SmartConsumer <rejected.consumer.SmartConsumer>` classes to extend
5+
The :py:class:`Consumer <rejected.consumer.Consumer>` class to extend
76
for consumer applications.
87

9-
While the :py:class:`Consumer <rejected.consumer.Consumer>` class provides all
10-
the structure required for implementing a rejected consumer,
11-
the :py:class:`SmartConsumer <rejected.consumer.SmartConsumer>` adds
12-
functionality designed to make writing consumers even easier. When messages
13-
are received by consumers extending :py:class:`SmartConsumer <rejected.consumer.SmartConsumer>`,
14-
if the message's ``content_type`` property contains one of the supported mime-types,
15-
the message body will automatically be deserialized, making the deserialized
16-
message body available via the ``body`` attribute. Additionally, should one of
17-
the supported ``content_encoding`` types (``gzip`` or ``bzip2``) be specified in the
18-
message's property, it will automatically be decoded.
8+
The :py:class:`Consumer <rejected.consumer.Consumer>` class provides all
9+
the structure required for implementing a rejected consumer, including
10+
automatic deserialization of message bodies based on the message's
11+
``content_type`` property. When messages are received, if the message's
12+
``content_type`` property contains one of the supported mime-types, the message
13+
body will automatically be deserialized, making the deserialized message body
14+
available via the ``body`` attribute. Additionally, should one of the supported
15+
``content_encoding`` types (``gzip`` or ``bzip2``) be specified in the message's
16+
property, it will automatically be decoded.
1917

2018
Message Type Validation
2119
-----------------------
@@ -51,7 +49,6 @@ Consumer Classes
5149
:maxdepth: 1
5250

5351
api_consumer
54-
api_smart_consumer
5552

5653
Exceptions
5754
----------

docs/consumer_howto.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ __version__ = '1.0.0'
6666
LOGGER = logging.getLogger(__name__)
6767

6868

69-
class ExampleConsumer(consumer.PublishingConsumer):
69+
class ExampleConsumer(consumer.Consumer):
7070

7171
def process(self):
7272
LOGGER.info(self.body)
73-
self.publish('new-exchange', 'routing-key', {}, self.body)
73+
self.publish_message('new-exchange', 'routing-key', {}, self.body)
7474
```
7575

76-
Note that the previous example extends `rejected.consumer.PublishingConsumer`
77-
instead of `rejected.consumer.Consumer`.
76+
Note that `consumer.Consumer` supports publishing directly — there is no need
77+
to extend a separate `PublishingConsumer` class.

examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
__version__ = '1.0.0'
1010

1111

12-
class ExampleConsumer(consumer.SmartConsumer):
12+
class ExampleConsumer(consumer.Consumer):
1313
def process(self):
1414
self.logger.info('Message: %r', self.body)
1515
action = random.randint(0, 100)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ dependencies = [
3737
]
3838

3939
[project.optional-dependencies]
40+
avro = ["fastavro>=1.7", "requests>=2.28"]
4041
html = ["beautifulsoup4"]
4142
msgpack = ["u-msgpack-python"]
4243
sentry = ["sentry-sdk>=2,<3"]

rejected/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
logging.getLogger(__name__).addHandler(logging.NullHandler())
1111

1212
from rejected.consumer import ( # noqa: E402
13+
AVRO_DATUM_MIME_TYPE,
1314
Consumer,
1415
ConsumerException,
1516
MessageException,
1617
ProcessingException,
17-
PublishingConsumer,
18-
SmartConsumer,
19-
SmartPublishingConsumer,
2018
)
2119

2220
__author__ = 'Gavin M. Roy <gavinmroy@gmail.com>'
@@ -27,13 +25,11 @@
2725
__version__ = 'unknown'
2826

2927
__all__ = [
28+
'AVRO_DATUM_MIME_TYPE',
3029
'Consumer',
3130
'ConsumerException',
3231
'MessageException',
3332
'ProcessingException',
34-
'PublishingConsumer',
35-
'SmartConsumer',
36-
'SmartPublishingConsumer',
3733
'__author__',
3834
'__since__',
3935
'__version__',

rejected/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class ConsumerConfig(pydantic.BaseModel):
5959
qos_prefetch: int = 1
6060
max_errors: int = 5
6161
error_exchange: str | None = None
62+
schema_uri_format: str | None = None
6263
sentry_dsn: str | None = None
6364
drop_exchange: str | None = None
6465
drop_invalid_messages: bool | None = None

0 commit comments

Comments
 (0)