NatsBroker
faststream.nats.NatsBroker #
NatsBroker(
servers: str | Iterable[str] = (
"nats://localhost:4222",
),
*,
error_cb: Optional[ErrorCallback] = None,
disconnected_cb: Optional[Callback] = None,
closed_cb: Optional[Callback] = None,
discovered_server_cb: Optional[Callback] = None,
reconnected_cb: Optional[Callback] = None,
name: str | None = SERVICE_NAME,
pedantic: bool = False,
verbose: bool = False,
allow_reconnect: bool = True,
connect_timeout: int = DEFAULT_CONNECT_TIMEOUT,
reconnect_time_wait: int = DEFAULT_RECONNECT_TIME_WAIT,
max_reconnect_attempts: int = DEFAULT_MAX_RECONNECT_ATTEMPTS,
ping_interval: int = DEFAULT_PING_INTERVAL,
max_outstanding_pings: int = DEFAULT_MAX_OUTSTANDING_PINGS,
dont_randomize: bool = False,
flusher_queue_size: int = DEFAULT_MAX_FLUSHER_QUEUE_SIZE,
no_echo: bool = False,
tls_hostname: str | None = EMPTY,
token: str | None = EMPTY,
drain_timeout: int = DEFAULT_DRAIN_TIMEOUT,
signature_cb: Optional[SignatureCallback] = EMPTY,
user_jwt_cb: Optional[JWTCallback] = EMPTY,
user_credentials: Optional[Credentials] = EMPTY,
nkeys_seed: str | None = EMPTY,
nkeys_seed_str: str | None = EMPTY,
inbox_prefix: str | bytes = DEFAULT_INBOX_PREFIX,
pending_size: int = DEFAULT_PENDING_SIZE,
flush_timeout: float | None = None,
ws_connection_headers: dict[str, list[str]]
| None = None,
reconnect_to_server_handler: ReconnectToServerHandler
| None = None,
js_options: Union[
JsInitOptions, dict[str, Any], None
] = None,
graceful_timeout: float | None = 15.0,
ack_policy: AckPolicy = EMPTY,
id_generator: IdGenerator = gen_cor_id,
decoder: Optional[CustomCallable] = None,
codec: Optional[CodecProto] = None,
parser: Optional[CustomCallable] = None,
dependencies: Sequence[Dependant] = (),
middlewares: Sequence[BrokerMiddleware[Any, Any]] = (),
routers: Iterable[NatsRegistrator] = (),
security: Optional[BaseSecurity] = None,
specification_url: str | Iterable[str] | None = None,
protocol: str | None = "nats",
protocol_version: str | None = "custom",
description: str | None = None,
tags: Iterable[Union[Tag, TagDict]] = (),
logger: Optional[LoggerProto] = EMPTY,
log_level: int = INFO,
apply_types: bool = True,
serializer: Optional[SerializerProto] = EMPTY,
provider: Optional[Provider] = None,
context: Optional[ContextRepo] = None,
underlying_driver_annotations: UnderlyingDriverAnnotations
| None = None,
)
Bases: NatsRegistrator, BrokerUsecase[Msg, Client, NatsBrokerConfig]
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: |
ws_connection_headers | WebSockets connection headers. TYPE: |
reconnect_to_server_handler | Reconnect to server handler. TYPE: |
js_options | JetStream initialization options. TYPE: |
graceful_timeout | Graceful shutdown timeout. Broker waits for all running subscribers completion before shut down. TYPE: |
ack_policy | Default acknowledgement policy for all subscribers. Individual subscribers can override. TYPE: |
id_generator | Factory used to generate TYPE: |
decoder | Custom decoder object. TYPE: |
codec | Custom codec 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: |
underlying_driver_annotations | Extra driver type hints that FastStream cannot inject, mapped to the annotation to use instead. Merged over the broker's own rows. Wrap a value in TYPE: |
Source code in faststream/nats/broker/broker.py
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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 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 | |
config instance-attribute #
config: ConfigComposition[BrokerConfigType_co] = (
ConfigComposition(config)
)
publish_batch async #
publish_batch(
*messages: SendableMessage, queue: str
) -> Any
Source code in faststream/_internal/broker/pub_base.py
53 54 55 56 57 58 59 | |
add_middleware #
add_middleware(
middleware: BrokerMiddleware[Any, Any],
) -> None
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
56 57 58 59 60 61 | |
insert_middleware #
insert_middleware(
middleware: BrokerMiddleware[Any, Any],
) -> None
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
63 64 65 66 67 68 | |
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: Sequence[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
codec: Optional[CodecProto] = None,
persistent: bool = True,
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: Sequence[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
codec: Optional[CodecProto] = None,
persistent: bool = True,
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: Sequence[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
codec: Optional[CodecProto] = None,
persistent: bool = True,
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: Sequence[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
codec: Optional[CodecProto] = None,
persistent: bool = True,
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: Union[
Literal[True], PullSub[Literal[False]]
] = ...,
kv_watch: None = None,
obj_watch: Literal[False] = False,
inbox_prefix: bytes = INBOX_PREFIX,
stream: Union[str, JStream] = ...,
dependencies: Sequence[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
codec: Optional[CodecProto] = None,
persistent: bool = True,
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: Sequence[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
codec: Optional[CodecProto] = None,
persistent: bool = True,
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[Literal[True]] = ...,
kv_watch: None = None,
obj_watch: Literal[False] = False,
inbox_prefix: bytes = INBOX_PREFIX,
stream: Union[str, JStream] = ...,
dependencies: Sequence[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
codec: Optional[CodecProto] = None,
persistent: bool = True,
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,
) -> BatchPullStreamSubscriber
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: Sequence[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
codec: Optional[CodecProto] = None,
persistent: bool = True,
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: Sequence[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
codec: Optional[CodecProto] = None,
persistent: bool = True,
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: Sequence[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
codec: Optional[CodecProto] = None,
persistent: bool = True,
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: Sequence[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
codec: Optional[CodecProto] = None,
persistent: bool = True,
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: 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: Sequence[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
codec: Optional[CodecProto] = None,
persistent: bool = True,
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]
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: |
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: |
codec | Custom codec object. TYPE: |
max_workers | Number of workers to process messages concurrently. 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
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 | |
publisher #
publisher(
subject: str,
*,
headers: dict[str, str] | None = None,
reply_to: str = "",
stream: Union[str, JStream, None] = None,
timeout: float | None = None,
persistent: bool = True,
title: str | None = None,
description: str | None = None,
schema: Any | None = None,
include_in_schema: bool = True,
) -> LogicPublisher
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: |
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
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 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 | |
include_router #
include_router(
router: NatsRegistrator,
*,
prefix: str = "",
dependencies: Sequence[Dependant] = (),
middlewares: Sequence[BrokerMiddleware[Any, Any]] = (),
include_in_schema: bool | None = None,
) -> None
Source code in faststream/nats/broker/registrator.py
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 | |
include_routers #
include_routers(
*routers: Registrator[MsgType, Any],
) -> None
Includes routers in the object.
Source code in faststream/_internal/broker/registrator.py
128 129 130 131 132 133 134 | |
connect async #
connect() -> ConnectionType
Connect to a remote server.
Source code in faststream/_internal/broker/broker.py
114 115 116 117 118 119 120 | |
stop async #
stop(
exc_type: type[BaseException] | None = None,
exc_val: BaseException | None = None,
exc_tb: Optional[TracebackType] = None,
) -> None
Source code in faststream/nats/broker/broker.py
690 691 692 693 694 695 696 697 698 699 700 701 702 | |
start async #
start() -> None
Connect broker to NATS cluster and startup all subscribers.
Source code in faststream/nats/broker/broker.py
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 | |
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,
schedule: Optional[Schedule] = 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,
schedule: Optional[Schedule] = None,
) -> Optional[PubAck]
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: |
schedule | Schedule to publish message at a specific time. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Optional[PubAck] |
|
Optional[PubAck] |
|
Source code in faststream/nats/broker/broker.py
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 | |
request async #
request(
message: SendableMessage,
subject: str,
headers: dict[str, str] | None = None,
correlation_id: str | None = None,
stream: str | None = None,
timeout: float = 0.5,
) -> NatsMessage
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: |
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
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 | |
key_value async #
key_value(
bucket: str,
*,
description: str | None = None,
max_value_size: int | None = None,
history: int = 1,
ttl: float | None = None,
max_bytes: int | None = None,
storage: Optional[StorageType] = None,
replicas: int = 1,
placement: Optional[Placement] = None,
republish: Optional[RePublish] = None,
direct: bool | None = None,
declare: bool = True,
) -> KeyValue
Source code in faststream/nats/broker/broker.py
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 | |
object_storage async #
object_storage(
bucket: str,
*,
description: str | None = None,
ttl: float | None = None,
max_bytes: int | None = None,
storage: Optional[StorageType] = None,
replicas: int = 1,
placement: Optional[Placement] = None,
declare: bool = True,
) -> ObjectStore
Source code in faststream/nats/broker/broker.py
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 | |
new_inbox async #
new_inbox() -> str
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
Source code in faststream/nats/broker/broker.py
997 998 999 1000 1001 1002 1003 1004 1005 1006 | |
ping async #
ping(timeout: float | None) -> bool
Source code in faststream/nats/broker/broker.py
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 | |