Awesome Messages Generic PubSub
Generic Message Listeners and Publishers.
This module provides interfaces to work with any kind of message publisher and consumer.
This module also provides currently the following implementations:
- RabbitMQ Message Listener
- RabbbitMQ Message Publisher
Currently only rabbitmq support is implemented but in a future other infrastructure pieces could be supported too.
The infrastructure of this package rely on abstractions so it is highly
decoupled. Apps code should depend only in MessageHandler,
MessagePublisher and MessageListener.
Installation
pip install awesome_messages
Create a MessageHandler to handle the received messages
from awesome_messages.domain.handler import MessageHandler
class PrintRequestHandler(MessageHandler):
def on_msg(self, message: dict):
print(message)
Configure a listener
I'm using here the RabbitMQ listener implementation.
You can write your custom listener using MessageListener interface.
if you write your own listener please make a pull request so that the
rest of the community can use it too.
# Import infrastructure specific listener
from awesome_messages.infra.rabbitmq.listener import RabbitMessageListener
connection_string = "amqps://user:password@host/.."
queue = "my_awesome_queue"
# Declare our listener with our previously defined MessageHandler
msg_listener = RabbitMessageListener(
connection_string, queue, PrintRequestHandler()
)
# Currently RabbitMQ listener is blocking
try:
msg_listener.start_listening()
finally:
msg_listener.stop_listening()
Configure a publisher
I'm using here the RabbitMQ publisher implementation.
You can write your custom publisher using MessagePublisher interface.
if you write your own publisher please make a pull request so that the
rest of the community can use it too.
# Import infrastructure specific publisher
from awesome_messages.infra.rabbitmq.publisher import RabbitMessagePublisher
msg_publisher = RabbitMessagePublisher(connection_string, queue)
try:
# Publish a message
msg_publisher.publish({"my msg": "my msg data"})
finally:
msg_publisher.stop_publishing()
Author notes
The way this module is structured allows anyone to easily replace one implementation by another without changing the rest of the application code.
This module invites the developer to use dependency injection to build their app. Relying on defined interfaces rather than implementations allows changes in dependencies be possible without changing the code.
Best practices in big projects
You can use a dependency injection library for configure your message handler, listener and publisher like the following one.
Support my work
If this module has been useful to you, it would mean a lot to me if you could support my work. This way you help to keep this and other projects alive.
Contributors
- Samuel López Saura - Linkedin Contact
Metadata
Release files for awesome-messages 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| awesome_messages-1.0.0.tar.gz | 4.5 kB | Without provenance | Details |
Release files / awesome_messages-1.0.0.tar.gz
| Download URL | awesome_messages-1.0.0.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b82297bc7aee342e5c460a92929b04c5f6abb85c0bbe26ec0845de80aef27838
|
|
BLAKE2b-256 checksum How to use checksums |
0125a3fbb2d8d11a3655e31e8ee9129147aa4f085ab2712cfc3c851af20969a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for awesome-messages 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.