def __init__(self, client, target, partition=None, keep_alive=None, auto_reconnect=True, loop=None): # pylint: disable=super-init-not-called """ Instantiate an EventHub event SenderAsync handler. :param client: The parent EventHubClientAsync. :type client: ~azure.eventhub._async.EventHubClientAsync :param target: The URI of the EventHub to send to. :type target: str :param loop: An event loop. """ self.loop = loop or asyncio.get_event_loop() self.client = client self.target = target self.partition = partition self.keep_alive = keep_alive self.auto_reconnect = auto_reconnect self.retry_policy = errors.ErrorPolicy(max_retries=3, on_error=_error_handler) self.name = "EHSender-{}".format(uuid.uuid4()) self.redirected = None self.error = None if partition: self.target += "/Partitions/" + partition self.name += "-partition{}".format(partition) self._handler = SendClientAsync( self.target, auth=self.client.get_auth(), debug=self.client.debug, msg_timeout=Sender.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._outcome = None self._condition = None
def __init__( # pylint: disable=super-init-not-called self, client, source, offset=None, prefetch=300, epoch=None, keep_alive=None, auto_reconnect=True, loop=None): """ Instantiate an async receiver. :param client: The parent EventHubClientAsync. :type client: ~azure.eventhub.async_ops.EventHubClientAsync :param source: The source EventHub from which to receive events. :type source: ~uamqp.address.Source :param prefetch: The number of events to prefetch from the service 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, 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)
def __init__(self, client, target, partition=None, keep_alive=None, auto_reconnect=True): """ Instantiate an EventHub event Sender handler. :param client: The parent EventHubClient. :type client: ~azure.eventhub.client.EventHubClient. :param target: The URI of the EventHub to send to. :type target: str """ self.client = client self.target = target self.partition = partition self.redirected = None self.error = None self.keep_alive = keep_alive self.auto_reconnect = auto_reconnect self.retry_policy = errors.ErrorPolicy(max_retries=3, on_error=_error_handler) self.name = "EHSender-{}".format(uuid.uuid4()) if partition: self.target += "/Partitions/" + partition self.name += "-partition{}".format(partition) self._handler = SendClient( self.target, auth=self.client.get_auth(), debug=self.client.debug, msg_timeout=Sender.TIMEOUT, error_policy=self.retry_policy, keep_alive_interval=self.keep_alive, client_name=self.name, properties=self.client.create_properties()) self._outcome = None self._condition = None
def __init__(self, client, source, event_position=None, prefetch=300, owner_level=None, keep_alive=None, auto_reconnect=True): """ Instantiate a consumer. EventHubConsumer should be instantiated by calling the `create_consumer` method in EventHubClient. :param client: The parent EventHubClient. :type client: ~azure.eventhub.client.EventHubClient :param source: The source EventHub from which to receive events. :type source: str :param prefetch: The number of events to prefetch from the service for processing. Default is 300. :type prefetch: int :param owner_level: The priority of the exclusive consumer. It will an exclusive consumer if owner_level is set. :type owner_level: int """ self.running = False self.client = client self.source = source self.offset = event_position self.messages_iter = None self.prefetch = prefetch 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) 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()) # pylint: disable=protected-access if owner_level: self.properties = { types.AMQPSymbol(self._epoch): types.AMQPLong(int(owner_level)) } self._handler = ReceiveClient( source, auth=self.client.get_auth(), debug=self.client.config.network_tracing, 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.client.config.user_agent)) # pylint: disable=protected-access
def __init__( # pylint: disable=super-init-not-called self, client, source, **kwargs): """ Instantiate an async consumer. EventHubConsumer should be instantiated by calling the `create_consumer` method in EventHubClient. :param client: The parent EventHubClientAsync. :type client: ~azure.eventhub.aio.EventHubClientAsync :param source: The source EventHub from which to receive events. :type source: ~uamqp.address.Source :param event_position: The position from which to start receiving. :type event_position: ~azure.eventhub.common.EventPosition :param prefetch: The number of events to prefetch from the service for processing. Default is 300. :type prefetch: int :param owner_level: The priority of the exclusive consumer. An exclusive consumer will be created if owner_level is set. :type owner_level: int :param track_last_enqueued_event_properties: Indicates whether or not the consumer should request information on the last enqueued event on its associated partition, and track that information as events are received. When information about the partition's last enqueued event is being tracked, each event received from the Event Hubs service will carry metadata about the partition. This results in a small amount of additional network bandwidth consumption that is generally a favorable trade-off when considered against periodically making requests for partition properties using the Event Hub client. It is set to `False` by default. :type track_last_enqueued_event_properties: bool :param loop: An event loop. """ event_position = kwargs.get("event_position", None) prefetch = kwargs.get("prefetch", 300) owner_level = kwargs.get("owner_level", None) keep_alive = kwargs.get("keep_alive", None) auto_reconnect = kwargs.get("auto_reconnect", True) track_last_enqueued_event_properties = kwargs.get("track_last_enqueued_event_properties", False) loop = kwargs.get("loop", None) super(EventHubConsumer, self).__init__() self._loop = loop or asyncio.get_event_loop() self._client = client self._source = source self._offset = event_position self._messages_iter = None self._prefetch = prefetch 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 = {} partition = self._source.split('/')[-1] self._partition = partition self._name = "EHReceiver-{}-partition{}".format(uuid.uuid4(), partition) if owner_level: self._link_properties[types.AMQPSymbol(self._epoch_symbol)] = types.AMQPLong(int(owner_level)) link_property_timeout_ms = (self._client._config.receive_timeout or self._timeout) * 1000 # pylint:disable=protected-access self._link_properties[types.AMQPSymbol(self._timeout_symbol)] = types.AMQPLong(int(link_property_timeout_ms)) self._handler = None self._track_last_enqueued_event_properties = track_last_enqueued_event_properties self._last_enqueued_event_properties = {}
def __init__( # pylint: disable=super-init-not-called self, client, target, partition=None, send_timeout=60, keep_alive=None, auto_reconnect=True, loop=None): """ Instantiate an EventHub event SenderAsync handler. :param client: The parent EventHubClientAsync. :type client: ~azure.eventhub.async_ops.EventHubClientAsync :param target: The URI of the EventHub to send to. :type target: str :param partition: The specific partition ID to send to. Default is `None`, in which case the service will assign to all partitions using round-robin. :type partition: str :param send_timeout: The timeout in seconds for an individual event to be sent from the time that it is queued. Default value is 60 seconds. If set to 0, there will be no timeout. :type send_timeout: int :param keep_alive: The time interval in seconds between pinging the connection to keep it alive during periods of inactivity. The default value is `None`, i.e. no keep alive pings. :type keep_alive: int :param auto_reconnect: Whether to automatically reconnect the sender if a retryable error occurs. Default value is `True`. :type auto_reconnect: bool :param loop: An event loop. If not specified the default event loop will be used. """ self.loop = loop or asyncio.get_event_loop() self.running = False self.client = client self.target = target self.partition = partition self.keep_alive = keep_alive self.auto_reconnect = auto_reconnect self.timeout = send_timeout self.retry_policy = errors.ErrorPolicy(max_retries=3, on_error=_error_handler) self.reconnect_backoff = 1 self.name = "EHSender-{}".format(uuid.uuid4()) self.redirected = None self.error = None if partition: self.target += "/Partitions/" + partition self.name += "-partition{}".format(partition) self._handler = SendClientAsync( self.target, auth=self.client.get_auth(), debug=self.client.debug, msg_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._outcome = None self._condition = None
def __init__(self, remote_address, auth=None, client_name=None, debug=False, error_policy=None, keep_alive_interval=None, **kwargs): self._encoding = kwargs.pop('encoding', None) or 'UTF-8' self._remote_address = remote_address if isinstance(remote_address, address.Address) \ else address.Address(remote_address) self._hostname = self._remote_address.hostname if not auth: username = self._remote_address.username password = self._remote_address.password if username and password: username = unquote_plus(username) password = unquote_plus(password) auth = authentication.SASLPlain(self._hostname, username, password) self._auth = auth if auth else authentication.SASLAnonymous( self._hostname) self._name = client_name if client_name else str(uuid.uuid4()) self._debug_trace = debug self._counter = c_uamqp.TickCounter() self._shutdown = False self._connection = None self._ext_connection = False self._session = None self._backoff = 0 self._error_policy = error_policy or errors.ErrorPolicy() self._keep_alive_interval = int( keep_alive_interval) if keep_alive_interval else 0 self._keep_alive_thread = None # Connection settings self._max_frame_size = kwargs.pop( 'max_frame_size', None) or constants.MAX_FRAME_SIZE_BYTES self._channel_max = kwargs.pop('channel_max', None) self._idle_timeout = kwargs.pop('idle_timeout', None) self._properties = kwargs.pop('properties', None) self._remote_idle_timeout_empty_frame_send_ratio = kwargs.pop( 'remote_idle_timeout_empty_frame_send_ratio', None) # Session settings self._outgoing_window = kwargs.pop( 'outgoing_window', None) or constants.MAX_FRAME_SIZE_BYTES self._incoming_window = kwargs.pop( 'incoming_window', None) or constants.MAX_FRAME_SIZE_BYTES self._handle_max = kwargs.pop('handle_max', None) # AMQP object settings self.connection_type = Connection self.session_type = Session if kwargs: raise ValueError("Received unrecognized kwargs: {}".format( ", ".join(kwargs.keys())))
def __init__( # pylint: disable=super-init-not-called self, client, target, **kwargs): """ Instantiate an async EventHubProducer. EventHubProducer should be instantiated by calling the `create_producer` method in EventHubClient. :param client: The parent EventHubClientAsync. :type client: ~azure.eventhub.aio.EventHubClientAsync :param target: The URI of the EventHub to send to. :type target: str :param partition: The specific partition ID to send to. Default is `None`, in which case the service will assign to all partitions using round-robin. :type partition: str :param send_timeout: The timeout in seconds for an individual event to be sent from the time that it is queued. Default value is 60 seconds. If set to 0, there will be no timeout. :type send_timeout: float :param keep_alive: The time interval in seconds between pinging the connection to keep it alive during periods of inactivity. The default value is `None`, i.e. no keep alive pings. :type keep_alive: float :param auto_reconnect: Whether to automatically reconnect the producer if a retryable error occurs. Default value is `True`. :type auto_reconnect: bool :param loop: An event loop. If not specified the default event loop will be used. """ partition = kwargs.get("partition", None) send_timeout = kwargs.get("send_timeout", 60) keep_alive = kwargs.get("keep_alive", None) auto_reconnect = kwargs.get("auto_reconnect", True) loop = kwargs.get("loop", None) super(EventHubProducer, self).__init__() self._loop = loop or asyncio.get_event_loop() self._max_message_size_on_link = None self._running = False self._client = client self._target = target self._partition = partition self._keep_alive = keep_alive self._auto_reconnect = auto_reconnect self._timeout = send_timeout 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._name = "EHProducer-{}".format(uuid.uuid4()) self._unsent_events = None self._redirected = None self._error = None if partition: self._target += "/Partitions/" + partition self._name += "-partition{}".format(partition) self._handler = None self._outcome = None self._condition = None self._link_properties = { types.AMQPSymbol(self._timeout_symbol): types.AMQPLong(int(self._timeout * 1000)) }
def __init__( # pylint: disable=super-init-not-called self, client, source, **kwargs): """ Instantiate an async consumer. EventHubConsumer should be instantiated by calling the `create_consumer` method in EventHubClient. :param client: The parent EventHubClientAsync. :type client: ~azure.eventhub.aio.EventHubClientAsync :param source: The source EventHub from which to receive events. :type source: ~uamqp.address.Source :param event_position: The position from which to start receiving. :type event_position: ~azure.eventhub.common.EventPosition :param prefetch: The number of events to prefetch from the service for processing. Default is 300. :type prefetch: int :param owner_level: The priority of the exclusive consumer. An exclusive consumer will be created if owner_level is set. :type owner_level: int :param loop: An event loop. """ event_position = kwargs.get("event_position", None) prefetch = kwargs.get("prefetch", 300) owner_level = kwargs.get("owner_level", None) keep_alive = kwargs.get("keep_alive", None) auto_reconnect = kwargs.get("auto_reconnect", True) loop = kwargs.get("loop", None) super(EventHubConsumer, self).__init__() self._loop = loop or asyncio.get_event_loop() self._running = False self._client = client self._source = source self._offset = event_position self._messages_iter = None self._prefetch = prefetch 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._redirected = None self._error = None self._link_properties = {} partition = self._source.split('/')[-1] self._partition = partition self._name = "EHReceiver-{}-partition{}".format( uuid.uuid4(), partition) if owner_level: self._link_properties[types.AMQPSymbol( self._epoch_symbol)] = types.AMQPLong(int(owner_level)) link_property_timeout_ms = (self._client._config.receive_timeout or self._timeout) * 1000 # pylint:disable=protected-access self._link_properties[types.AMQPSymbol( self._timeout_symbol)] = types.AMQPLong( int(link_property_timeout_ms)) self._handler = None
def __init__(self, client, target, partition=None, send_timeout=60, keep_alive=None, auto_reconnect=True): """ Instantiate an EventHubProducer. EventHubProducer should be instantiated by calling the `create_producer` method in EventHubClient. :param client: The parent EventHubClient. :type client: ~azure.eventhub.client.EventHubClient. :param target: The URI of the EventHub to send to. :type target: str :param partition: The specific partition ID to send to. Default is None, in which case the service will assign to all partitions using round-robin. :type partition: str :param send_timeout: The timeout in seconds for an individual event to be sent from the time that it is queued. Default value is 60 seconds. If set to 0, there will be no timeout. :type send_timeout: float :param keep_alive: The time interval in seconds between pinging the connection to keep it alive during periods of inactivity. The default value is None, i.e. no keep alive pings. :type keep_alive: float :param auto_reconnect: Whether to automatically reconnect the producer if a retryable error occurs. Default value is `True`. :type auto_reconnect: bool """ self.running = False self.client = client self.target = target self.partition = partition self.timeout = send_timeout self.redirected = None self.error = None 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) self.reconnect_backoff = 1 self.name = "EHProducer-{}".format(uuid.uuid4()) self.unsent_events = None if partition: self.target += "/Partitions/" + partition self.name += "-partition{}".format(partition) self._handler = SendClient(self.target, auth=self.client.get_auth(), debug=self.client.config.network_tracing, msg_timeout=self.timeout, error_policy=self.retry_policy, keep_alive_interval=self.keep_alive, client_name=self.name, properties=self.client._create_properties( self.client.config.user_agent)) # pylint: disable=protected-access self._outcome = None self._condition = None
def __init__(self, client, source, **kwargs): # type: (EventHubConsumerClient, str, Any) -> None event_position = kwargs.get("event_position", None) prefetch = kwargs.get("prefetch", 300) owner_level = kwargs.get("owner_level", None) keep_alive = kwargs.get("keep_alive", None) auto_reconnect = kwargs.get("auto_reconnect", True) track_last_enqueued_event_properties = kwargs.get( "track_last_enqueued_event_properties", False ) idle_timeout = kwargs.get("idle_timeout", None) self.running = False self.closed = False self.stop = False # used by event processor self.handler_ready = False self._on_event_received = kwargs[ "on_event_received" ] # type: Callable[[EventData], None] self._client = client self._source = source self._offset = event_position self._offset_inclusive = kwargs.get("event_position_inclusive", False) self._prefetch = prefetch 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 is not None: 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._message_buffer = deque() # type: ignore self._last_received_event = None # type: Optional[EventData]
def __init__(self, session, source, target, on_message_received, name=None, receive_settle_mode=constants.ReceiverSettleMode.PeekLock, send_settle_mode=constants.SenderSettleMode.Unsettled, max_message_size=constants.MAX_MESSAGE_LENGTH_BYTES, prefetch=300, properties=None, error_policy=None, debug=False, encoding='UTF-8', desired_capabilities=None): # pylint: disable=protected-access if name: self.name = name.encode(encoding) if isinstance( name, six.text_type) else name else: self.name = str(uuid.uuid4()).encode(encoding) target = target.encode(encoding) if isinstance( target, six.text_type) else target role = constants.Role.Receiver self.source = source._address.value self.target = c_uamqp.Messaging.create_target(target) self.on_message_received = on_message_received self.encoding = encoding self.error_policy = error_policy or errors.ErrorPolicy() self._settle_mode = receive_settle_mode self._conn = session._conn self._session = session self._link = c_uamqp.create_link(session._session, self.name, role.value, self.source, self.target) self._link.subscribe_to_detach_event(self) if prefetch: self._link.set_prefetch_count(prefetch) if properties: self._link.set_attach_properties( utils.data_factory(properties, encoding=encoding)) if receive_settle_mode: self.receive_settle_mode = receive_settle_mode if send_settle_mode: self.send_settle_mode = send_settle_mode if max_message_size: self.max_message_size = max_message_size if desired_capabilities: self._link.set_desired_capabilities(desired_capabilities) self._receiver = c_uamqp.create_message_receiver(self._link, self) self._receiver.set_trace(debug) self._state = constants.MessageReceiverState.Idle self._error = None
def __init__(self, client: "EventHubConsumerClient", source: str, **kwargs) -> None: super().__init__() event_position = kwargs.get("event_position", None) prefetch = kwargs.get("prefetch", 300) owner_level = kwargs.get("owner_level", None) keep_alive = kwargs.get("keep_alive", None) auto_reconnect = kwargs.get("auto_reconnect", True) track_last_enqueued_event_properties = kwargs.get( "track_last_enqueued_event_properties", False) idle_timeout = kwargs.get("idle_timeout", None) loop = kwargs.get("loop", None) self.running = False self.closed = False self._on_event_received = kwargs[ "on_event_received"] # type: Callable[[EventData], Awaitable[None]] self._loop = loop or get_running_loop() self._client = client self._source = source self._offset = event_position self._offset_inclusive = kwargs.get("event_position_inclusive", False) self._prefetch = prefetch 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._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 __init__(self, client, source, **kwargs): """ Instantiate a consumer. EventHubConsumer should be instantiated by calling the `create_consumer` method in EventHubClient. :param client: The parent EventHubClient. :type client: ~azure.eventhub.client.EventHubClient :param source: The source EventHub from which to receive events. :type source: str :param prefetch: The number of events to prefetch from the service for processing. Default is 300. :type prefetch: int :param owner_level: The priority of the exclusive consumer. It will an exclusive consumer if owner_level is set. :type owner_level: int """ event_position = kwargs.get("event_position", None) prefetch = kwargs.get("prefetch", 300) owner_level = kwargs.get("owner_level", None) keep_alive = kwargs.get("keep_alive", None) auto_reconnect = kwargs.get("auto_reconnect", True) super(EventHubConsumer, self).__init__() self.running = False self.client = client self.source = source self.offset = event_position self.messages_iter = None self.prefetch = prefetch 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) self.reconnect_backoff = 1 self._link_properties = {} self.redirected = None self.error = 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( self._epoch)] = types.AMQPLong(int(owner_level)) link_property_timeout_ms = (self.client.config.receive_timeout or self.timeout) * 1000 self._link_properties[types.AMQPSymbol( self._timeout)] = types.AMQPLong(int(link_property_timeout_ms)) self._handler = None
def __init__(self, hostname, sasl, container_id=False, max_frame_size=None, channel_max=None, idle_timeout=None, properties=None, remote_idle_timeout_empty_frame_send_ratio=None, error_policy=None, debug=False, encoding='UTF-8'): uamqp._Platform.initialize() # pylint: disable=protected-access self.container_id = container_id if container_id else str(uuid.uuid4()) if isinstance(self.container_id, six.text_type): self.container_id = self.container_id.encode(encoding) self.hostname = hostname.encode(encoding) if isinstance( hostname, six.text_type) else hostname self.auth = sasl self.cbs = None self.error_policy = error_policy or errors.ErrorPolicy() self._debug = debug self._conn = self._create_connection(sasl) self._sessions = [] self._lock = threading.Lock() self._state = c_uamqp.ConnectionState.UNKNOWN self._encoding = encoding self._settings = {} self._error = None self._closing = False if max_frame_size: self._settings['max_frame_size'] = max_frame_size self.max_frame_size = max_frame_size if channel_max: self._settings['channel_max'] = channel_max self.channel_max = channel_max if idle_timeout: self._settings['idle_timeout'] = idle_timeout self.idle_timeout = idle_timeout if properties: self._settings['properties'] = properties self.properties = properties if remote_idle_timeout_empty_frame_send_ratio: self._conn.remote_idle_timeout_empty_frame_send_ratio = remote_idle_timeout_empty_frame_send_ratio
def __init__(self, client: "EventHubProducerClient", target: str, **kwargs) -> None: super().__init__() partition = kwargs.get("partition", None) send_timeout = kwargs.get("send_timeout", 60) keep_alive = kwargs.get("keep_alive", None) auto_reconnect = kwargs.get("auto_reconnect", True) loop = kwargs.get("loop", None) idle_timeout = kwargs.get("idle_timeout", None) self.running = False self.closed = False self._loop = loop or get_running_loop() self._max_message_size_on_link = None self._client = client self._target = target self._partition = partition self._keep_alive = keep_alive self._auto_reconnect = auto_reconnect self._timeout = send_timeout self._idle_timeout = (idle_timeout * 1000) if idle_timeout else None 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._name = "EHProducer-{}".format(uuid.uuid4()) self._unsent_events = [] # type: List[Any] self._error = None if partition: self._target += "/Partitions/" + partition self._name += "-partition{}".format(partition) self._handler = None # type: Optional[SendClientAsync] self._outcome = None # type: Optional[constants.MessageSendResult] self._condition = None # type: Optional[Exception] self._lock = asyncio.Lock(loop=self._loop) self._link_properties = { types.AMQPSymbol(TIMEOUT_SYMBOL): types.AMQPLong(int(self._timeout * 1000)) }
def __init__(self, client, source, **kwargs): """ Instantiate a consumer. EventHubConsumer should be instantiated by calling the `create_consumer` method in EventHubClient. :param client: The parent EventHubClient. :type client: ~azure.eventhub.client.EventHubClient :param source: The source EventHub from which to receive events. :type source: str :param prefetch: The number of events to prefetch from the service for processing. Default is 300. :type prefetch: int :param owner_level: The priority of the exclusive consumer. An exclusive consumer will be created if owner_level is set. :type owner_level: int :param track_last_enqueued_event_properties: Indicates whether or not the consumer should request information on the last enqueued event on its associated partition, and track that information as events are received. When information about the partition's last enqueued event is being tracked, each event received from the Event Hubs service will carry metadata about the partition. This results in a small amount of additional network bandwidth consumption that is generally a favorable trade-off when considered against periodically making requests for partition properties using the Event Hub client. It is set to `False` by default. :type track_last_enqueued_event_properties: bool """ event_position = kwargs.get("event_position", None) prefetch = kwargs.get("prefetch", 300) owner_level = kwargs.get("owner_level", None) keep_alive = kwargs.get("keep_alive", None) auto_reconnect = kwargs.get("auto_reconnect", True) track_last_enqueued_event_properties = kwargs.get( "track_last_enqueued_event_properties", False) idle_timeout = kwargs.get("idle_timeout", None) self.running = False self.closed = False self.stop = False # used by event processor self.handler_ready = False self._on_event_received = kwargs.get("on_event_received") self._client = client self._source = source self._offset = event_position self._offset_inclusive = kwargs.get("event_position_inclusive", False) self._prefetch = prefetch 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 = {} 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) * 1000 # pylint:disable=protected-access self._link_properties[types.AMQPSymbol( TIMEOUT_SYMBOL)] = types.AMQPLong(int(link_property_timeout_ms)) self._handler = None self._track_last_enqueued_event_properties = track_last_enqueued_event_properties self._last_received_event = None