django-sqs-extended-client/README.rst
AWS SQS Extended Client Library for Django
To manage large Amazon Simple Queue Service (Amazon SQS) messages, you can use Amazon Simple Storage Service (Amazon S3) and the Amazon SQS Extended Client Library for Django. This is especially useful for storing and consuming messages up to 2 GB. Unless your application requires repeatedly creating queues and leaving them inactive or storing large amounts of data in your queues, consider using Amazon S3 for storing your data.
Quick start
Add “django_sqs_extended_client” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... 'django_sqs_extended_client', ]On AWS SQS create your Queue and subscribe it to a SNS Topic. After that edit the subscription in “Subscription filter policy” like this:
{ "event_type": [ "YOUR_SNS_SUBSCRIPTION_FILTER_EVENT_TYPE_1" ] }Include some additional django settings like this:
# AWS SNS KEYS AWS_ACCESS_KEY_ID = 'YOUR_AWS_ACCESS_KEY_ID' AWS_SECRET_ACCESS_KEY = 'YOUR_AWS_SECRET_ACCESS_KEY' AWS_DEFAULT_REGION = 'YOUR_AWS_DEFAULT_REGION' AWS_S3_QUEUE_STORAGE_NAME = 'YOUR_AWS_S3_QUEUE_STORAGE_NAME' AWS_SNS_TOPIC = 'YOUR_AWS_SNS_TOPIC' AWS_SNS_TOPIC_FIFO = 'YOUR_AWS_SNS_TOPIC_FIFO' # AWS EVENTS: SNS_EVENTS = { 'EVENT_TYPE_1': 'YOUR_SNS_SUBSCRIPTION_FILTER_EVENT_TYPE_1', 'EVENT_TYPE_2': 'YOUR_SNS_SUBSCRIPTION_FILTER_EVENT_TYPE_2', ... } SQS_EVENTS = { 'EVENT_TYPE_3': { 'sns_event_filter': 'YOUR_SNS_SUBSCRIPTION_FILTER_EVENT_TYPE_3', 'sqs_queue_url': 'YOUR_QUEUE_URL_FOR_EVENT_3', 'event_processor': 'PATH_OF_THE_CLASS_PROCESSOR_FOR_EVENT_3' }, 'EVENT_TYPE_4': { 'sns_event_filter': 'YOUR_SNS_SUBSCRIPTION_FILTER_EVENT_TYPE_4', 'sqs_queue_url': 'YOUR_QUEUE_URL_FOR_EVENT_4', 'event_processor': 'PATH_OF_THE_CLASS_PROCESSOR_FOR_EVENT_4' }, ... }Add one cron for each SQS event to process. Run it every minute with a lock:
* * * * * python manage.py process_queue EVENT_TYPE_3 * * * * * python manage.py process_queue EVENT_TYPE_4
You can use a library as https://pypi.org/project/django-chroniker/ for an easier way to manage crons and lockers
E.g:
In django_project/django_project/settings.py:
# AWS SNS KEYS AWS_ACCESS_KEY_ID = 'ABCDEFGHIJKLMNOPQRSTUWXYZ' AWS_SECRET_ACCESS_KEY = '74gfq83hg83qh5erg/G&Cwd23^VFBfvV^vvkf7g77' AWS_DEFAULT_REGION = 'us-east-1' AWS_S3_QUEUE_STORAGE_NAME = 'sns-queues' AWS_SNS_TOPIC = 'arn:aws:sns:us-east-1:123456789:domainEvents' # AWS EVENTS: SNS_EVENTS = { 'PAYMENT_REGISTERED': 'this-service.event.payment.registered' } SQS_EVENTS = { 'BOOKING_SERVICE__ROOM_BOOKED': { 'sns_event_filter': 'booking-service.event.room.booked', 'sqs_queue_url': 'https://sqs.us-east-1.amazonaws.com/123456789/booking-service--room-booked', 'event_processor': 'your_project.event_processors.room_booked.RoomBooked' }, }Cron:
* * * * * python manage.py process_queue BOOKING_SERVICE__ROOM_BOOKED
Usage
In the sender service:
Dispatch your data using EventDispatcher like this:
from django_sqs_extended_client.event.event_dispatcher import EventDispatcher
event_dispatcher = EventDispatcher()
event_dispatcher.dispatch(
event_name=settings.SNS_EVENTS['PAYMENT_REGISTERED'],
event_data=your_data,
)
event_data accept list, dict and row content data as xml, csv, json.
In the receiver service:
For each settings.SQS_EVENTS, add a class which extends django_sqs_extended_client.event_processor.EventProcessor. This Class accepts the data in the constructor and must have the method execute() where you can add the code to manage your data. Use the same paths of the ‘event_processor’ in settings.SQS_EVENTS like this:
from django_sqs_extended_client.event_processor.event_processor import EventProcessor
class ImageCreated(EventProcessor):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def execute(self):
# your code here
pass
Metadata
Release files for django-sqs-extended-client 2.6.1
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 | Actions |
|---|---|---|---|---|
| django-sqs-extended-client-2.6.1.tar.gz | 12.1 kB | Without provenance | Details for django-sqs-extended-client-2.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_sqs_extended_client-2.6.1-py3-none-any.whl | Python 3 | none | any | Details for django_sqs_extended_client-2.6.1-py3-none-any.whl |
Total release size: 26.3 kB
Release files / django-sqs-extended-client-2.6.1.tar.gz
| Download URL | django-sqs-extended-client-2.6.1.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea530d25eb6a7aab19df624bd2927b4369e86917f09e66e221e37767ca7a88f8
|
|
BLAKE2b-256 checksum How to use checksums |
caa93c0a9bd22f51f438c632e1bcc650257d6b1e967d911cbf72c3ffacd7cbb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Release files / django_sqs_extended_client-2.6.1-py3-none-any.whl
| Download URL | django_sqs_extended_client-2.6.1-py3-none-any.whl |
|---|---|
| Size | 14.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
863a3fd9ae028514c017faddb33cc2aa749085c8bac05d88287de68d223a3661
|
|
BLAKE2b-256 checksum How to use checksums |
b2b7c2766754792a6759fcf31b808a91b05fcc841201b755a87f8ec5d00a9e9a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Security for django-sqs-extended-client 2.6.1
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.