Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ jobs:
image: rabbitmq:4.0.2-alpine
ports:
- 5672:5672
redis:
image: redis:7.4.1-alpine
ports:
- 6379:6379
strategy:
fail-fast: false
matrix:
Expand All @@ -88,7 +92,7 @@ jobs:
- name: Install the project dependencies
run: poetry install --all-extras
- name: Run pytest
run: poetry run pytest --broker-url=amqp://guest:guest@localhost:5672/ --broker-retry-delay=3 --broker-retry-delay-mode=constant --broker-retries-limit=10 --cov-report=xml
run: poetry run pytest --broker-retry-delay=3 --broker-retry-delay-mode=constant --broker-retries-limit=10 --cov-report=xml
- name: Upload results to Codecov
uses: codecov/codecov-action@v4
with:
Expand Down
56 changes: 45 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ message brokers.

## key features

* builtin CLI to work with broker
* same protobuf structures as in gRPC
* similar calls as in gRPC
* unary-unary
* (TODO) unary-stream
* (TODO) stream-unary
* (TODO) stream-stream
* declarative style, abstract from broker commands (such as declare_exchange / queue_bind)
* resource declarative style, no broker commands (just `async with broker.publisher(...)` or `async with broker.consumer(...)`)
* publisher & consumer middlewares
* message serializers

Expand All @@ -30,27 +31,56 @@ pyprotostuben project example for more details.

You may configure codegen output using protobuf extensions from [buf schema registry](https://buf.build/zerlok/brokrpc).

## supported brokers & protocols
## drivers

* [AMQP](https://www.rabbitmq.com/tutorials/amqp-concepts)
* [aiormq](https://github.com/mosquito/aiormq)
* (TODO) redis
* (TODO) kafka
* (TODO) NATS
| driver | broker |
|------------|----------|
| `aiormq` | RabbitMQ |
| `aioredis` | Redis |
| (TODO) | Kafka |
| (TODO) | NATs |

## usage

[pypi package](https://pypi.python.org/pypi/BrokRPC)

install with your favorite python package manager
install with your favorite python package manager, specify driver in extra (e.g. for `aiormq`):

```shell
pip install BrokRPC[aiormq]
```

### CLI

`brokrpc` commands either publish messages from stdin or prints consumed messages to stdout. See help for more info.

```shell
brokrpc --help
```

#### examples

Start JSON publisher (press `ctrl+d` to stop):

```shell
brokrpc amqp://guest:guest@localhost:5672/ publish -e my-exchange my-rk --encoder=json
```

Start JSON consumer (press `ctrl+d` to stop):

```shell
brokrpc amqp://guest:guest@localhost:5672/ consume -e my-exchange my-rk --decoder=json
```

Check broker connection (returns `0` exit code on success and `1` on failure):

```shell
brokrpc --retry-delay=3 --retries-limit=10 amqp://guest:guest@localhost:5672/ check
```

### Broker

use Broker as high level API to create consumers & publishers
Broker class is a part of high-level API. All consumers & publishers are created via this class.

```python
from brokrpc.broker import Broker
Expand All @@ -62,6 +92,10 @@ async with Broker(...) as broker:
...
```

### BrokerDriver

Driver is a part of low-level API. Broker delegates calls to driver.

### Consumer

```python
Expand All @@ -75,7 +109,7 @@ from brokrpc.serializer.json import JSONSerializer
async def register_consumer(broker: Broker) -> None:
# define consumer function (you also can use async function & `Consumer` interface).
def consume_binary_message(message: Message[bytes]) -> None:
print(message)
print(message)

# consumer is not attached yet

Expand Down Expand Up @@ -204,7 +238,7 @@ async def main() -> None:

# connect to broker
async with broker:
# start RPC server until SIGINT or SIGTERM
# run RPC server until SIGINT or SIGTERM
await server.run_until_terminated()


Expand Down
7 changes: 6 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
version: '3.3'
version: '3.7'

services:
rabbitmq:
image: rabbitmq:4.0.2-management-alpine
ports:
- "5672:5672"
- "15672:15672"

redis:
image: redis:7.4.1-alpine
ports:
- "6379:6379"
Loading