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
2 changes: 2 additions & 0 deletions faststream/nats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
StorageType,
StreamConfig,
StreamSource,
PriorityPolicy
)

from .annotations import NatsMessage
Expand Down Expand Up @@ -63,4 +64,5 @@
"StreamSource",
"TestApp",
"TestNatsBroker",
"PriorityPolicy",
)
12 changes: 12 additions & 0 deletions faststream/nats/broker/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ async def publish(
stream: None = None,
timeout: float | None = None,
schedule: Optional["Schedule"] = None,
msg_ttl: float | None = None,
) -> None: ...

@overload
Expand All @@ -569,6 +570,7 @@ async def publish(
stream: str | None = None,
timeout: float | None = None,
schedule: Optional["Schedule"] = None,
msg_ttl: float | None = None,
) -> "PubAck": ...

@override
Expand All @@ -582,6 +584,7 @@ async def publish(
stream: str | None = None,
timeout: float | None = None,
schedule: Optional["Schedule"] = None,
msg_ttl: float | None = None,
) -> Optional["PubAck"]:
"""Publish message directly.

Expand Down Expand Up @@ -611,6 +614,8 @@ async def publish(
Timeout to send message to NATS.
schedule:
Schedule to publish message at a specific time.
msg_ttl:
Per-message TTL in seconds.

Returns:
`None` if you publishes a regular message.
Expand All @@ -626,6 +631,7 @@ async def publish(
timeout=timeout or 0.5,
_publish_type=PublishType.PUBLISH,
schedule=schedule,
msg_ttl=msg_ttl,
)

result: PubAck | None
Expand All @@ -644,6 +650,7 @@ async def request( # type: ignore[override]
correlation_id: str | None = None,
stream: str | None = None,
timeout: float = 0.5,
msg_ttl: float | None = None,
) -> "NatsMessage":
"""Make a synchronous request to outer subscriber.

Expand All @@ -666,6 +673,8 @@ async def request( # type: ignore[override]
JetStream name. This option is required if your target subscriber listens for events using JetStream.
timeout:
Timeout to send message to NATS.
msg_ttl:
Per-message TTL in seconds.

Returns:
`faststream.nats.message.NatsMessage` object as an outer subscriber response.
Expand All @@ -678,6 +687,7 @@ async def request( # type: ignore[override]
timeout=timeout,
stream=stream,
_publish_type=PublishType.REQUEST,
msg_ttl=msg_ttl,
)

producer = self.config.js_producer if stream is not None else self.config.producer
Expand All @@ -699,6 +709,7 @@ async def key_value(
placement: Optional["Placement"] = None,
republish: Optional["RePublish"] = None,
direct: bool | None = None,
limit_marker_ttl: float | None = None, # in seconds
# custom
declare: bool = True,
) -> "KeyValue":
Expand All @@ -716,6 +727,7 @@ async def key_value(
republish=republish,
direct=direct,
declare=declare,
limit_marker_ttl=limit_marker_ttl,
)

async def object_storage(
Expand Down
78 changes: 78 additions & 0 deletions faststream/nats/broker/registrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ def subscriber(
max_workers: None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
pause_until: str | None = None,
name: str | None = None,
priority_policy: api.PriorityPolicy | None = None,
priority_timeout: float | None = None,
priority_groups: list[str] | None = None,
priority_group: str | None = None,
# AsyncAPI information
title: str | None = None,
description: str | None = None,
Expand Down Expand Up @@ -118,6 +124,12 @@ def subscriber(
max_workers: int = ...,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
pause_until: str | None = None,
name: str | None = None,
priority_policy: api.PriorityPolicy | None = None,
priority_timeout: float | None = None,
priority_groups: list[str] | None = None,
priority_group: str | None = None,
# AsyncAPI information
title: str | None = None,
description: str | None = None,
Expand Down Expand Up @@ -157,6 +169,12 @@ def subscriber(
max_workers: None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
pause_until: str | None = None,
name: str | None = None,
priority_policy: api.PriorityPolicy | None = None,
priority_timeout: float | None = None,
priority_groups: list[str] | None = None,
priority_group: str | None = None,
# AsyncAPI information
title: str | None = None,
description: str | None = None,
Expand Down Expand Up @@ -196,6 +214,12 @@ def subscriber(
max_workers: int = ...,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
pause_until: str | None = None,
name: str | None = None,
priority_policy: api.PriorityPolicy | None = None,
priority_timeout: float | None = None,
priority_groups: list[str] | None = None,
priority_group: str | None = None,
# AsyncAPI information
title: str | None = None,
description: str | None = None,
Expand Down Expand Up @@ -235,6 +259,12 @@ def subscriber(
max_workers: None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
pause_until: str | None = None,
name: str | None = None,
priority_policy: api.PriorityPolicy | None = None,
priority_timeout: float | None = None,
priority_groups: list[str] | None = None,
priority_group: str | None = None,
# AsyncAPI information
title: str | None = None,
description: str | None = None,
Expand Down Expand Up @@ -274,6 +304,12 @@ def subscriber(
max_workers: int = ...,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
pause_until: str | None = None,
name: str | None = None,
priority_policy: api.PriorityPolicy | None = None,
priority_timeout: float | None = None,
priority_groups: list[str] | None = None,
priority_group: str | None = None,
# AsyncAPI information
title: str | None = None,
description: str | None = None,
Expand Down Expand Up @@ -313,6 +349,12 @@ def subscriber(
max_workers: None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
pause_until: str | None = None,
name: str | None = None,
priority_policy: api.PriorityPolicy | None = None,
priority_timeout: float | None = None,
priority_groups: list[str] | None = None,
priority_group: str | None = None,
# AsyncAPI information
title: str | None = None,
description: str | None = None,
Expand Down Expand Up @@ -352,6 +394,12 @@ def subscriber(
max_workers: None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
pause_until: str | None = None,
name: str | None = None,
priority_policy: api.PriorityPolicy | None = None,
priority_timeout: float | None = None,
priority_groups: list[str] | None = None,
priority_group: str | None = None,
# AsyncAPI information
title: str | None = None,
description: str | None = None,
Expand Down Expand Up @@ -391,6 +439,12 @@ def subscriber(
max_workers: None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
pause_until: str | None = None,
name: str | None = None,
priority_policy: api.PriorityPolicy | None = None,
priority_timeout: float | None = None,
priority_groups: list[str] | None = None,
priority_group: str | None = None,
# AsyncAPI information
title: str | None = None,
description: str | None = None,
Expand Down Expand Up @@ -430,6 +484,12 @@ def subscriber(
max_workers: int | None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
pause_until: str | None = None,
name: str | None = None,
priority_policy: api.PriorityPolicy | None = None,
priority_timeout: float | None = None,
priority_groups: list[str] | None = None,
priority_group: str | None = None,
# AsyncAPI information
title: str | None = None,
description: str | None = None,
Expand Down Expand Up @@ -469,6 +529,12 @@ def subscriber(
max_workers: int | None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
pause_until: str | None = None,
name: str | None = None,
priority_policy: api.PriorityPolicy | None = None,
priority_timeout: float | None = None,
priority_groups: list[str] | None = None,
priority_group: str | None = None,
# AsyncAPI information
title: str | None = None,
description: str | None = None,
Expand Down Expand Up @@ -516,6 +582,12 @@ def subscriber(
description: AsyncAPI subscriber object description. Uses decorated docstring as default.
include_in_schema: Whetever to include operation in AsyncAPI schema or not.
persistent: Whether to make the subscriber persistent or not.
pause_until: Consumer pause until timestamp.
name: Consumer name.
priority_policy: priority policy for a consumer.
priority_timeout: the duration (seconds) after which the client will be unpinned if no new.
priority_groups: priority groups this consumer supports.
priority_group: specific priority group.

Returns:
LogicSubscriber[Any]: The created subscriber object.
Expand Down Expand Up @@ -544,6 +616,12 @@ def subscriber(
inbox_prefix=inbox_prefix,
ack_policy=ack_policy,
no_reply=no_reply,
pause_until=pause_until,
name=name,
priority_policy=priority_policy,
priority_timeout=priority_timeout,
priority_groups=priority_groups,
priority_group=priority_group,
broker_config=cast("NatsBrokerConfig", self.config),
# AsyncAPI
title_=title,
Expand Down
2 changes: 2 additions & 0 deletions faststream/nats/helpers/bucket_declarer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async def create_key_value(
placement: Optional["Placement"] = None,
republish: Optional["RePublish"] = None,
direct: bool | None = None,
limit_marker_ttl: float | None = None, # in seconds
# custom
declare: bool = True,
) -> "KeyValue":
Expand All @@ -56,6 +57,7 @@ async def create_key_value(
placement=placement,
republish=republish,
direct=direct,
limit_marker_ttl=limit_marker_ttl,
),
)
else:
Expand Down
2 changes: 2 additions & 0 deletions faststream/nats/publisher/producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ async def publish(self, cmd: "NatsPublishCommand") -> "PubAck":
headers=headers_to_send,
stream=cmd.stream,
timeout=cmd.timeout,
msg_ttl=cmd.msg_ttl,
)

@override
Expand Down Expand Up @@ -198,6 +199,7 @@ async def request(self, cmd: "NatsPublishCommand") -> "Msg":
headers=headers_to_send,
stream=cmd.stream,
timeout=cmd.timeout,
msg_ttl=cmd.msg_ttl,
)

msg = await future
Expand Down
10 changes: 10 additions & 0 deletions faststream/nats/publisher/usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async def publish(
correlation_id: str | None = None,
stream: None = None,
timeout: float | None = None,
msg_ttl: float | None = None,
) -> None: ...

@overload
Expand All @@ -70,6 +71,7 @@ async def publish(
correlation_id: str | None = None,
stream: str | None = None,
timeout: float | None = None,
msg_ttl: float | None = None,
) -> "PubAck": ...

@override
Expand All @@ -82,6 +84,7 @@ async def publish(
correlation_id: str | None = None,
stream: str | None = None,
timeout: float | None = None,
msg_ttl: float | None = None,
) -> Optional["PubAck"]:
"""Publish message directly.

Expand All @@ -104,6 +107,8 @@ async def publish(
Can be omitted without any effect if you doesn't want PubAck frame.
timeout:
Timeout to send message to NATS.
msg_ttl:
Per-message TTL in seconds.

Returns:
`None` if you publishes a regular message.
Expand All @@ -118,6 +123,7 @@ async def publish(
stream=stream or getattr(self.stream, "name", None),
timeout=timeout or self.timeout,
_publish_type=PublishType.PUBLISH,
msg_ttl=msg_ttl,
)

response: PubAck | None
Expand Down Expand Up @@ -177,6 +183,7 @@ async def request(
correlation_id: str | None = None,
stream: str | None = None,
timeout: float = 0.5,
msg_ttl: float | None = None,
) -> "NatsMessage":
"""Make a synchronous request to outer subscriber.

Expand All @@ -199,6 +206,8 @@ async def request(
This allows to make RPC calls over JetStream subjects.
timeout:
Timeout to send message to NATS.
msg_ttl:
Per-message TTL in seconds.

Returns:
`faststream.nats.message.NatsMessage` object as an outer subscriber response.
Expand All @@ -211,6 +220,7 @@ async def request(
correlation_id=correlation_id or self._outer_config.id_generator(),
stream=stream or getattr(self.stream, "name", None),
_publish_type=PublishType.REQUEST,
msg_ttl=msg_ttl,
)

if cmd.stream:
Expand Down
Loading
Loading