Skip to content

NatsResponse

faststream.nats.response.NatsResponse #

NatsResponse(
    body: SendableMessage,
    *,
    headers: dict[str, str] | None = None,
    correlation_id: str | None = None,
    stream: str | None = None,
    schedule: Optional[Schedule] = None,
)

Bases: Response

Source code in faststream/nats/response.py
def __init__(
    self,
    body: "SendableMessage",
    *,
    headers: dict[str, str] | None = None,
    correlation_id: str | None = None,
    stream: str | None = None,
    schedule: Optional["Schedule"] = None,
) -> None:
    super().__init__(
        body=body,
        headers=headers,
        correlation_id=correlation_id,
    )
    self.stream = stream
    self.schedule = schedule

stream instance-attribute #

stream = stream

schedule instance-attribute #

schedule = schedule

body instance-attribute #

body = body

headers instance-attribute #

headers = headers or {}

correlation_id instance-attribute #

correlation_id = correlation_id

as_publish_command #

as_publish_command() -> NatsPublishCommand
Source code in faststream/nats/response.py
@override
def as_publish_command(self) -> "NatsPublishCommand":
    return NatsPublishCommand(
        message=self.body,
        headers=self.headers,
        correlation_id=self.correlation_id,
        _publish_type=PublishType.PUBLISH,
        # Nats specific
        subject="",
        stream=self.stream,
        schedule=self.schedule,
    )

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
def get_publish_key(self) -> 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:
        The key for publishing, or None if this Response type doesn't use keys.
    """
    return None