
                             d dl mZ d dlmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZmZmZ d dlm Z  d dl!m"Z" d dl#m$Z$m%Z%m&Z&  G d dee       Z' G d dee       Z(y)    )ThreadPoolExecutor)OptionalUnionSetAsyncIterator)ClientOptions)Credentials)StreamingPullFuture)Message)ReassignmentHandlermake_async_subscriber) MultiplexedAsyncSubscriberClient)MultiplexedSubscriberClient)MessageTransformer)NackHandler)SubscriberClientInterfaceAsyncSubscriberClientInterfaceMessageCallback)ConstructableFromServiceAccount)RequireStarted)FlowControlSettings	PartitionSubscriptionPathc                       e Zd ZU dZeed<   eed<   dddddddddee   dee	   d	ee
   d
ee   dee   dedee   fdZ	 ddeeef   dededeee      def
dZd Zd Zy)SubscriberClientz
    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.
    _impl_require_startedNgrpc_asyncio)executornack_handlerreassignment_handlermessage_transformercredentials	transportclient_optionsr    r!   r"   r#   r$   r%   r&   c          	      x    |
t               }t        |fd      | _        t               | _        y)a  
        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`.
        Nc                 ,    t        | ||	      S N)	subscriptionr%   #per_partition_flow_control_settingsr!   r"   r#   fixed_partitionsr$   r&   r   	r*   
partitionssettingsr&   r$   r#   r!   r"   r%   s	      Hlib/third_party/google/cloud/pubsublite/cloudpubsub/subscriber_client.py<lambda>z+SubscriberClient.__init__.<locals>.<lambda>X   &    7L)#4<)%9$7!+'-
8    )r   r   r   r   r   )selfr    r!   r"   r#   r$   r%   r&   s     ``````r0   __init__zSubscriberClient.__init__>   s9    , )+H0
 


 !/ 0r3   r*   callbackr+   r,   returnc                 r    | j                   j                          | j                  j                  ||||      S Nr   require_startedr   	subscribe)r4   r*   r6   r+   r,   s        r0   r<   zSubscriberClient.subscribef   s9     	--/zz##/	
 	
r3   c                 n    | j                   j                          | j                  j                          | S r9   )r   	__enter__r   r4   s    r0   r>   zSubscriberClient.__enter__u   s)    '')

r3   c                 x    | j                   j                  |||       | j                  j                  |||       y r9   )r   __exit__r   r4   exc_type	exc_value	tracebacks       r0   rA   zSubscriberClient.__exit__z   s0    

Hi;&&xIFr3   r9   )__name__
__module____qualname____doc__r   __annotations__r   r   r   r   r   r   r	   strr   r5   r   r   r   r   r   r   r
   r<   r>   rA    r3   r0   r   r   3   s     %$$$
 26.2>B<@-1'26&1 -.&1 {+	&1
 '':;&1 &&89&1 k*&1 &1 !/&1Z 6:
,c12
 "
 .A	

 #3y>2
 


Gr3   r   c                       e Zd ZU dZeed<   eed<   ddddddddee   dee	   d	ee
   d
ee   dedee   fdZ	 ddeeef   dedeee      dee   fdZd Zd Zy)AsyncSubscriberClienta	  
    An AsyncSubscriberClient reads messages similar to Google Pub/Sub, but must be used in an
    async context.
    Any subscribe failures are unlikely to succeed if retried.

    Must be used in an `async with` block or have __aenter__() awaited before use.
    r   r   Nr   )r!   r"   r#   r$   r%   r&   r!   r"   r#   r$   r%   r&   c                ^    t        fd      | _        t               | _        y)a  
        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`.
        c                 ,    t        | ||	      S r)   r   r-   s	      r0   r1   z0AsyncSubscriberClient.__init__.<locals>.<lambda>   r2   r3   N)r   r   r   r   )r4   r!   r"   r#   r$   r%   r&   s    ``````r0   r5   zAsyncSubscriberClient.__init__   s(    ( 6
 


 !/ 0r3   r*   r+   r,   r7   c                    K   | j                   j                          | j                  j                  |||       d {   S 7 wr9   r:   )r4   r*   r+   r,   s       r0   r<   zAsyncSubscriberClient.subscribe   sD      	--/ZZ))=?O
 
 	
 
s   ;AAAc                    K   | j                   j                          | j                  j                          d {    | S 7 wr9   )r   r>   r   
__aenter__r?   s    r0   rS   z AsyncSubscriberClient.__aenter__   s8     '')jj##%%% 	&s   8AAAc                    K   | j                   j                  |||       d {    | j                  j                  |||       y 7 "wr9   )r   	__aexit__r   rA   rB   s       r0   rU   zAsyncSubscriberClient.__aexit__   s@     jj""8Y	BBB&&xIF 	Cs   !AA#Ar9   )rF   rG   rH   rI   r   rJ   r   r   r   r   r   r	   rK   r   r5   r   r   r   r   r   r   r   r<   rS   rU   rL   r3   r0   rN   rN      s     *)$$
 /3>B<@-1'26!1 {+!1 '':;	!1
 &&89!1 k*!1 !1 !/!1N 6:		
,c12	
 .A	
 #3y>2		

 
w		

Gr3   rN   N))concurrent.futures.threadr   typingr   r   r   r   google.api_core.client_optionsr   google.auth.credentialsr	   )google.cloud.pubsub_v1.subscriber.futuresr
   )google.cloud.pubsub_v1.subscriber.messager   8google.cloud.pubsublite.cloudpubsub.reassignment_handlerr   <google.cloud.pubsublite.cloudpubsub.internal.make_subscriberr   Pgoogle.cloud.pubsublite.cloudpubsub.internal.multiplexed_async_subscriber_clientr   Jgoogle.cloud.pubsublite.cloudpubsub.internal.multiplexed_subscriber_clientr   7google.cloud.pubsublite.cloudpubsub.message_transformerr   0google.cloud.pubsublite.cloudpubsub.nack_handlerr   ?google.cloud.pubsublite.cloudpubsub.subscriber_client_interfacer   r   r   Cgoogle.cloud.pubsublite.internal.constructable_from_service_accountr   0google.cloud.pubsublite.internal.require_startedr   google.cloud.pubsublite.typesr   r   r   r   rN   rL   r3   r0   <module>rf      s    9 6 6 8 / I = X W H 
 L IG02Q IGXCG"$CCGr3   