Skip to content

Commit

Permalink
fix #53
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancetnik committed Jun 6, 2023
1 parent ffe6421 commit 9caf05d
Show file tree
Hide file tree
Showing 27 changed files with 58 additions and 63 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ from fastapi import Depends, FastAPI
from pydantic import BaseModel
from propan.fastapi import RabbitRouter

app = FastAPI()

router = RabbitRouter("amqp://guest:guest@localhost:5672")

app = FastAPI(lifespan=router.lifespan_context)

class Incoming(BaseModel):
m: dict

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/en/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ Great news! Now **Propan** can be used as a full part of **FastAPI**!
from fastapi import FastAPI
from propan.fastapi import RabbitRouter

app = FastAPI()

router = RabbitRouter("amqp://guest:guest@localhost:5672")

app = FastAPI(lifespan=router.lifespan_context)

@router.event("test")
async def hello(m: dict) -> dict:
return { "response": "Hello Propan!" }
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/ru/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ propan create async [broker] [APPNAME]
from fastapi import FastAPI
from propan.fastapi import RabbitRouter

app = FastAPI()

router = RabbitRouter("amqp://guest:guest@localhost:5672")

app = FastAPI(lifespan=router.lifespan_context)

@router.event("test")
async def hello(m: dict) -> dict:
return { "response": "Hello, Propan!" }
Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/index/kafka/05_native_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from pydantic import BaseModel
from propan.fastapi import KafkaRouter

app = FastAPI()

router = KafkaRouter("localhost:9092")

app = FastAPI(lifespan=router.lifespan_context)

class Incoming(BaseModel):
m: dict

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/index/nats/05_native_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from pydantic import BaseModel
from propan.fastapi import NatsRouter

app = FastAPI()

router = NatsRouter("nats://localhost:4222")

app = FastAPI(lifespan=router.lifespan_context)

class Incoming(BaseModel):
m: dict

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/index/rabbit/05_native_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from pydantic import BaseModel
from propan.fastapi import RabbitRouter

app = FastAPI()

router = RabbitRouter("amqp://guest:guest@localhost:5672")

app = FastAPI(lifespan=router.lifespan_context)

class Incoming(BaseModel):
m: dict

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/index/redis/05_native_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from pydantic import BaseModel
from propan.fastapi import RedisRouter

app = FastAPI()

router = RedisRouter("redis://localhost:6379")

app = FastAPI(lifespan=router.lifespan_context)

class Incoming(BaseModel):
m: dict

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/index/sqs/05_native_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from pydantic import BaseModel
from propan.fastapi import SQSRouter

app = FastAPI()

router = SQSRouter("http://localhost:9324")

app = FastAPI(lifespan=router.lifespan_context)

class Incoming(BaseModel):
m: dict

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/kafka/fastapi_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from pydantic import BaseModel
from propan.fastapi import KafkaRouter

app = FastAPI()

router = KafkaRouter("localhost:9092")

app = FastAPI(lifespan=router.lifespan_context)

class Incoming(BaseModel):
m: dict

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/kafka/fastapi_plugin_depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from propan.fastapi import KafkaRouter
from typing_extensions import Annotated

app = FastAPI()

router = KafkaRouter("localhost:9092")

app = FastAPI(lifespan=router.lifespan_context)

def broker():
return router.broker

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/kafka/fastapi_plugin_send.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from fastapi import FastAPI
from propan.fastapi import KafkaRouter

app = FastAPI()

router = KafkaRouter("localhost:9092")

app = FastAPI(lifespan=router.lifespan_context)

@router.get("/")
async def hello_http():
await router.broker.publish("Hello, Kafka!", "test")
Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/nats/fastapi_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from pydantic import BaseModel
from propan.fastapi import NatsRouter

app = FastAPI()

router = NatsRouter("nats://localhost:4222")

app = FastAPI(lifespan=router.lifespan_context)

class Incoming(BaseModel):
m: dict

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/nats/fastapi_plugin_depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from propan.fastapi import NatsRouter
from typing_extensions import Annotated

app = FastAPI()

router = NatsRouter("nats://localhost:4222")

app = FastAPI(lifespan=router.lifespan_context)

def broker():
return router.broker

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/nats/fastapi_plugin_send.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from fastapi import FastAPI
from propan.fastapi import NatsRouter

app = FastAPI()

router = NatsRouter("nats://localhost:4222")

app = FastAPI(lifespan=router.lifespan_context)

@router.get("/")
async def hello_http():
await router.broker.publish("Hello, Nats!", "test")
Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/rabbit/fastapi_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from pydantic import BaseModel
from propan.fastapi import RabbitRouter

app = FastAPI()

router = RabbitRouter("amqp://guest:guest@localhost:5672")

app = FastAPI(lifespan=router.lifespan_context)

class Incoming(BaseModel):
m: dict

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/rabbit/fastapi_plugin_depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from propan.fastapi import RabbitRouter
from typing_extensions import Annotated

app = FastAPI()

router = RabbitRouter("amqp://guest:guest@localhost:5672")

app = FastAPI(lifespan=router.lifespan_context)

def broker():
return router.broker

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/rabbit/fastapi_plugin_send.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from fastapi import FastAPI
from propan.fastapi import RabbitRouter

app = FastAPI()

router = RabbitRouter("amqp://guest:guest@localhost:5672")

app = FastAPI(lifespan=router.lifespan_context)

@router.get("/")
async def hello_http():
await router.broker.publish("Hello, Rabbit!", "test")
Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/redis/fastapi_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from pydantic import BaseModel
from propan.fastapi import RedisRouter

app = FastAPI()

router = RedisRouter("redis://localhost:6379")

app = FastAPI(lifespan=router.lifespan_context)

class Incoming(BaseModel):
m: dict

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/redis/fastapi_plugin_depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from propan.fastapi import RedisRouter
from typing_extensions import Annotated

app = FastAPI()

router = RedisRouter("redis://localhost:6379")

app = FastAPI(lifespan=router.lifespan_context)

def broker():
return router.broker

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/redis/fastapi_plugin_send.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from fastapi import FastAPI
from propan.fastapi import RedisRouter

app = FastAPI()

router = RedisRouter("redis://localhost:6379")

app = FastAPI(lifespan=router.lifespan_context)

@router.get("/")
async def hello_http():
await router.broker.publish("Hello, Redis!", "test")
Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/sqs/fastapi_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from pydantic import BaseModel
from propan.fastapi import SQSRouter

app = FastAPI()

router = SQSRouter("http://localhost:9324")

app = FastAPI(lifespan=router.lifespan_context)

class Incoming(BaseModel):
m: dict

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/sqs/fastapi_plugin_depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from propan.fastapi import SQSRouter
from typing_extensions import Annotated

app = FastAPI()

router = SQSRouter("http://localhost:9324")

app = FastAPI(lifespan=router.lifespan_context)

def broker():
return router.broker

Expand Down
4 changes: 2 additions & 2 deletions docs/docs_src/integrations/sqs/fastapi_plugin_send.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from fastapi import FastAPI
from propan.fastapi import SQSRouter

app = FastAPI()

router = SQSRouter("http://localhost:9324")

app = FastAPI(lifespan=router.lifespan_context)

@router.get("/")
async def hello_http():
await router.broker.publish("Hello, SQS!", "test")
Expand Down
2 changes: 1 addition & 1 deletion propan/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from unittest.mock import Mock

__version__ = "0.1.2.12"
__version__ = "0.1.2.13"


INSTALL_MESSAGE = (
Expand Down
22 changes: 8 additions & 14 deletions propan/brokers/_model/broker_usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,21 +218,19 @@ def _wrap_decode_message(
params: Sequence[ModelField] = (),
_raw: bool = False,
) -> Callable[[PropanMessage], Awaitable[T]]:
decode: Callable[
[PropanMessage], Awaitable[Union[PropanMessage, DecodedMessage]]
]
if _raw is True:
decode = _fake_decode
else:
decode = self._decode_message

is_unwrap = len(params) > 1

@wraps(func)
async def wrapper(message: PropanMessage) -> T:
msg = await decode(message)
if is_unwrap is True and isinstance(msg, Mapping):
msg = await self._decode_message(message)
message.decoded_body = msg

if _raw is True:
return await func(message)

elif is_unwrap is True and isinstance(msg, Mapping):
return await func(**msg)

else:
return await func(msg)

Expand Down Expand Up @@ -287,7 +285,3 @@ def _log(
self.logger.log(
level=(log_level or self.log_level), msg=message, extra=extra
)


async def _fake_decode(message: PropanMessage) -> PropanMessage:
return message
1 change: 1 addition & 0 deletions propan/brokers/_model/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ class PropanMessage:
reply_to: str = ""
headers: AnyDict = Field(default_factory=dict)
message_id: str = Field(default_factory=lambda: str(uuid4()))
decoded_body: Optional[DecodedMessage] = None
4 changes: 2 additions & 2 deletions propan/fastapi/core/route.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import inspect
from itertools import dropwhile
from typing import Any, Callable, Coroutine, Optional, Union
from typing import Any, Callable, Coroutine, Optional

from fastapi.dependencies.models import Dependant
from fastapi.dependencies.utils import get_dependant, solve_dependencies
Expand Down Expand Up @@ -73,7 +73,7 @@ def get_session(
)

async def app(message: NativeMessage) -> Any:
body: Union[AnyDict, bytes] = message.body
body = message.decoded_body
if first_arg is not None:
if not isinstance(body, dict): # pragma: no branch
body = {first_arg: body}
Expand Down

0 comments on commit 9caf05d

Please sign in to comment.