AWS SQS item processing callback
Project description
SQS Callback decorator
Python decorator for registering message handlers from Simple Queue Service endpoints.
- decorator register callbacks for specific queues
listen
to iterate over all callbacks, read messages from queues and dispatchpost
to quickly send data to a queue and obtain message ID
usage
import sqsfn
@sqsfn.sqs_queue_listener(sqs_queue_name="my-queue-name")
def my_example_queue_listener(data_from_queue):
"""process a queue item"""
print("recieved data")
return True
if __name__ == "__main__":
asyncio.run(sqsfn.listen())
multiple queues
import sqsfn
@sqsfn.sqs_queue_listener(sqs_queue_name="queue-a")
def my_example_queue_listener(data_from_queue_a):
print("received from queue a")
sqsfn.post("queue-b", data_from_queue_a)
return True
@sqsfn.sqs_queue_listener(sqs_queue_name="queue-b")
def my_example_queue_listener(data_from_queue_b):
print("received from queue b")
sqsfn.post("queue-c", data_from_queue_b)
return True
@sqsfn.sqs_queue_listener(sqs_queue_name="queue-c")
def my_example_queue_listener(data_from_queue_c):
print("received from queue c")
sqsfn.post("queue-a", data_from_queue_c)
return True
if __name__ == "__main__":
asyncio.run(sqsfn.listen())
success and failure queues
the on_success
and on_fail
optional parameters accept a function which
will be called on successful processing of the message or otherwise.
import sqsfn
@sqsfn.sqs_queue_listener(
sqs_queue_name="my-queue-name",
on_success=lambda x: sqsfn.post("my-success-queue", x),
on_fail=lambda x: sqsfn.post("my-fail-queue", x)
)
def my_example_queue_listener(data_from_queue):
"""process a queue item"""
print("recieved data")
return True
if __name__ == "__main__":
asyncio.run(sqsfn.listen())
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for bayis_sqs_callback-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0638483fceccf9e94682946e20dbcef12de5bf8fc0e643ef1c4118d541f98cc8 |
|
MD5 | 6a8ac8f312b9035b80d85e857ae41343 |
|
BLAKE2b-256 | 3f4d2bb1870d94b3a783eede9c982e78836fcbfac5f4fa41bdd3af40fc23aa8a |