Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/budziam/amqp-ko-python
Object oriented AMQP layer for microservices communication.
https://github.com/budziam/amqp-ko-python
amqp amqp-ko microservice microservices-communication queue rabbitmq tools
Last synced: 30 days ago
JSON representation
Object oriented AMQP layer for microservices communication.
- Host: GitHub
- URL: https://github.com/budziam/amqp-ko-python
- Owner: budziam
- License: mit
- Created: 2019-08-02T08:28:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-11T19:17:09.000Z (over 5 years ago)
- Last Synced: 2024-12-15T03:13:01.769Z (2 months ago)
- Topics: amqp, amqp-ko, microservice, microservices-communication, queue, rabbitmq, tools
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AMQP Kø
Object oriented AMQP layer for microservices communication.## Usage
The recommended way to use AMQP Kø is to create your own queue object. The simplest way to do this is using `createQueue` function.### Create queue
```python
from amqp_ko import create_queue, AsyncConnection, Message, MessageGate
from dataclasses import dataclass@dataclass(frozen=True)
class TopicFollow(Message):
user_id: int
topic_name: strdef unmarshal_topic_follow(data: dict) -> TopicFollow:
return TopicFollow(
user_id=data["user_id"],
topic_name=data["topic_name"],
)message_gates = [
MessageGate("topic_follow", TopicFollow, unmarshal_topic_follow),
]async with AsyncConnection("localhost", 5672, "rabbitmq", "rabbitmq") as connection:
queue = await create_queue(connection, "exchange-name", message_gates)
```### Consume messages
```python
from amqp_ko import Consumer, Jobclass ConnectUserWithTopic(Consumer):
async def consume(self, job: Job[TopicFollow]):
# Put here some code to connect user with a topic
# using "job.message.user_id" and "job.message.topic_name"
await job.ack()
await queue.consume(
"queue-name",
{TopicFollow: ConnectUserWithTopic()},
)
```### Produce message
```python
message = TopicFollow(120, "entertainment")
await queue.produce(message)
```## Installation
```bash
pip install amqp-ko
```#### Author: [Michał Budziak]
[Michał Budziak]: http://github.com/budziam