sqs-polling
sqs-polling is simple AWS SQS daemon. The following is all.
- Polls SQS at regular intervals.
- Receives messages and executes your callback.
- If your callback function returns True, deletes the message.
Installation
$ pip install sqs-polling
Usage
The key function is sqs_polling, please check its interface.
The simplest usage is below.
from sqs_polling import sqs_polling
def your_callback(message, greeting):
print(greeting + message["name"])
return True
your_queue_url="https://sqs.your-region.amazonaws.com/XXXXXXXXXXXX/your-sqs",
sqs_polling(queue_url=your_queue_url, callback=your_callback, callback_args={"greeting": "Hello, "})
Callback
Your callback function must return 1 bool value.
If True, deletes the processed message.
If False, the message is remaining in your SQS and reprocessed after visibility_timeout seconds. It is recommended to return False if message processing fails.
Configuration
AWS account profile
In the example above, explicit AWS account profiles is omitted.
If explicit authentication is required, you can access SQS by setting additional profiles in aws_profile_dict argument.
your_aws_profile = {
"region_name": "your-region",
"aws_access_key_id": "XXXXXXXXXXXXXXXXXXXX",
"aws_secret_access_key": "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
}
sqs_polling(queue_url=your_queue_url, callback=your_callback, aws_profile_dict=your_aws_profile)
Polling
The arguments related to polling settings are as follows.
extract_body: Whether to extract the message body. (default: True)- The
bodyhere refers to$.Messages.BodyJSON element of SQS messages.
- The
interval_seconds: Message reception interval seconds. (default: 1.0)visibility_timeout: Message visibility timeout seconds. (default: 300)
Concurrency
sqs-polling can process messages in parallel using threads or processes. It can be controlled by the following arguments.
max_workers: Max number of concurrent threads or processes. (default: 1)process_worker: If this is True, processes is used instead of threads. (default: False)
# Parallel processing with up to 64 threads.
sqs_polling(queue_url=your_queue_url, callback=your_callback, max_workers=64)
# Parallel processing with up to 4 processes.
sqs_polling(queue_url=your_queue_url, callback=your_callback, process_worker=True, max_workers=4)
Metadata
Release files for sqs-polling 0.1.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 | |
|---|---|---|---|
| sqs-polling-0.1.0.tar.gz | 4.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sqs_polling-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.5 kB
Release files / sqs-polling-0.1.0.tar.gz
| Download URL | sqs-polling-0.1.0.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0c3c6f40255fc3d1a94e51b736ffc50f669db72d0e1ec9f5feba1cee2cae2985
|
|
BLAKE2b-256 checksum How to use checksums |
78c1dcefd372e9df04c69f53ace45f0a7746b01a0b39278d4cfadd8bafa26f72
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.5.7
|
Release files / sqs_polling-0.1.0-py3-none-any.whl
| Download URL | sqs_polling-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9855305d92520aa283abc62d909a8bd45473e18db12b242db4d1686a25628841
|
|
BLAKE2b-256 checksum How to use checksums |
4c15b31ad964a85fb88a0a26d388dae5585eb8c1f12e227f28286b17c03aca1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.5.7
|