A simple Python SQS utility package
Project description
This package takes care of the boilerplate involved in listening to an SQS queue, as well as sending messages to a queue.
Installation
pip install pySqsListener
Listening to a queue
Here is a basic code sample:
from sqs_listener import SqsListener class MyListener(SqsListener): def handle_message(self, body, attributes, messages_attributes): run_my_function(body['param1'], body['param2'] listener = MyListener('my-message-queue', 'my-error-queue') listener.listen(True)
Error Listener
from sqs_listener import SqsListener class MyErrorListener(SqsListener): def handle_message(self, body, attributes, messages_attributes): save_to_log(body['exception_type'], body['error_message'] error_listener = MyErrorListener('my-error-queue') error_listener.listen()
Sending messages
Launcher Example
from sqs_launcher import SqsLauncher launcher = SqsLauncher('my-queue') response = launcher.launch_message({'param1': 'hello', 'param2': 'world'})
Important Notes
The environment variable AWS_ACCOUNT_ID must be set, in addition to the environment having valid AWS credentials (via environment variables or a credentials file)
For both the main queue and the error queue, if the queue doesn’t exist (in the specified region), it will be created at runtime.
The error queue receives only two values in the message body: exception_type and error_message. Both are of type str
Upcoming Features
Create an issue with a suggestion for a feature, and I’ll see what I can do!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for pySqsListener-0.4.6-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86d48f86c56c3d4782b52d429efec16d4cce9ba4816a5a6e3ee2db47083addb1 |
|
MD5 | 239a84c57ab4948b6cee8e8776fe48f1 |
|
BLAKE2b-256 | 32d0222936496b8df07739fb2c1cc7d003c642d60444172fa7336312a15b75ef |