Wasla was developed to facilitate the build of events based systems that uses RabbitMQ as the message broker, wasla is built on aio_pika to represent the core of RabbitMQ connection, while wasla provides a mini framework for routing and middlewares. With the right configuration and a well structured routing map, you can publish an event to many consumers with just one line of code.
Project description
wasla Documentation
Overview
Wasla was developed to facilitate the build of events based systems that uses RabbitMQ as the message broker, wasla is built on aio_pika to represent the core of RabbitMQ connection, while wasla provides a mini framework for routing and middlewares. With the right configuration and a well structured routing map, you can publish an event to many consumers with just one line of code.
Installation
pip install wasla
Quick Start
1. Create a Consumer Service
from wasla import Builder, Router
from pydantic import BaseModel
# Define your event schema
class OrderCreatedEvent(BaseModel):
order_id: str
amount: float
# Create router with optional prefix
order_router = Router(prefix="orders")
@order_router.route("created", OrderCreatedEvent)
async def handle_order_created(event: OrderCreatedEvent):
print(f"Processing order {event.order_id}")
# Configure the consumer
builder = Builder(
routing_key="orders.#", # Base routing key
queue_name="order_processor",
concurrency_limit=5 # Max parallel messages
)
# Add components
builder.include_router(order_router)
2. Connect to RabbitMQ
import aio_pika
async def main():
connection = await aio_pika.connect_robust("amqp://guest:guest@localhost/")
channel = await connection.channel()
exchange = await channel.declare_exchange("events", ExchangeType.TOPIC)
# Configure builder
builder.amqp_channel = channel
builder.exchange = exchange
# Start consuming
await builder.run()
asyncio.run(main())
Core Features
Routing System
# With schema validation
@router.route("payment.completed", PaymentEvent)
async def handle_payment(event: PaymentEvent):
pass
# Without validation (accepts any payload)
@router.route("log")
async def handle_logs(event):
pass
Middleware Pipeline
# Custom middleware example
class MetricsMiddleware(MiddlewareInterface):
async def handle(self, request, next):
start = time.time()
await next()
print(f"Request took {time.time()-start:.2f}s")
builder.add_middleware(MetricsMiddleware())
Error Handling
- Automatic retries (3 attempts by default)
Logging Customization
# Customize logger (automatically created if not set)
builder.logger = my_custom_logger
Manual Queue Binding
queue = await channel.declare_queue("custom-queue")
builder.queue = queue # Override auto-created queue
Best Practices
- Schema Validation: Always define Pydantic models for important events
- Concurrency: Set reasonable limits based on your workload
- Monitoring: Check DLQ regularly for failed messages
- Logging: Use the built-in structured logger or integrate with your existing system
Troubleshooting
Common Issues:
ValueError: Exchange must be TOPIC type→ Ensure your exchange is declared asExchangeType.TOPICMessage validation failed→ Verify your Pydantic schemas match the event payloadsQueue binding failed→ Check your routing key patterns (wildcards:#,*)
For additional support, please open an issue.
License
Licensed under the Apache 2.0 License.
See NOTICE for third-party attributions.
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wasla-0.0.1.tar.gz.
File metadata
- Download URL: wasla-0.0.1.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d9cec2361addf7733f5458e31dc7a42ea9a6be9a6d52ed9df2fceed0a062392
|
|
| MD5 |
73009b8c608f9f2d72c8db86a6c88e69
|
|
| BLAKE2b-256 |
e618a3a7c6c3e01768b5f3da1058f587dce900125c02f8b3d2e53dcdfda1044a
|
File details
Details for the file wasla-0.0.1-py3-none-any.whl.
File metadata
- Download URL: wasla-0.0.1-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82d18c48b75c42e91a899767a1f2c3345c3ed08646a1b9b7dcae1977398e2085
|
|
| MD5 |
d10022555563ba1908ba636e492b4b6f
|
|
| BLAKE2b-256 |
495bbef54f82095334d86e8ce108a726f6f5dc31d137e30b4613fce54600f331
|