Skip to content

PullSub

faststream.nats.PullSub #

PullSub(
    batch_size: int = 1,
    timeout: float | None = 5.0,
    batch: Literal[False] = False,
)
PullSub(
    batch_size: int = 1,
    timeout: float | None = 5.0,
    batch: Literal[True] = ...,
)
PullSub(
    batch_size: int = 1,
    timeout: float | None = 5.0,
    batch: bool = ...,
)
PullSub(
    batch_size: int = 1,
    timeout: float | None = 5.0,
    batch: bool = False,
)

Bases: Generic[BatchT_co]

A class to represent a NATS pull subscription.

PARAMETER DESCRIPTION
batch_size

Target batch size with batch=True; maximum messages per request with batch=False (default is 1).

TYPE: int DEFAULT: 1

timeout (

obj:float, optional): Maximum time in seconds to collect a batch with batch=True; timeout per request with batch=False. None waits until the batch is full with batch=True (default is 5.0).

batch

Whether to propagate consuming batch as iterable object to your handler (default is False).

TYPE: bool DEFAULT: False

Source code in faststream/nats/schemas/pull_sub.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def __init__(
    self,
    batch_size: int = 1,
    timeout: float | None = 5.0,
    batch: bool = False,
) -> None:
    if batch_size < 1:
        message = "You must specify a positive `batch_size`."
        raise ValueError(message)
    if timeout is not None and timeout <= 0:
        message = "You must specify a positive `timeout` or None."
        raise ValueError(message)

    self.batch_size = batch_size
    self.batch = batch
    self.timeout = timeout

batch_size instance-attribute #

batch_size = batch_size

batch instance-attribute #

batch = batch

timeout instance-attribute #

timeout = timeout

validate classmethod #

validate(value: Literal[True]) -> PullSub
validate(value: Literal[False]) -> None
validate(value: PullSub) -> PullSub
validate(value: Union[bool, PullSub]) -> Optional[PullSub]
validate(value: Union[bool, PullSub]) -> Optional[PullSub]
Source code in faststream/nats/schemas/pull_sub.py
85
86
87
88
89
90
91
@classmethod
def validate(cls, value: Union[bool, "PullSub"]) -> Optional["PullSub"]:
    if value is True:
        return PullSub()
    if value is False:
        return None
    return value