Skip to content

Commit

Permalink
chore: update docs examples
Browse files Browse the repository at this point in the history
  • Loading branch information
berrytern committed Oct 3, 2024
1 parent 05603dc commit 9ff7727
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
7 changes: 6 additions & 1 deletion amqp_client_python/rabbitmq/async_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,12 @@ async def rpc_subscribe(
)

async def subscribe(
self, queue_name, exchange_name, routing_key, callback, response_timeout
self,
queue_name: str,
exchange_name: str,
routing_key: str,
callback: Callable[[Any], Awaitable[None]],
response_timeout: Optional[float],
):
self.backup["subscribe"][routing_key] = {
"queue_name": queue_name,
Expand Down
21 changes: 10 additions & 11 deletions amqp_client_python/rabbitmq/async_eventbus_rabbitmq.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Awaitable, Optional, Union, Any, List
from typing import Callable, Awaitable, Optional, Union, Any
from .async_connection import AsyncConnection
from ..domain.utils import ConnectionType
from amqp_client_python.domain.models import Config
Expand Down Expand Up @@ -49,15 +49,14 @@ def __init__(
config, loop, rpc_client_publisher_confirms=True,
rpc_server_publisher_confirms=False, rpc_server_auto_ack=False)
### register subscribe
>>> def handler(*body):
>>> def subscribe_handler(body):
print(f"do something with: {body}")
>>> subscribe_event = ExampleEvent("rpc_exchange")
>>> await eventbus.subscribe(subscribe_event, handler, "user.find")
>>> await eventbus.subscribe("rpc_exchange", "user.find", subscribe_handler)
### provide resource
>>> def handler2(*body):
>>> def rpc_provider_handler(body) -> Union[str, bytes]:
print(f"do something with: {body}")
return "response"
>>> await eventbus.provide_resource("user.find2", handle2)
return b"response"
>>> await eventbus.provide_resource("user.find2", rpc_provider_handler)
"""
self._loop: Optional[AbstractEventLoop] = loop
self._signal = Signal()
Expand Down Expand Up @@ -132,7 +131,7 @@ async def rpc_client(
RpcProviderException: if the rpc provider responded with an error
Examples:
>>> await eventbus.rpc_client("example.rpc", "user.find", [{"name": "example"}], "application/json")
>>> await eventbus.rpc_client("example.rpc", "user.find", {"name": "example"}, "application/json")
"""

async def add_rpc_client():
Expand Down Expand Up @@ -212,7 +211,7 @@ async def add_publish():
async def provide_resource(
self,
name: str,
handler: Callable[[List[Any]], Awaitable[Union[bytes, str]]],
handler: Callable[[Any], Awaitable[Union[bytes, str]]],
response_timeout: Optional[int] = None,
connection_timeout: int = 16,
) -> None:
Expand All @@ -232,10 +231,10 @@ async def provide_resource(
AutoReconnectException: when cannout reconnect on the gived timeout
Examples:
>>> async def handle(body) -> Union[bytes, str]:
>>> async def handler(body) -> Union[bytes, str]:
print(f"received message: {body}")
return b"[]"
>>> await eventbus.provide_resource("user.find", handle)
>>> await eventbus.provide_resource("user.find", handler)
"""

async def add_resource():
Expand Down

0 comments on commit 9ff7727

Please sign in to comment.