NatsBroker
faststream.nats.NatsBroker
#
NatsBroker(
servers=("nats://localhost:4222",),
*,
error_cb=None,
disconnected_cb=None,
closed_cb=None,
discovered_server_cb=None,
reconnected_cb=None,
name=SERVICE_NAME,
pedantic=False,
verbose=False,
allow_reconnect=True,
connect_timeout=DEFAULT_CONNECT_TIMEOUT,
reconnect_time_wait=DEFAULT_RECONNECT_TIME_WAIT,
max_reconnect_attempts=DEFAULT_MAX_RECONNECT_ATTEMPTS,
ping_interval=DEFAULT_PING_INTERVAL,
max_outstanding_pings=DEFAULT_MAX_OUTSTANDING_PINGS,
dont_randomize=False,
flusher_queue_size=DEFAULT_MAX_FLUSHER_QUEUE_SIZE,
no_echo=False,
tls_hostname=None,
token=None,
drain_timeout=DEFAULT_DRAIN_TIMEOUT,
signature_cb=None,
user_jwt_cb=None,
user_credentials=None,
nkeys_seed=None,
nkeys_seed_str=None,
inbox_prefix=DEFAULT_INBOX_PREFIX,
pending_size=DEFAULT_PENDING_SIZE,
flush_timeout=None,
js_options=None,
graceful_timeout=None,
decoder=None,
parser=None,
dependencies=(),
middlewares=(),
routers=(),
security=None,
specification_url=None,
protocol="nats",
protocol_version="custom",
description=None,
tags=(),
logger=EMPTY,
log_level=INFO,
apply_types=True,
serializer=EMPTY,
provider=None,
context=None,
)
Bases: NatsRegistrator
, BrokerUsecase[Msg, Client]
A class to represent a NATS broker.
Initialize the NatsBroker object.
PARAMETER | DESCRIPTION |
---|---|
servers
|
NATS cluster addresses to connect.
TYPE:
|
error_cb
|
Callback to report errors.
TYPE:
|
disconnected_cb
|
Callback to report disconnection from NATS.
TYPE:
|
closed_cb
|
Callback to report when client stops reconnection to NATS.
TYPE:
|
discovered_server_cb
|
A callback to report when a new server joins the cluster.
TYPE:
|
reconnected_cb
|
Callback to report success reconnection.
TYPE:
|
name
|
Label the connection with name (shown in NATS monitoring).
TYPE:
|
pedantic
|
Turn on NATS server pedantic mode that performs extra checks on the protocol. https://docs.nats.io/using-nats/developer/connecting/misc#turn-on-pedantic-mode
TYPE:
|
verbose
|
Verbose mode produce more feedback about code execution.
TYPE:
|
allow_reconnect
|
Whether recover connection automatically or not.
TYPE:
|
connect_timeout
|
Timeout in seconds to establish connection with NATS server.
TYPE:
|
reconnect_time_wait
|
Time in seconds to wait for reestablish connection to NATS server
TYPE:
|
max_reconnect_attempts
|
Maximum attempts number to reconnect to NATS server.
TYPE:
|
ping_interval
|
Interval in seconds to ping.
TYPE:
|
max_outstanding_pings
|
Maximum number of failed pings
TYPE:
|
dont_randomize
|
Boolean indicating should client randomly shuffle servers list for reconnection randomness.
TYPE:
|
flusher_queue_size
|
Max count of commands awaiting to be flushed to the socket
TYPE:
|
no_echo
|
Boolean indicating should commands be echoed.
TYPE:
|
tls_hostname
|
Hostname for TLS.
TYPE:
|
token
|
Auth token for NATS auth.
TYPE:
|
drain_timeout
|
Timeout in seconds to drain subscriptions.
TYPE:
|
signature_cb
|
A callback used to sign a nonce from the server while authenticating with nkeys. The user should sign the nonce and return the base64 encoded signature.
TYPE:
|
user_jwt_cb
|
A callback used to fetch and return the account signed JWT for this user.
TYPE:
|
user_credentials
|
A user credentials file or tuple of files.
TYPE:
|
nkeys_seed
|
Path-like object containing nkeys seed that will be used.
TYPE:
|
nkeys_seed_str
|
Nkeys seed to be used.
TYPE:
|
inbox_prefix
|
Prefix for generating unique inboxes, subjects with that prefix and NUID.ß
TYPE:
|
pending_size
|
Max size of the pending buffer for publishing commands.
TYPE:
|
flush_timeout
|
Max duration to wait for a forced flush to occur
TYPE:
|
js_options
|
JetStream initialization options.
TYPE:
|
graceful_timeout
|
Graceful shutdown timeout. Broker waits for all running subscribers completion before shut down.
TYPE:
|
decoder
|
Custom decoder object
TYPE:
|
parser
|
Custom parser object.
TYPE:
|
dependencies
|
Dependencies to apply to all broker subscribers.
TYPE:
|
middlewares
|
"Middlewares to apply to all broker publishers/subscribers.
TYPE:
|
routers
|
"Routers to apply to broker.
TYPE:
|
security
|
Security options to connect broker and generate AsyncAPI server security information.
TYPE:
|
specification_url
|
AsyncAPI hardcoded server addresses. Use
TYPE:
|
protocol
|
AsyncAPI server protocol.
TYPE:
|
protocol_version
|
AsyncAPI server protocol version.
TYPE:
|
description
|
AsyncAPI server description.
TYPE:
|
tags
|
AsyncAPI server tags. |
logger
|
User specified logger to pass into Context and log service messages.
TYPE:
|
log_level
|
Service messages log level.
TYPE:
|
apply_types
|
Whether to use FastDepends or not.
TYPE:
|
serializer
|
FastDepends-compatible serializer to validate incoming messages.
TYPE:
|
provider
|
Provider for FastDepends.
TYPE:
|
context
|
Context for FastDepends.
TYPE:
|
Source code in faststream/nats/broker/broker.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
|
publish_batch
async
#
add_middleware
#
Append BrokerMiddleware to the end of middlewares list.
Current middleware will be used as a most inner of the stack.
Source code in faststream/_internal/broker/registrator.py
insert_middleware
#
Insert BrokerMiddleware to the start of middlewares list.
Current middleware will be used as a most outer of the stack.
Source code in faststream/_internal/broker/registrator.py
subscriber
#
subscriber(
subject: str = "",
queue: str = "",
pending_msgs_limit: int | None = None,
pending_bytes_limit: int | None = None,
max_msgs: int = 0,
durable: None = None,
config: None = None,
ordered_consumer: Literal[False] = False,
idle_heartbeat: None = None,
flow_control: None = None,
deliver_policy: None = None,
headers_only: None = None,
pull_sub: Literal[False] = False,
kv_watch: None = None,
obj_watch: Literal[False] = False,
inbox_prefix: bytes = INBOX_PREFIX,
stream: None = None,
dependencies: Iterable[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
persistent: bool = True,
ack_first: bool = EMPTY,
middlewares: Sequence[SubscriberMiddleware[Any]] = (),
no_ack: bool = EMPTY,
max_workers: None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
title: str | None = None,
description: str | None = None,
include_in_schema: bool = True,
) -> CoreSubscriber
subscriber(
subject: str = "",
queue: str = "",
pending_msgs_limit: int | None = None,
pending_bytes_limit: int | None = None,
max_msgs: int = 0,
durable: None = None,
config: None = None,
ordered_consumer: Literal[False] = False,
idle_heartbeat: None = None,
flow_control: None = None,
deliver_policy: None = None,
headers_only: None = None,
pull_sub: Literal[False] = False,
kv_watch: None = None,
obj_watch: Literal[False] = False,
inbox_prefix: bytes = INBOX_PREFIX,
stream: None = None,
dependencies: Iterable[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
persistent: bool = True,
ack_first: bool = EMPTY,
middlewares: Sequence[SubscriberMiddleware[Any]] = (),
no_ack: bool = EMPTY,
max_workers: int = ...,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
title: str | None = None,
description: str | None = None,
include_in_schema: bool = True,
) -> ConcurrentCoreSubscriber
subscriber(
subject: str = "",
queue: str = "",
pending_msgs_limit: int | None = None,
pending_bytes_limit: int | None = None,
max_msgs: int = 0,
durable: str | None = None,
config: Optional[ConsumerConfig] = None,
ordered_consumer: bool = False,
idle_heartbeat: float | None = None,
flow_control: bool | None = None,
deliver_policy: Optional[DeliverPolicy] = None,
headers_only: bool | None = None,
pull_sub: Literal[False] = False,
kv_watch: None = None,
obj_watch: Literal[False] = False,
inbox_prefix: bytes = INBOX_PREFIX,
stream: Union[str, JStream] = ...,
dependencies: Iterable[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
persistent: bool = True,
ack_first: bool = EMPTY,
middlewares: Sequence[SubscriberMiddleware[Any]] = (),
no_ack: bool = EMPTY,
max_workers: None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
title: str | None = None,
description: str | None = None,
include_in_schema: bool = True,
) -> PushStreamSubscriber
subscriber(
subject: str = "",
queue: str = "",
pending_msgs_limit: int | None = None,
pending_bytes_limit: int | None = None,
max_msgs: int = 0,
durable: str | None = None,
config: Optional[ConsumerConfig] = None,
ordered_consumer: bool = False,
idle_heartbeat: float | None = None,
flow_control: bool | None = None,
deliver_policy: Optional[DeliverPolicy] = None,
headers_only: bool | None = None,
pull_sub: Literal[False] = False,
kv_watch: None = None,
obj_watch: Literal[False] = False,
inbox_prefix: bytes = INBOX_PREFIX,
stream: Union[str, JStream] = ...,
dependencies: Iterable[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
persistent: bool = True,
ack_first: bool = EMPTY,
middlewares: Sequence[SubscriberMiddleware[Any]] = (),
no_ack: bool = EMPTY,
max_workers: int = ...,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
title: str | None = None,
description: str | None = None,
include_in_schema: bool = True,
) -> ConcurrentPushStreamSubscriber
subscriber(
subject: str = "",
queue: str = "",
pending_msgs_limit: int | None = None,
pending_bytes_limit: int | None = None,
max_msgs: int = 0,
durable: str | None = None,
config: Optional[ConsumerConfig] = None,
ordered_consumer: bool = False,
idle_heartbeat: float | None = None,
flow_control: bool | None = None,
deliver_policy: Optional[DeliverPolicy] = None,
headers_only: bool | None = None,
pull_sub: Literal[True] = ...,
kv_watch: None = None,
obj_watch: Literal[False] = False,
inbox_prefix: bytes = INBOX_PREFIX,
stream: Union[str, JStream] = ...,
dependencies: Iterable[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
persistent: bool = True,
ack_first: bool = EMPTY,
middlewares: Sequence[SubscriberMiddleware[Any]] = (),
no_ack: bool = EMPTY,
max_workers: None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
title: str | None = None,
description: str | None = None,
include_in_schema: bool = True,
) -> PullStreamSubscriber
subscriber(
subject: str = "",
queue: str = "",
pending_msgs_limit: int | None = None,
pending_bytes_limit: int | None = None,
max_msgs: int = 0,
durable: str | None = None,
config: Optional[ConsumerConfig] = None,
ordered_consumer: bool = False,
idle_heartbeat: float | None = None,
flow_control: bool | None = None,
deliver_policy: Optional[DeliverPolicy] = None,
headers_only: bool | None = None,
pull_sub: Literal[True] = ...,
kv_watch: None = None,
obj_watch: Literal[False] = False,
inbox_prefix: bytes = INBOX_PREFIX,
stream: Union[str, JStream] = ...,
dependencies: Iterable[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
persistent: bool = True,
ack_first: bool = EMPTY,
middlewares: Sequence[SubscriberMiddleware[Any]] = (),
no_ack: bool = EMPTY,
max_workers: int = ...,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
title: str | None = None,
description: str | None = None,
include_in_schema: bool = True,
) -> ConcurrentPullStreamSubscriber
subscriber(
subject: str = "",
queue: str = "",
pending_msgs_limit: int | None = None,
pending_bytes_limit: int | None = None,
max_msgs: int = 0,
durable: str | None = None,
config: Optional[ConsumerConfig] = None,
ordered_consumer: bool = False,
idle_heartbeat: float | None = None,
flow_control: bool | None = None,
deliver_policy: Optional[DeliverPolicy] = None,
headers_only: bool | None = None,
pull_sub: PullSub = ...,
kv_watch: None = None,
obj_watch: Literal[False] = False,
inbox_prefix: bytes = INBOX_PREFIX,
stream: Union[str, JStream] = ...,
dependencies: Iterable[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
persistent: bool = True,
ack_first: bool = EMPTY,
middlewares: Sequence[SubscriberMiddleware[Any]] = (),
no_ack: bool = EMPTY,
max_workers: None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
title: str | None = None,
description: str | None = None,
include_in_schema: bool = True,
) -> Union[PullStreamSubscriber, BatchPullStreamSubscriber]
subscriber(
subject: str = "",
queue: str = "",
pending_msgs_limit: int | None = None,
pending_bytes_limit: int | None = None,
max_msgs: int = 0,
durable: None = None,
config: None = None,
ordered_consumer: Literal[False] = False,
idle_heartbeat: None = None,
flow_control: None = None,
deliver_policy: None = None,
headers_only: None = None,
pull_sub: Literal[False] = False,
kv_watch: Union[str, KvWatch] = ...,
obj_watch: Literal[False] = False,
inbox_prefix: bytes = INBOX_PREFIX,
stream: None = None,
dependencies: Iterable[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
persistent: bool = True,
ack_first: bool = EMPTY,
middlewares: Sequence[SubscriberMiddleware[Any]] = (),
no_ack: bool = EMPTY,
max_workers: None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
title: str | None = None,
description: str | None = None,
include_in_schema: bool = True,
) -> KeyValueWatchSubscriber
subscriber(
subject: str = "",
queue: str = "",
pending_msgs_limit: int | None = None,
pending_bytes_limit: int | None = None,
max_msgs: int = 0,
durable: None = None,
config: None = None,
ordered_consumer: Literal[False] = False,
idle_heartbeat: None = None,
flow_control: None = None,
deliver_policy: None = None,
headers_only: None = None,
pull_sub: Literal[False] = False,
kv_watch: None = None,
obj_watch: Union[Literal[True], ObjWatch] = ...,
inbox_prefix: bytes = INBOX_PREFIX,
stream: None = None,
dependencies: Iterable[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
persistent: bool = True,
ack_first: bool = EMPTY,
middlewares: Sequence[SubscriberMiddleware[Any]] = (),
no_ack: bool = EMPTY,
max_workers: None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
title: str | None = None,
description: str | None = None,
include_in_schema: bool = True,
) -> ObjStoreWatchSubscriber
subscriber(
subject: str = "",
queue: str = "",
pending_msgs_limit: int | None = None,
pending_bytes_limit: int | None = None,
max_msgs: int = 0,
durable: str | None = None,
config: Optional[ConsumerConfig] = None,
ordered_consumer: bool = False,
idle_heartbeat: float | None = None,
flow_control: bool | None = None,
deliver_policy: Optional[DeliverPolicy] = None,
headers_only: bool | None = None,
pull_sub: Union[bool, PullSub] = False,
kv_watch: Union[str, KvWatch, None] = None,
obj_watch: Union[bool, ObjWatch] = False,
inbox_prefix: bytes = INBOX_PREFIX,
stream: Union[str, JStream, None] = None,
dependencies: Iterable[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
persistent: bool = True,
ack_first: bool = EMPTY,
middlewares: Sequence[SubscriberMiddleware[Any]] = (),
no_ack: bool = EMPTY,
max_workers: int | None = None,
ack_policy: AckPolicy = EMPTY,
no_reply: bool = False,
title: str | None = None,
description: str | None = None,
include_in_schema: bool = True,
) -> LogicSubscriber[Any]
subscriber(
subject="",
queue="",
pending_msgs_limit=None,
pending_bytes_limit=None,
max_msgs=0,
durable=None,
config=None,
ordered_consumer=False,
idle_heartbeat=None,
flow_control=None,
deliver_policy=None,
headers_only=None,
pull_sub=False,
kv_watch=None,
obj_watch=False,
inbox_prefix=INBOX_PREFIX,
stream=None,
dependencies=(),
parser=None,
decoder=None,
persistent=True,
ack_first=EMPTY,
middlewares=(),
no_ack=EMPTY,
max_workers=None,
ack_policy=EMPTY,
no_reply=False,
title=None,
description=None,
include_in_schema=True,
)
Creates NATS subscriber object.
You can use it as a handler decorator @broker.subscriber(...)
.
PARAMETER | DESCRIPTION |
---|---|
subject
|
NATS subject to subscribe.
TYPE:
|
queue
|
Subscribers' NATS queue name. Subscribers with same queue name will be load balanced by the NATS server.
TYPE:
|
pending_msgs_limit
|
Limit of messages, considered by NATS server as possible to be delivered to the client without been answered. In case of NATS Core, if that limits exceeds, you will receive NATS 'Slow Consumer' error. That's literally means that your worker can't handle the whole load. In case of NATS JetStream, you will no longer receive messages until some of delivered messages will be acked in any way.
TYPE:
|
pending_bytes_limit
|
The number of bytes, considered by NATS server as possible to be delivered to the client without been answered. In case of NATS Core, if that limit exceeds, you will receive NATS 'Slow Consumer' error. That's literally means that your worker can't handle the whole load. In case of NATS JetStream, you will no longer receive messages until some of delivered messages will be acked in any way.
TYPE:
|
max_msgs
|
Consuming messages limiter. Automatically disconnect if reached.
TYPE:
|
durable
|
Name of the durable consumer to which the the subscription should be bound.
TYPE:
|
config
|
Configuration of JetStream consumer to be subscribed with.
TYPE:
|
ordered_consumer
|
Enable ordered consumer mode.
TYPE:
|
idle_heartbeat
|
Enable Heartbeats for a consumer to detect failures.
TYPE:
|
flow_control
|
Enable Flow Control for a consumer.
TYPE:
|
deliver_policy
|
Deliver Policy to be used for subscription.
TYPE:
|
headers_only
|
Should be message delivered without payload, only headers and metadata.
TYPE:
|
pull_sub
|
NATS Pull consumer parameters container. Should be used with
TYPE:
|
kv_watch
|
KeyValue watch parameters container.
TYPE:
|
obj_watch
|
ObjectStore watch parameters container.
TYPE:
|
inbox_prefix
|
Prefix for generating unique inboxes, subjects with that prefix and NUID.
TYPE:
|
ack_first
|
Whether to
TYPE:
|
stream
|
Subscribe to NATS Stream with
TYPE:
|
dependencies
|
Dependencies list (
TYPE:
|
parser
|
Parser to map original nats-py Msg to FastStream one.
TYPE:
|
decoder
|
Function to decode FastStream msg bytes body to python objects.
TYPE:
|
middlewares
|
Subscriber middlewares to wrap incoming message processing.
TYPE:
|
max_workers
|
Number of workers to process messages concurrently.
TYPE:
|
no_ack
|
Whether to disable FastStream auto acknowledgement logic or not.
TYPE:
|
ack_policy
|
Whether to
TYPE:
|
no_reply
|
Whether to disable FastStream RPC and Reply To auto responses or not.
TYPE:
|
title
|
AsyncAPI subscriber object title.
TYPE:
|
description
|
AsyncAPI subscriber object description. Uses decorated docstring as default.
TYPE:
|
include_in_schema
|
Whetever to include operation in AsyncAPI schema or not.
TYPE:
|
persistent
|
Whether to make the subscriber persistent or not.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
LogicSubscriber[Any]
|
LogicSubscriber[Any]: The created subscriber object. |
Source code in faststream/nats/broker/registrator.py
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 |
|
publisher
#
publisher(
subject,
*,
headers=None,
reply_to="",
stream=None,
timeout=None,
persistent=True,
middlewares=(),
title=None,
description=None,
schema=None,
include_in_schema=True,
)
Creates long-living and AsyncAPI-documented publisher object.
You can use it as a handler decorator (handler should be decorated by @broker.subscriber(...)
too) - @broker.publisher(...)
.
In such case publisher will publish your handler return value.
Or you can create a publisher object to call it lately - broker.publisher(...).publish(...)
.
PARAMETER | DESCRIPTION |
---|---|
subject
|
NATS subject to send message.
TYPE:
|
headers
|
Message headers to store metainformation.
content-type and correlation_id will be set automatically by framework anyway.
Can be overridden by
TYPE:
|
reply_to
|
NATS subject name to send response.
TYPE:
|
stream
|
This option validates that the target
TYPE:
|
timeout
|
Timeout to send message to NATS.
TYPE:
|
middlewares
|
Publisher middlewares to wrap outgoing messages.
TYPE:
|
title
|
AsyncAPI publisher object title.
TYPE:
|
description
|
AsyncAPI publisher object description.
TYPE:
|
schema
|
AsyncAPI publishing message type.
Should be any python-native object annotation or
TYPE:
|
include_in_schema
|
Whetever to include operation in AsyncAPI schema or not.
TYPE:
|
persistent
|
Whether to make the publisher persistent or not.
TYPE:
|
Source code in faststream/nats/broker/registrator.py
include_router
#
Source code in faststream/nats/broker/registrator.py
include_routers
#
connect
async
#
stop
async
#
Source code in faststream/nats/broker/broker.py
close
async
#
Source code in faststream/nats/broker/broker.py
start
async
#
Connect broker to NATS cluster and startup all subscribers.
Source code in faststream/nats/broker/broker.py
publish
async
#
publish(
message: SendableMessage,
subject: str,
headers: dict[str, str] | None = None,
reply_to: str = "",
correlation_id: str | None = None,
stream: None = None,
timeout: float | None = None,
) -> None
publish(
message: SendableMessage,
subject: str,
headers: dict[str, str] | None = None,
reply_to: str = "",
correlation_id: str | None = None,
stream: str | None = None,
timeout: float | None = None,
) -> PubAck
publish(
message,
subject,
headers=None,
reply_to="",
correlation_id=None,
stream=None,
timeout=None,
)
Publish message directly.
This method allows you to publish message in not AsyncAPI-documented way. You can use it in another frameworks applications or to publish messages from time to time.
Please, use @broker.publisher(...)
or broker.publisher(...).publish(...)
instead in a regular way.
PARAMETER | DESCRIPTION |
---|---|
message
|
Message body to send.
Can be any encodable object (native python types or
TYPE:
|
subject
|
NATS subject to send message.
TYPE:
|
headers
|
Message headers to store metainformation. content-type and correlation_id will be set automatically by framework anyway.
TYPE:
|
reply_to
|
NATS subject name to send response.
TYPE:
|
correlation_id
|
Manual message correlation_id setter. correlation_id is a useful option to trace messages.
TYPE:
|
stream
|
This option validates that the target subject is in presented stream. Can be omitted without any effect if you doesn't want PubAck frame.
TYPE:
|
timeout
|
Timeout to send message to NATS.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Optional[PubAck]
|
|
Optional[PubAck]
|
|
Source code in faststream/nats/broker/broker.py
request
async
#
Make a synchronous request to outer subscriber.
If out subscriber listens subject by stream, you should setup the same stream explicitly. Another way you will reseave confirmation frame as a response.
PARAMETER | DESCRIPTION |
---|---|
message
|
Message body to send.
Can be any encodable object (native python types or
TYPE:
|
subject
|
NATS subject to send message.
TYPE:
|
headers
|
Message headers to store metainformation. content-type and correlation_id will be set automatically by framework anyway.
TYPE:
|
reply_to
|
NATS subject name to send response.
|
correlation_id
|
Manual message correlation_id setter. correlation_id is a useful option to trace messages.
TYPE:
|
stream
|
JetStream name. This option is required if your target subscriber listens for events using JetStream.
TYPE:
|
timeout
|
Timeout to send message to NATS.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NatsMessage
|
|
Source code in faststream/nats/broker/broker.py
key_value
async
#
key_value(
bucket,
*,
description=None,
max_value_size=None,
history=1,
ttl=None,
max_bytes=None,
storage=None,
replicas=1,
placement=None,
republish=None,
direct=None,
declare=True,
)
Source code in faststream/nats/broker/broker.py
object_storage
async
#
object_storage(
bucket,
*,
description=None,
ttl=None,
max_bytes=None,
storage=None,
replicas=1,
placement=None,
declare=True,
)
Source code in faststream/nats/broker/broker.py
new_inbox
async
#
Return a unique inbox that can be used for NATS requests or subscriptions.
The inbox prefix can be customised by passing inbox_prefix
when creating your NatsBroker
.
This method calls nats.aio.client.Client.new_inbox
[1] under the hood.
[1] https://nats-io.github.io/nats.py/modules.html#nats.aio.client.Client.new_inbox