Skip to content
Merged
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Protobunny

> [!WARNING]
> The project is in early development.
> The project is in early development.
> The core functionality for the available backends is implemented and tested,
> but the public API may undergo breaking changes before the 1.0 release.


Protobunny is the open-source evolution of [AM-Flow](https://am-flow.com)'s internal messaging library.
Expand Down Expand Up @@ -95,6 +97,7 @@ Documentation home page: [https://am-flow.github.io/protobunny/](https://am-flow
- [x] **Result workflow**: Subscribe to results topics and receive protobunny `Result` messages produced by your callbacks.
- [x] **Cloud-Native**: NATS (Core & JetStream) integration.
- [ ] **Cloud Providers**: AWS (SQS/SNS) and GCP Pub/Sub.
- [ ] **OpenTelemetry** Integration (Planned)
- [ ] **More backends**: Kafka support.
- [ ] **gRPC** Direct Call support

Expand Down
35 changes: 30 additions & 5 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
API Reference
=============

Core Package
------------
Core Package Async
------------------

.. automodule:: protobunny
:members:
.. automodule:: protobunny.asyncio
:members:

Core Package Sync
-----------------

.. automodule:: protobunny
:members:
:no-index:

Models
Expand Down Expand Up @@ -48,6 +52,17 @@ Redis aio backend
:members:
:no-index:


NATS aio backend
-----------------
.. automodule:: protobunny.asyncio.backends.nats
:members:
.. automodule:: protobunny.asyncio.backends.nats.connection
:members:
.. automodule:: protobunny.asyncio.backends.nats.queues
:members:
:no-index:

Python aio backend
------------------
.. automodule:: protobunny.asyncio.backends.python
Expand Down Expand Up @@ -91,6 +106,17 @@ Redis backend
:members:
:no-index:

NATS backend
----------------
.. automodule:: protobunny.backends.nats
:members:
.. automodule:: protobunny.backends.nats.connection
:members:
.. automodule:: protobunny.backends.nats.queues
:members:
:no-index:


Python backend
----------------
.. automodule:: protobunny.backends.python
Expand All @@ -113,4 +139,3 @@ protobunny utility
------------------
.. automodule:: protobunny.wrapper
:members:
:undoc-members:
26 changes: 15 additions & 11 deletions docs/source/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ For a full example, using FastAPI, Redis, and protobunny, see [this repo](https:
## Setup

### pyproject.toml
Add `protobunny` to your `pyproject.toml` dependencies:
Add `protobunny` to your `pyproject.toml` dependencies (add the backend you need as extra dependency):

```shell
uv add protobunny[rabbitmq, numpy]
Expand Down Expand Up @@ -325,7 +325,7 @@ messages-directory = "messages"
messages-prefix = "acme"
generated-package-name = "mymessagelib"
generated-package-root = "codegen"
backend = "rabbitmq"
backend = "rabbitmq" # configure here the backend (choose between rabbitmq, redis, mosquitto, nats, python)
mode = "async"
```

Expand Down Expand Up @@ -376,22 +376,19 @@ You should find the generated classes under `codegen/mymessagelib`.
### Python code to test the library

```python

import asyncio
import logging
import sys
import time

import protobunny as pb
from protobunny import asyncio as pb_asyncio

# sys.path.append(pb.default_configuration.generated_package_root)
# this is needed when the python classes for your lib are generated in a subfolder
# that is not in the namespace and it must not be treated as a package
# It's just a sys.path.append("./codegen")
pb.config_lib()
# # sys.path.append(pb.default_configuration.generated_package_root)
# sys.path.append("./codegen")
pb.config_lib() # this is needed when the python classes for your lib are generated in a subfolder

import mymessagelib as ml


logging.basicConfig(
level=logging.INFO, format="[%(asctime)s %(levelname)s] %(name)s - %(message)s"
)
Expand All @@ -411,20 +408,24 @@ class TestLibAsync:

async def worker1(self, task: ml.main.tasks.TaskMessage) -> None:
log.info("1- Working on: %s", task)
await asyncio.sleep(0.1)

async def worker2(self, task: ml.main.tasks.TaskMessage) -> None:
log.info("2- Working on: %s", task)
await asyncio.sleep(0.1)

async def on_message_mymessage(self, message: ml.main.MyMessage) -> None:
log.info("Got main message: %s", message)


def run_forever(self):
asyncio.run(self.main())

def log_callback(self, incoming, body) -> None:
log.info(f"LOG {incoming.routing_key}: {body}")

async def main(self):

await pb_asyncio.subscribe_logger(self.log_callback)
await pb_asyncio.subscribe(ml.main.tasks.TaskMessage, self.worker1)
await pb_asyncio.subscribe(ml.main.tasks.TaskMessage, self.worker2)
Expand Down Expand Up @@ -454,9 +455,11 @@ class TestLib:

def worker1(self, task: ml.main.tasks.TaskMessage) -> None:
log.info("1- Working on: %s", task)
time.sleep(0.1)

def worker2(self, task: ml.main.tasks.TaskMessage) -> None:
log.info("2- Working on: %s", task)
time.sleep(0.1)

def log_callback(self, incoming, body) -> None:
log.info(f"LOG {incoming.routing_key}: {body}")
Expand All @@ -478,7 +481,8 @@ class TestLib:


if __name__ == "__main__":
if conf.use_async:
config = pb.config
if config.use_async:
log.info("Using async")
testlib = TestLibAsync()
pb_asyncio.run_forever(testlib.main)
Expand Down
Loading