Send and receive messages by using SQS queues.
Project description
Send and receive messages by using SQS queues.
pip install comlink
poetry add comlink
Docs
Example
import asyncio
import datetime
from comlink import SqsConsumer, SqsQueue
async def example(sqs_client, queue_url):
# Create a queue object
sqs_queue = SqsQueue(url=queue_url, client=sqs_client)
# Event for stopping the consumer
stop_event = asyncio.Event()
# Create a consumer with a handler that just prints the message
consumer = SqsConsumer(queue=sqs_queue, handler=print)
# Start the consumer
consumer_task = await consumer.start(stop_event=stop_event)
# Send a message to the queue
await sqs_queue.put(f"{datetime.datetime.now()} Hello, world!")
# Wait for 1 second for the message to be processed
await asyncio.sleep(1)
# Stop the consumer
stop_event.set()
# Wait for the consumer to stop
await consumer_task
More examples can be found in the examples directory.
Development
Setup
- Install Poetry.
- Install dependencies with
poetry install
. - Install Docker.
- Run
docker compose -f docker-compose.dev.yml up -d
to start the development environment (localstack). Tests will fail until the environment is up and running.
Testing
Run poetry run pytest
to run the tests.
Formatting
Run poetry run black .
to format the code.
Run poetry run isort .
to sort the imports.
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
comlink-0.2.0.tar.gz
(5.1 kB
view hashes)