@@ -58,7 +58,7 @@ def _create_auth(self, username=None, password=None): # pylint: disable=no-self
58
58
return authentication .SASLPlain (
59
59
self .address .hostname , username , password , http_proxy = self .http_proxy )
60
60
return authentication .SASTokenAsync .from_shared_access_key (
61
- self .auth_uri , username , password , timeout = 60 , http_proxy = self .http_proxy )
61
+ self .auth_uri , username , password , timeout = self . auth_timeout , http_proxy = self .http_proxy )
62
62
63
63
async def _close_clients_async (self ):
64
64
"""
@@ -77,8 +77,9 @@ async def _start_client_async(self, client):
77
77
try :
78
78
await client .open_async ()
79
79
except Exception as exp : # pylint: disable=broad-except
80
- log .info ("Encountered error while starting handler: {}" . format ( exp ) )
80
+ log .info ("Encountered error while starting handler: %r" , exp )
81
81
await client .close_async (exception = exp )
82
+ log .info ("Finished closing failed handler" )
82
83
83
84
async def _handle_redirect (self , redirects ):
84
85
if len (redirects ) != len (self .clients ):
@@ -104,17 +105,17 @@ async def run_async(self):
104
105
105
106
:rtype: list[~azure.eventhub.common.EventHubError]
106
107
"""
107
- log .info ("{} : Starting {} clients" . format ( self .container_id , len (self .clients ) ))
108
+ log .info ("%r : Starting %r clients" , self .container_id , len (self .clients ))
108
109
tasks = [self ._start_client_async (c ) for c in self .clients ]
109
110
try :
110
111
await asyncio .gather (* tasks )
111
112
redirects = [c .redirected for c in self .clients if c .redirected ]
112
113
failed = [c .error for c in self .clients if c .error ]
113
114
if failed and len (failed ) == len (self .clients ):
114
- log .warning ("{} : All clients failed to start." . format ( self .container_id ) )
115
+ log .warning ("%r : All clients failed to start." , self .container_id )
115
116
raise failed [0 ]
116
117
elif failed :
117
- log .warning ("{}: {} clients failed to start." . format ( self .container_id , len (failed ) ))
118
+ log .warning ("%r: %r clients failed to start." , self .container_id , len (failed ))
118
119
elif redirects :
119
120
await self ._handle_redirect (redirects )
120
121
except EventHubError :
@@ -129,7 +130,7 @@ async def stop_async(self):
129
130
"""
130
131
Stop the EventHubClient and all its Sender/Receiver clients.
131
132
"""
132
- log .info ("{} : Stopping {} clients" . format ( self .container_id , len (self .clients ) ))
133
+ log .info ("%r : Stopping %r clients" , self .container_id , len (self .clients ))
133
134
self .stopped = True
134
135
await self ._close_clients_async ()
135
136
@@ -182,7 +183,7 @@ def add_async_receiver(
182
183
:operation: An optional operation to be appended to the hostname in the source URL.
183
184
The value must start with `/` character.
184
185
:type operation: str
185
- :rtype: ~azure.eventhub._async .receiver_async.ReceiverAsync
186
+ :rtype: ~azure.eventhub.async_ops .receiver_async.ReceiverAsync
186
187
"""
187
188
path = self .address .path + operation if operation else self .address .path
188
189
source_url = "amqps://{}{}/ConsumerGroups/{}/Partitions/{}" .format (
@@ -213,7 +214,7 @@ def add_async_epoch_receiver(
213
214
:operation: An optional operation to be appended to the hostname in the source URL.
214
215
The value must start with `/` character.
215
216
:type operation: str
216
- :rtype: ~azure.eventhub._async .receiver_async.ReceiverAsync
217
+ :rtype: ~azure.eventhub.async_ops .receiver_async.ReceiverAsync
217
218
"""
218
219
path = self .address .path + operation if operation else self .address .path
219
220
source_url = "amqps://{}{}/ConsumerGroups/{}/Partitions/{}" .format (
@@ -224,7 +225,9 @@ def add_async_epoch_receiver(
224
225
self .clients .append (handler )
225
226
return handler
226
227
227
- def add_async_sender (self , partition = None , operation = None , keep_alive = 30 , auto_reconnect = True , loop = None ):
228
+ def add_async_sender (
229
+ self , partition = None , operation = None , send_timeout = 60 ,
230
+ keep_alive = 30 , auto_reconnect = True , loop = None ):
228
231
"""
229
232
Add an async sender to the client to send ~azure.eventhub.common.EventData object
230
233
to an EventHub.
@@ -236,13 +239,23 @@ def add_async_sender(self, partition=None, operation=None, keep_alive=30, auto_r
236
239
:operation: An optional operation to be appended to the hostname in the target URL.
237
240
The value must start with `/` character.
238
241
:type operation: str
239
- :rtype: ~azure.eventhub._async.sender_async.SenderAsync
242
+ :param send_timeout: The timeout in seconds for an individual event to be sent from the time that it is
243
+ queued. Default value is 60 seconds. If set to 0, there will be no timeout.
244
+ :type send_timeout: int
245
+ :param keep_alive: The time interval in seconds between pinging the connection to keep it alive during
246
+ periods of inactivity. The default value is 30 seconds. If set to `None`, the connection will not
247
+ be pinged.
248
+ :type keep_alive: int
249
+ :param auto_reconnect: Whether to automatically reconnect the sender if a retryable error occurs.
250
+ Default value is `True`.
251
+ :type auto_reconnect: bool
252
+ :rtype: ~azure.eventhub.async_ops.sender_async.SenderAsync
240
253
"""
241
254
target = "amqps://{}{}" .format (self .address .hostname , self .address .path )
242
255
if operation :
243
256
target = target + operation
244
257
handler = AsyncSender (
245
- self , target , partition = partition , keep_alive = keep_alive ,
258
+ self , target , partition = partition , send_timeout = send_timeout , keep_alive = keep_alive ,
246
259
auto_reconnect = auto_reconnect , loop = loop )
247
260
self .clients .append (handler )
248
261
return handler
0 commit comments