Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self._handler.wait()
return True
except errors.TokenExpired as shutdown:
log.info("Sender disconnected due to token expiry. Shutting down.")
error = EventHubError(str(shutdown), shutdown)
self.close(exception=error)
raise error
except (errors.LinkDetach, errors.ConnectionClose) as shutdown:
if shutdown.action.retry and self.auto_reconnect:
log.info("Sender detached. Attempting reconnect.")
return False
log.info("Sender reconnect failed. Shutting down.")
error = EventHubError(str(shutdown), shutdown)
self.close(exception=error)
raise error
except errors.MessageHandlerError as shutdown:
if self.auto_reconnect:
log.info("Sender detached. Attempting reconnect.")
return False
log.info("Sender reconnect failed. Shutting down.")
error = EventHubError(str(shutdown), shutdown)
self.close(exception=error)
raise error
except errors.AMQPConnectionError as shutdown:
if str(shutdown).startswith("Unable to open authentication session") and self.auto_reconnect:
log.info("Sender couldn't authenticate. Attempting reconnect.")
return False
log.info("Sender connection error (%r). Shutting down.", shutdown)
error = EventHubError(str(shutdown))
self.close(exception=error)
raise error
except Exception as e:
msg_timeout=self.timeout,
error_policy=self.retry_policy,
keep_alive_interval=self.keep_alive,
client_name=self.name,
properties=self.client.create_properties())
try:
self._handler.open()
self._handler.queue_message(*unsent_events)
self._handler.wait()
return True
except errors.TokenExpired as shutdown:
log.info("Sender disconnected due to token expiry. Shutting down.")
error = EventHubError(str(shutdown), shutdown)
self.close(exception=error)
raise error
except (errors.LinkDetach, errors.ConnectionClose) as shutdown:
if shutdown.action.retry and self.auto_reconnect:
log.info("Sender detached. Attempting reconnect.")
return False
log.info("Sender reconnect failed. Shutting down.")
error = EventHubError(str(shutdown), shutdown)
self.close(exception=error)
raise error
except errors.MessageHandlerError as shutdown:
if self.auto_reconnect:
log.info("Sender detached. Attempting reconnect.")
return False
log.info("Sender reconnect failed. Shutting down.")
error = EventHubError(str(shutdown), shutdown)
self.close(exception=error)
raise error
except errors.AMQPConnectionError as shutdown:
self.prefetch = prefetch
self.epoch = epoch
self.keep_alive = keep_alive
self.auto_reconnect = auto_reconnect
self.retry_policy = errors.ErrorPolicy(max_retries=3, on_error=_error_handler)
self.reconnect_backoff = 1
self.properties = None
self.redirected = None
self.error = None
partition = self.source.split('/')[-1]
self.name = "EHReceiver-{}-partition{}".format(uuid.uuid4(), partition)
source = Source(self.source)
if self.offset is not None:
source.set_filter(self.offset.selector())
if epoch:
self.properties = {types.AMQPSymbol(self._epoch): types.AMQPLong(int(epoch))}
self._handler = ReceiveClient(
source,
auth=self.client.get_auth(),
debug=self.client.debug,
prefetch=self.prefetch,
link_properties=self.properties,
timeout=self.timeout,
error_policy=self.retry_policy,
keep_alive_interval=self.keep_alive,
client_name=self.name,
properties=self.client.create_properties())
self.prefetch = prefetch
self.epoch = epoch
self.keep_alive = keep_alive
self.auto_reconnect = auto_reconnect
self.retry_policy = errors.ErrorPolicy(max_retries=3, on_error=_error_handler)
self.reconnect_backoff = 1
self.redirected = None
self.error = None
self.properties = None
partition = self.source.split('/')[-1]
self.name = "EHReceiver-{}-partition{}".format(uuid.uuid4(), partition)
source = Source(self.source)
if self.offset is not None:
source.set_filter(self.offset.selector())
if epoch:
self.properties = {types.AMQPSymbol(self._epoch): types.AMQPLong(int(epoch))}
self._handler = ReceiveClientAsync(
source,
auth=self.client.get_auth(),
debug=self.client.debug,
prefetch=self.prefetch,
link_properties=self.properties,
timeout=self.timeout,
error_policy=self.retry_policy,
keep_alive_interval=self.keep_alive,
client_name=self.name,
properties=self.client.create_properties(),
loop=self.loop)
self._reconnect_backoff = 1
self._link_properties = {} # type: Dict[types.AMQPType, types.AMQPType]
self._error = None
self._timeout = 0
self._idle_timeout = (idle_timeout * 1000) if idle_timeout else None
partition = self._source.split("/")[-1]
self._partition = partition
self._name = "EHConsumer-{}-partition{}".format(uuid.uuid4(), partition)
if owner_level:
self._link_properties[types.AMQPSymbol(EPOCH_SYMBOL)] = types.AMQPLong(
int(owner_level)
)
link_property_timeout_ms = (
self._client._config.receive_timeout or self._timeout # pylint:disable=protected-access
) * 1000
self._link_properties[types.AMQPSymbol(TIMEOUT_SYMBOL)] = types.AMQPLong(
int(link_property_timeout_ms)
)
self._handler = None # type: Optional[ReceiveClient]
self._track_last_enqueued_event_properties = (
track_last_enqueued_event_properties
)
self._last_received_event = None # type: Optional[EventData]
def _send_event_data(self, timeout_time=None, last_exception=None):
# type: (Optional[float], Optional[Exception]) -> None
if self._unsent_events:
self._open()
self._set_msg_timeout(timeout_time, last_exception)
self._handler.queue_message(*self._unsent_events) # type: ignore
self._handler.wait() # type: ignore
self._unsent_events = self._handler.pending_messages # type: ignore
if self._outcome != constants.MessageSendResult.Ok:
if self._outcome == constants.MessageSendResult.Timeout:
self._condition = OperationTimeoutError("Send operation timed out")
if self._condition:
raise self._condition
self._owner_level = owner_level
self._keep_alive = keep_alive
self._auto_reconnect = auto_reconnect
self._retry_policy = errors.ErrorPolicy(
max_retries=self._client._config.max_retries, on_error=_error_handler # pylint:disable=protected-access
)
self._reconnect_backoff = 1
self._link_properties = {} # type: Dict[types.AMQPType, types.AMQPType]
self._error = None
self._timeout = 0
self._idle_timeout = (idle_timeout * 1000) if idle_timeout else None
partition = self._source.split("/")[-1]
self._partition = partition
self._name = "EHConsumer-{}-partition{}".format(uuid.uuid4(), partition)
if owner_level:
self._link_properties[types.AMQPSymbol(EPOCH_SYMBOL)] = types.AMQPLong(
int(owner_level)
)
link_property_timeout_ms = (
self._client._config.receive_timeout or self._timeout # pylint:disable=protected-access
) * 1000
self._link_properties[types.AMQPSymbol(TIMEOUT_SYMBOL)] = types.AMQPLong(
int(link_property_timeout_ms)
)
self._handler = None # type: Optional[ReceiveClient]
self._track_last_enqueued_event_properties = (
track_last_enqueued_event_properties
)
self._last_received_event = None # type: Optional[EventData]
)
self._reconnect_backoff = 1
self._timeout = 0
self._idle_timeout = (idle_timeout * 1000) if idle_timeout else None
self._link_properties = {} # type: Dict[types.AMQPType, types.AMQPType]
partition = self._source.split("/")[-1]
self._partition = partition
self._name = "EHReceiver-{}-partition{}".format(uuid.uuid4(), partition)
if owner_level:
self._link_properties[types.AMQPSymbol(EPOCH_SYMBOL)] = types.AMQPLong(
int(owner_level)
)
link_property_timeout_ms = (
self._client._config.receive_timeout or self._timeout # pylint:disable=protected-access
) * 1000
self._link_properties[types.AMQPSymbol(TIMEOUT_SYMBOL)] = types.AMQPLong(
int(link_property_timeout_ms)
)
self._handler = None # type: Optional[ReceiveClientAsync]
self._track_last_enqueued_event_properties = (
track_last_enqueued_event_properties
)
self._event_queue = queue.Queue()
self._last_received_event = None # type: Optional[EventData]
def wait(self):
"""
Wait until all transferred events have been sent.
"""
if self.error:
raise self.error
if not self.running:
raise ValueError("Unable to send until client has been started.")
try:
self._handler.wait()
except (errors.TokenExpired, errors.AuthenticationException):
log.info("Sender disconnected due to token error. Attempting reconnect.")
self.reconnect()
except (errors.LinkDetach, errors.ConnectionClose) as shutdown:
if shutdown.action.retry and self.auto_reconnect:
log.info("Sender detached. Attempting reconnect.")
self.reconnect()
else:
log.info("Sender detached. Shutting down.")
error = EventHubError(str(shutdown), shutdown)
self.close(exception=error)
raise error
except errors.MessageHandlerError as shutdown:
if self.auto_reconnect:
log.info("Sender detached. Attempting reconnect.")
self.reconnect()
else:
for processing. Default is 300.
:type prefetch: int
:param epoch: An optional epoch value.
:type epoch: int
:param loop: An event loop.
"""
self.loop = loop or asyncio.get_event_loop()
self.running = False
self.client = client
self.source = source
self.offset = offset
self.prefetch = prefetch
self.epoch = epoch
self.keep_alive = keep_alive
self.auto_reconnect = auto_reconnect
self.retry_policy = errors.ErrorPolicy(max_retries=3, on_error=_error_handler)
self.reconnect_backoff = 1
self.redirected = None
self.error = None
self.properties = None
partition = self.source.split('/')[-1]
self.name = "EHReceiver-{}-partition{}".format(uuid.uuid4(), partition)
source = Source(self.source)
if self.offset is not None:
source.set_filter(self.offset.selector())
if epoch:
self.properties = {types.AMQPSymbol(self._epoch): types.AMQPLong(int(epoch))}
self._handler = ReceiveClientAsync(
source,
auth=self.client.get_auth(),
debug=self.client.debug,
prefetch=self.prefetch,