faststream_fastapi 1.3.0__tar.gz → 1.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/PKG-INFO +1 -1
  2. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/pyproject.toml +1 -2
  3. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/faststream_api.py +28 -3
  4. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/LICENSE +0 -0
  5. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/README.md +0 -0
  6. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/__about__.py +0 -0
  7. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/__init__.py +0 -0
  8. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/__init__.py +0 -0
  9. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/asyncapi_router.py +0 -0
  10. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/background_middleware.py +0 -0
  11. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/config.py +0 -0
  12. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/fastapi_compat.py +0 -0
  13. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/fs_re_exports/__init__.py +0 -0
  14. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/fs_re_exports/_compat.py +0 -0
  15. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/fs_re_exports/application.py +0 -0
  16. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/fs_re_exports/broker.py +0 -0
  17. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/fs_re_exports/constants.py +0 -0
  18. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/fs_re_exports/context.py +0 -0
  19. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/fs_re_exports/di.py +0 -0
  20. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/fs_re_exports/logger.py +0 -0
  21. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/get_dependant.py +0 -0
  22. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/logger.py +0 -0
  23. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/replace_context.py +0 -0
  24. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/_internal/wrap_callable_to_fastapi_compatible.py +0 -0
  25. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/asyncapi_config.py +0 -0
  26. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/context.py +0 -0
  27. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/py.typed +0 -0
  28. {faststream_fastapi-1.3.0 → faststream_fastapi-1.4.0}/src/faststream_fastapi/stream_message.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: faststream_fastapi
3
- Version: 1.3.0
3
+ Version: 1.4.0
4
4
  Summary: FastAPI integration for FastStream
5
5
  Keywords: rabbitmq,kafka,nats,redis,mqtt,asyncapi,framework,message brokers,fastapi
6
6
  Author: Ivan Kirpichnikov
@@ -13,7 +13,7 @@ license = "MIT"
13
13
  license-files = ["LICENSE"]
14
14
 
15
15
  requires-python = ">=3.10"
16
- version = "1.3.0"
16
+ version = "1.4.0"
17
17
 
18
18
  keywords = [
19
19
  "rabbitmq",
@@ -90,7 +90,6 @@ testing = [
90
90
  testing-dependencies = [
91
91
  "httpx2==2.5.0",
92
92
  "asgi_lifespan==2.1.0",
93
- "zmqtt==0.0.5",
94
93
  "faststream[rabbit,kafka,confluent,nats,redis,mqtt]>=0.7.0",
95
94
  ]
96
95
 
@@ -1,6 +1,7 @@
1
1
  import traceback
2
2
  from collections.abc import AsyncIterator, Awaitable, Callable, Iterable
3
3
  from contextlib import asynccontextmanager
4
+ from logging import getLogger
4
5
  from typing import Any
5
6
 
6
7
  from fastapi import FastAPI
@@ -8,6 +9,7 @@ from fastapi.params import Depends
8
9
  from faststream.message import StreamMessage
9
10
  from faststream.specification.base import SpecificationFactory
10
11
  from starlette.types import Receive, Scope, Send
12
+ from typing_extensions import Self
11
13
 
12
14
  from faststream_fastapi._internal.asyncapi_router import AsyncAPIRouter
13
15
  from faststream_fastapi._internal.background_middleware import _BackgroundMiddleware
@@ -22,6 +24,7 @@ from faststream_fastapi._internal.wrap_callable_to_fastapi_compatible import (
22
24
  )
23
25
  from faststream_fastapi.asyncapi_config import AsyncAPIConfig
24
26
 
27
+ _logger = getLogger(__name__)
25
28
 
26
29
  def _subscriber_compatibility_wrapper(
27
30
  config: Config,
@@ -41,6 +44,10 @@ def _subscriber_compatibility_wrapper(
41
44
  return subscriber_compatibility_wrapper
42
45
 
43
46
 
47
+ async def _default_connection_hook(broker: BrokerUsecase[Any, Any]) -> None:
48
+ await broker.start()
49
+
50
+
44
51
  class FastStreamAPI:
45
52
  def __init__(
46
53
  self,
@@ -50,6 +57,9 @@ class FastStreamAPI:
50
57
  # AsyncAPI
51
58
  specification: SpecificationFactory | None = None,
52
59
  asyncapi_path: str | AsyncAPIConfig | None = None,
60
+ # Low API
61
+ safe_connection: bool = False,
62
+ connection_hook: Callable[[Any], Awaitable[None]] | None = None,
53
63
  ) -> None:
54
64
  self._application = application
55
65
 
@@ -97,6 +107,13 @@ class FastStreamAPI:
97
107
  *subscriber._call_decorators,
98
108
  )
99
109
 
110
+ self._safe_connection = safe_connection
111
+
112
+ if connection_hook is None:
113
+ connection_hook = _default_connection_hook
114
+
115
+ self._connection_hook = connection_hook
116
+
100
117
  # For FastStream docs gen
101
118
  @property
102
119
  def schema(self) -> SpecificationFactory:
@@ -121,8 +138,8 @@ class FastStreamAPI:
121
138
  await receive()
122
139
  try:
123
140
  async with (
124
- self._lifespan_context(app),
125
141
  self._application.router.lifespan_context(app) as maybe_state,
142
+ self._lifespan_context(app),
126
143
  ):
127
144
  if maybe_state is not None:
128
145
  if "state" not in scope:
@@ -145,7 +162,7 @@ class FastStreamAPI:
145
162
  await send({"type": "lifespan.shutdown.complete"})
146
163
 
147
164
  @asynccontextmanager
148
- async def _lifespan_context(self, application: Any) -> AsyncIterator[None]:
165
+ async def _lifespan_context(self, application: Self) -> AsyncIterator[None]:
149
166
  if self._asyncapi_config is not None:
150
167
  asyncapi_router = AsyncAPIRouter(
151
168
  brokers=self._brokers,
@@ -158,10 +175,18 @@ class FastStreamAPI:
158
175
 
159
176
  try:
160
177
  for broker in self._brokers:
161
- await broker.start()
178
+ await self._connect_broker(broker)
162
179
  started_brokers.append(broker)
163
180
 
164
181
  yield None
165
182
  finally:
166
183
  for started_broker in started_brokers:
167
184
  await started_broker.stop()
185
+
186
+ async def _connect_broker(self, broker: BrokerUsecase[Any, Any]) -> None:
187
+ try:
188
+ await self._connection_hook(broker)
189
+ except Exception as error:
190
+ if self._safe_connection:
191
+ raise
192
+ _logger.warning("The start to broker %r was unsuccessful.", broker, exc_info=error)