Class SubscriberClient (1.9.0)

SubscriberClient(
    *,
    executor: typing.Optional[concurrent.futures.thread.ThreadPoolExecutor] = None,
    nack_handler: typing.Optional[
        google.cloud.pubsublite.cloudpubsub.nack_handler.NackHandler
    ] = None,
    reassignment_handler: typing.Optional[
        google.cloud.pubsublite.cloudpubsub.reassignment_handler.ReassignmentHandler
    ] = None,
    message_transformer: typing.Optional[
        google.cloud.pubsublite.cloudpubsub.message_transformer.MessageTransformer
    ] = None,
    credentials: typing.Optional[google.auth.credentials.Credentials] = None,
    transport: str = "grpc_asyncio",
    client_options: typing.Optional[google.api_core.client_options.ClientOptions] = None
)

A SubscriberClient reads messages similar to Google Pub/Sub. Any subscribe failures are unlikely to succeed if retried.

Must be used in a with block or have enter() called before use.

Methods

SubscriberClient

SubscriberClient(
    *,
    executor: typing.Optional[concurrent.futures.thread.ThreadPoolExecutor] = None,
    nack_handler: typing.Optional[
        google.cloud.pubsublite.cloudpubsub.nack_handler.NackHandler
    ] = None,
    reassignment_handler: typing.Optional[
        google.cloud.pubsublite.cloudpubsub.reassignment_handler.ReassignmentHandler
    ] = None,
    message_transformer: typing.Optional[
        google.cloud.pubsublite.cloudpubsub.message_transformer.MessageTransformer
    ] = None,
    credentials: typing.Optional[google.auth.credentials.Credentials] = None,
    transport: str = "grpc_asyncio",
    client_options: typing.Optional[google.api_core.client_options.ClientOptions] = None
)

Create a new SubscriberClient.

__enter__

__enter__()

Return self upon entering the runtime context.

__exit__

__exit__(exc_type, exc_value, traceback)

Raise any exception triggered within the runtime context.

subscribe

subscribe(
    subscription: typing.Union[
        google.cloud.pubsublite.types.paths.SubscriptionPath, str
    ],
    callback: typing.Callable[
        [google.cloud.pubsub_v1.subscriber.message.Message], None
    ],
    per_partition_flow_control_settings: google.cloud.pubsublite.types.flow_control_settings.FlowControlSettings,
    fixed_partitions: typing.Optional[
        typing.Set[google.cloud.pubsublite.types.partition.Partition]
    ] = None,
) -> google.cloud.pubsub_v1.subscriber.futures.StreamingPullFuture

This method starts a background thread to begin pulling messages from a Pub/Sub Lite subscription and scheduling them to be processed using the provided callback.

Parameters
NameDescription
subscription typing.Union[google.cloud.pubsublite.types.paths.SubscriptionPath, str]

The subscription to subscribe to.

callback typing.Callable[[google.cloud.pubsub_v1.subscriber.message.Message], NoneType]

The callback function. This function receives the message as its only argument.

per_partition_flow_control_settings FlowControlSettings

The flow control settings for each partition subscribed to. Note that these settings apply to each partition individually, not in aggregate.

fixed_partitions typing.Optional[typing.Set[google.cloud.pubsublite.types.partition.Partition]]

A fixed set of partitions to subscribe to. If not present, will instead use auto-assignment.

Exceptions
TypeDescription
GoogleApiCallErrorOn a permanent failure.