def __init__( self, nack_handler: Optional[NackHandler] = None, message_transformer: Optional[MessageTransformer] = None, credentials: Optional[Credentials] = None, transport: str = "grpc_asyncio", client_options: Optional[ClientOptions] = None, ): """ Create a new AsyncSubscriberClient. Args: nack_handler: A handler for when `nack()` is called. The default NackHandler raises an exception and fails the subscribe stream. message_transformer: A transformer from Pub/Sub Lite messages to Cloud Pub/Sub messages. This may not return a message with "message_id" set. credentials: If provided, the credentials to use when connecting. transport: The transport to use. Must correspond to an asyncio transport. client_options: The client options to use when connecting. If used, must explicitly set `api_endpoint`. """ self._impl = MultiplexedAsyncSubscriberClient( lambda subscription, partitions, settings: make_async_subscriber( subscription=subscription, transport=transport, per_partition_flow_control_settings=settings, nack_handler=nack_handler, message_transformer=message_transformer, fixed_partitions=partitions, credentials=credentials, client_options=client_options, ) ) self._require_started = RequireStarted()
def __init__( self, *, executor: Optional[ThreadPoolExecutor] = None, nack_handler: Optional[NackHandler] = None, reassignment_handler: Optional[ReassignmentHandler] = None, message_transformer: Optional[MessageTransformer] = None, credentials: Optional[Credentials] = None, transport: str = "grpc_asyncio", client_options: Optional[ClientOptions] = None, ): """ Create a new SubscriberClient. Args: executor: A ThreadPoolExecutor to use. The client will shut it down on __exit__. If provided a single threaded executor, messages will be ordered per-partition, but take care that the callback does not block for too long as it will impede forward progress on all subscriptions. nack_handler: A handler for when `nack()` is called. The default NackHandler raises an exception and fails the subscribe stream. message_transformer: A transformer from Pub/Sub Lite messages to Cloud Pub/Sub messages. This may not return a message with "message_id" set. credentials: If provided, the credentials to use when connecting. transport: The transport to use. Must correspond to an asyncio transport. client_options: The client options to use when connecting. If used, must explicitly set `api_endpoint`. """ if executor is None: executor = ThreadPoolExecutor() self._impl = MultiplexedSubscriberClient( executor, lambda subscription, partitions, settings: make_async_subscriber( subscription=subscription, transport=transport, per_partition_flow_control_settings=settings, nack_handler=nack_handler, reassignment_handler=reassignment_handler, message_transformer=message_transformer, fixed_partitions=partitions, credentials=credentials, client_options=client_options, ), ) self._require_started = RequireStarted()