Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add subscriber no-reply option #1461

Merged
merged 1 commit into from
May 23, 2024
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
1 change: 0 additions & 1 deletion faststream/broker/publisher/usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from faststream.asyncapi.utils import to_camelcase
from faststream.broker.publisher.proto import PublisherProto
from faststream.broker.types import (
BrokerMiddleware,
MsgType,
P_HandlerParams,
T_HandlerReturn,
Expand Down
18 changes: 15 additions & 3 deletions faststream/broker/subscriber/usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from faststream.asyncapi.abc import AsyncAPIOperation
from faststream.asyncapi.message import parse_handler_params
from faststream.asyncapi.utils import to_camelcase
from faststream.broker.publisher.proto import ProducerProto
from faststream.broker.subscriber.call_item import HandlerItem
from faststream.broker.subscriber.proto import SubscriberProto
from faststream.broker.types import (
Expand All @@ -40,6 +39,7 @@

from faststream.broker.message import StreamMessage
from faststream.broker.middlewares import BaseMiddleware
from faststream.broker.publisher.proto import BasePublisherProto, ProducerProto
from faststream.broker.types import (
AsyncCallable,
BrokerMiddleware,
Expand Down Expand Up @@ -93,6 +93,7 @@ def __init__(
self,
*,
no_ack: bool,
no_reply: bool,
retry: Union[bool, int],
broker_dependencies: Iterable["Depends"],
broker_middlewares: Iterable["BrokerMiddleware[MsgType]"],
Expand All @@ -108,6 +109,7 @@ def __init__(

self._default_parser = default_parser
self._default_decoder = default_decoder
self._no_reply = no_reply
# Watcher args
self._no_ack = no_ack
self._retry = retry
Expand Down Expand Up @@ -139,7 +141,7 @@ def setup( # type: ignore[override]
self,
*,
logger: Optional["LoggerProto"],
producer: Optional[ProducerProto],
producer: Optional["ProducerProto"],
graceful_timeout: Optional[float],
extra_context: "AnyDict",
# broker options
Expand Down Expand Up @@ -338,7 +340,7 @@ async def consume(self, msg: MsgType) -> Any:
)

for p in chain(
self._make_response_publisher(message),
self.__get_reponse_publisher(message),
h.handler._publishers,
):
await p.publish(
Expand All @@ -358,6 +360,16 @@ async def consume(self, msg: MsgType) -> Any:

return None

def __get_reponse_publisher(
self,
message: "StreamMessage[MsgType]",
) -> Iterable["BasePublisherProto"]:
if not message.reply_to or self._no_reply:
return ()

else:
return self._make_response_publisher(message)

def get_log_context(
self,
message: Optional["StreamMessage[MsgType]"],
Expand Down
Loading
Loading