Skip to content

RabbitPublisher

faststream.rabbit.RabbitPublisher #

RabbitPublisher(
    queue: Union[RabbitQueue, str] = "",
    exchange: Union[RabbitExchange, str, None] = None,
    *,
    routing_key: str = "",
    mandatory: bool = True,
    immediate: bool = False,
    timeout: TimeoutType = None,
    persist: bool = False,
    reply_to: str | None = None,
    priority: int | None = None,
    title: str | None = None,
    description: str | None = None,
    schema: Any | None = None,
    include_in_schema: bool = True,
    headers: Optional[HeadersType] = None,
    content_type: str | None = None,
    content_encoding: str | None = None,
    expiration: Optional[DateType] = None,
    message_type: str | None = None,
    user_id: str | None = None,
    persistent: bool = True,
)

Bases: ArgsContainer

Delayed RabbitPublisher registration object.

Just a copy of RabbitRegistrator.publisher(...) arguments.

Initialized RabbitPublisher.

PARAMETER DESCRIPTION
queue

Default message routing key to publish with. Can be any RabbitQueue instance or string representation of the queue.

TYPE: Union[RabbitQueue, str] DEFAULT: ''

exchange

Target exchange to publish message to. Any RabbitExchange instance or string representation of the exchange. If not specified, it will default to the value provided in queue.

TYPE: Union[RabbitExchange, str, None] DEFAULT: None

routing_key

Default message routing key to publish with. Overrides queue option if presented.

TYPE: str DEFAULT: ''

mandatory

Client waits for confirmation that the message is placed to some queue. RabbitMQ returns message to client if there is no suitable queue.

TYPE: bool DEFAULT: True

immediate

Client expects that there is consumer ready to take the message to work. RabbitMQ returns message to client if there is no suitable consumer.

TYPE: bool DEFAULT: False

timeout

Send confirmation time from RabbitMQ.

TYPE: TimeoutType DEFAULT: None

persist

Restore the message on RabbitMQ reboot.

TYPE: bool DEFAULT: False

reply_to

Reply message routing key to send with (always sending to default exchange).

TYPE: str | None DEFAULT: None

priority

The message priority (0 by default).

TYPE: int | None DEFAULT: None

title

AsyncAPI publisher object title.

TYPE: str | None DEFAULT: None

description

AsyncAPI publisher object description.

TYPE: str | None DEFAULT: None

schema

AsyncAPI publishing message type. Should be any python-native object annotation or pydantic.BaseModel.

TYPE: Any | None DEFAULT: None

include_in_schema

Whetever to include operation in AsyncAPI schema or not.

TYPE: bool DEFAULT: True

headers

Message headers to store metainformation. Can be overridden by publish.headers if specified.

TYPE: Optional[HeadersType] DEFAULT: None

content_type

Message content-type header. Used by application, not core RabbitMQ. Will be set automatically if not specified.

TYPE: str | None DEFAULT: None

content_encoding

Message body content encoding, e.g. gzip.

TYPE: str | None DEFAULT: None

expiration

Message expiration (lifetime) in seconds (or datetime or timedelta).

TYPE: Optional[DateType] DEFAULT: None

message_type

Application-specific message type, e.g. orders.created.

TYPE: str | None DEFAULT: None

user_id

Publisher connection User ID, validated if set.

TYPE: str | None DEFAULT: None

persistent

Whether to make the publisher persistent or not.

TYPE: bool DEFAULT: True

Source code in faststream/rabbit/broker/router.py
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
def __init__(
    self,
    queue: Union["RabbitQueue", str] = "",
    exchange: Union["RabbitExchange", str, None] = None,
    *,
    routing_key: str = "",
    mandatory: bool = True,
    immediate: bool = False,
    timeout: "TimeoutType" = None,
    persist: bool = False,
    reply_to: str | None = None,
    priority: int | None = None,
    # AsyncAPI args
    title: str | None = None,
    description: str | None = None,
    schema: Any | None = None,
    include_in_schema: bool = True,
    # message args
    headers: Optional["HeadersType"] = None,
    content_type: str | None = None,
    content_encoding: str | None = None,
    expiration: Optional["DateType"] = None,
    message_type: str | None = None,
    user_id: str | None = None,
    persistent: bool = True,
) -> None:
    """Initialized RabbitPublisher.

    Args:
        queue:
            Default message routing key to publish with.
            Can be any `RabbitQueue` instance or string representation of the queue.
        exchange:
            Target exchange to publish message to.
            Any `RabbitExchange` instance or string representation of the exchange. If not
            specified, it will default to the value provided in `queue`.
        routing_key:
            Default message routing key to publish with. Overrides `queue`
            option if presented.
        mandatory:
            Client waits for confirmation that the message is placed to some queue.
            RabbitMQ returns message to client if there is no suitable queue.
        immediate:
            Client expects that there is consumer ready to take the message to work.
            RabbitMQ returns message to client if there is no suitable consumer.
        timeout:
            Send confirmation time from RabbitMQ.
        persist:
            Restore the message on RabbitMQ reboot.
        reply_to:
            Reply message routing key to send with (always sending to default exchange).
        priority:
            The message priority (0 by default).
        title:
            AsyncAPI publisher object title.
        description:
            AsyncAPI publisher object description.
        schema:
            AsyncAPI publishing message type. Should be any python-native object annotation or `pydantic.BaseModel`.
        include_in_schema:
            Whetever to include operation in AsyncAPI schema or not.
        headers:
            Message headers to store metainformation. Can be overridden by `publish.headers` if specified.
        content_type:
            Message **content-type** header. Used by application, not core RabbitMQ. Will be set automatically if not specified.
        content_encoding:
            Message body content encoding, e.g. **gzip**.
        expiration:
            Message expiration (lifetime) in seconds (or datetime or timedelta).
        message_type:
            Application-specific message type, e.g. **orders.created**.
        user_id:
            Publisher connection User ID, validated if set.
        persistent: Whether to make the publisher persistent or not.
    """
    super().__init__(
        queue=queue,
        exchange=exchange,
        routing_key=routing_key,
        mandatory=mandatory,
        immediate=immediate,
        timeout=timeout,
        persist=persist,
        reply_to=reply_to,
        priority=priority,
        headers=headers,
        content_type=content_type,
        content_encoding=content_encoding,
        expiration=expiration,
        message_type=message_type,
        user_id=user_id,
        # AsyncAPI args
        title=title,
        description=description,
        schema=schema,
        include_in_schema=include_in_schema,
        persistent=persistent,
    )

args instance-attribute #

args: Iterable[Any] = args

kwargs instance-attribute #

kwargs: dict[str, Any] = kwargs