Skip to content

BatchPublishCommand

faststream.BatchPublishCommand #

BatchPublishCommand(
    body: Any,
    /,
    *bodies: Any,
    _publish_type: PublishType,
    reply_to: str = "",
    destination: str = "",
    correlation_id: str | None = None,
    headers: dict[str, Any] | None = None,
)

Bases: PublishCommand

Source code in faststream/response/response.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
def __init__(
    self,
    body: Any,
    /,
    *bodies: Any,
    _publish_type: PublishType,
    reply_to: str = "",
    destination: str = "",
    correlation_id: str | None = None,
    headers: dict[str, Any] | None = None,
) -> None:
    super().__init__(
        body,
        headers=headers,
        correlation_id=correlation_id,
        destination=destination,
        reply_to=reply_to,
        _publish_type=_publish_type,
    )
    self.extra_bodies = bodies

body instance-attribute #

body = body

headers instance-attribute #

headers = headers or {}

correlation_id instance-attribute #

correlation_id = correlation_id

destination instance-attribute #

destination = destination

reply_to instance-attribute #

reply_to = reply_to

publish_type instance-attribute #

publish_type = _publish_type

extra_bodies instance-attribute #

extra_bodies = bodies

batch_bodies property writable #

batch_bodies: tuple[Any, ...]

as_publish_command #

as_publish_command() -> PublishCommand

Method to transform handlers' Response result to DTO for publishers.

Source code in faststream/response/response.py
22
23
24
25
26
27
28
29
def as_publish_command(self) -> "PublishCommand":
    """Method to transform handlers' Response result to DTO for publishers."""
    return PublishCommand(
        body=self.body,
        headers=self.headers,
        correlation_id=self.correlation_id,
        _publish_type=PublishType.PUBLISH,
    )

get_publish_key #

get_publish_key() -> Any | None

Get the key for publishing this message.

Override this method in subclasses to provide broker-specific keys. Default implementation returns None (no key).

RETURNS DESCRIPTION
Any | None

The key for publishing, or None if this Response type doesn't use keys.

Source code in faststream/response/response.py
31
32
33
34
35
36
37
38
39
40
def get_publish_key(self) -> Any | None:  # noqa: PLR6301
    """Get the key for publishing this message.

    Override this method in subclasses to provide broker-specific keys.
    Default implementation returns None (no key).

    Returns:
        The key for publishing, or None if this Response type doesn't use keys.
    """
    return None

add_headers #

add_headers(
    headers: dict[str, Any], *, override: bool = True
) -> None
Source code in faststream/response/response.py
71
72
73
74
75
76
77
78
79
80
def add_headers(
    self,
    headers: dict[str, Any],
    *,
    override: bool = True,
) -> None:
    if override:
        self.headers |= headers
    else:
        self.headers = headers | self.headers

from_cmd classmethod #

from_cmd(
    cmd: PublishCommand, *, batch: bool = False
) -> BatchPublishCommand
Source code in faststream/response/response.py
122
123
124
125
126
127
128
129
@classmethod
def from_cmd(
    cls,
    cmd: "PublishCommand",
    *,
    batch: bool = False,
) -> "BatchPublishCommand":
    raise NotImplementedError