Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EventHubs] Add keep_alive_interval to producer client #23361

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def __init__(self, fully_qualified_namespace, eventhub_name, credential, **kwarg
self._credential = EventhubAzureNamedKeyTokenCredential(credential) # type: ignore
else:
self._credential = credential # type: ignore
self._keep_alive = kwargs.get("keep_alive", 30)
self._keep_alive_interval = kwargs.get("keep_alive_interval")
self._auto_reconnect = kwargs.get("auto_reconnect", True)
self._mgmt_target = "amqps://{}/{}".format(
self._address.hostname, self.eventhub_name
Expand Down
6 changes: 3 additions & 3 deletions sdk/eventhub/azure-eventhub/azure/eventhub/_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self, client, target, **kwargs):
# type: (EventHubProducerClient, str, Any) -> None
partition = kwargs.get("partition", None)
send_timeout = kwargs.get("send_timeout", 60)
keep_alive = kwargs.get("keep_alive", None)
keep_alive_interval = kwargs.get("keep_alive_interval")
auto_reconnect = kwargs.get("auto_reconnect", True)
idle_timeout = kwargs.get("idle_timeout", None)

Expand All @@ -99,7 +99,7 @@ def __init__(self, client, target, **kwargs):
self._timeout = send_timeout
self._idle_timeout = (idle_timeout * 1000) if idle_timeout else None
self._error = None
self._keep_alive = keep_alive
self._keep_alive_interval = keep_alive_interval
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
Expand Down Expand Up @@ -127,7 +127,7 @@ def _create_handler(self, auth):
msg_timeout=self._timeout * 1000,
idle_timeout=self._idle_timeout,
error_policy=self._retry_policy,
keep_alive_interval=self._keep_alive,
keep_alive_interval=self._keep_alive_interval,
client_name=self._name,
link_properties=self._link_properties,
properties=create_properties(self._client._config.user_agent), # pylint: disable=protected-access
Expand Down
11 changes: 11 additions & 0 deletions sdk/eventhub/azure-eventhub/azure/eventhub/_producer_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class EventHubProducerClient(ClientBase):
:keyword str connection_verify: Path to the custom CA_BUNDLE file of the SSL certificate which is used to
authenticate the identity of the connection endpoint.
Default is None in which case `certifi.where()` will be used.
:keyword keep_alive_interval: If set, a thread will be started to keep the connection
alive during periods of user inactivity. The value will determine how long the
thread will sleep (in seconds) between pinging the connection. If 0 or None, no
thread will be started. Default is None.
:paramtype keep_alive_interval: int or None

.. admonition:: Example:

Expand Down Expand Up @@ -176,6 +181,7 @@ def _create_producer(self, partition_id=None, send_timeout=None):
partition=partition_id,
send_timeout=send_timeout,
idle_timeout=self._idle_timeout,
keep_alive_interval=self._keep_alive_interval
)
return handler

Expand Down Expand Up @@ -221,6 +227,11 @@ def from_connection_string(cls, conn_str, **kwargs):
:keyword str connection_verify: Path to the custom CA_BUNDLE file of the SSL certificate which is used to
authenticate the identity of the connection endpoint.
Default is None in which case `certifi.where()` will be used.
:keyword keep_alive_interval: If set, a thread will be started to keep the connection
alive during periods of user inactivity. The value will determine how long the
thread will sleep (in seconds) between pinging the connection. If 0 or None, no
thread will be started. Default is None.
:paramtype keep_alive_interval: int or None
:rtype: ~azure.eventhub.EventHubProducerClient

.. admonition:: Example:
Expand Down
2 changes: 1 addition & 1 deletion sdk/eventhub/azure-eventhub/azure/eventhub/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Licensed under the MIT License.
# ------------------------------------

VERSION = "5.9.0b2"
VERSION = "5.10.0b1"
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, client: "EventHubProducerClient", target: str, **kwargs) -> N
super().__init__()
partition = kwargs.get("partition", None)
send_timeout = kwargs.get("send_timeout", 60)
keep_alive = kwargs.get("keep_alive", None)
keep_alive_interval = kwargs.get("keep_alive_interval")
auto_reconnect = kwargs.get("auto_reconnect", True)
idle_timeout = kwargs.get("idle_timeout", None)

Expand All @@ -75,7 +75,7 @@ def __init__(self, client: "EventHubProducerClient", target: str, **kwargs) -> N
self._client = client
self._target = target
self._partition = partition
self._keep_alive = keep_alive
self._keep_alive_interval = keep_alive_interval
self._auto_reconnect = auto_reconnect
self._timeout = send_timeout
self._idle_timeout = (idle_timeout * 1000) if idle_timeout else None
Expand Down Expand Up @@ -105,7 +105,7 @@ def _create_handler(self, auth: "JWTTokenAsync") -> None:
msg_timeout=self._timeout * 1000,
idle_timeout=self._idle_timeout,
error_policy=self._retry_policy,
keep_alive_interval=self._keep_alive,
keep_alive_interval=self._keep_alive_interval,
client_name=self._name,
link_properties=self._link_properties,
properties=create_properties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class EventHubProducerClient(ClientBaseAsync):
:keyword str connection_verify: Path to the custom CA_BUNDLE file of the SSL certificate which is used to
authenticate the identity of the connection endpoint.
Default is None in which case `certifi.where()` will be used.
:keyword keep_alive_interval: If set, a coroutine will be started to keep the connection
alive during periods of user inactivity. The value will determine how long the
coroutine will sleep (in seconds) between pinging the connection. If 0 or None, no
coroutine will be started. Default is None.
:paramtype keep_alive_interval: int or None

.. admonition:: Example:

Expand Down Expand Up @@ -180,6 +185,7 @@ def _create_producer(
partition=partition_id,
send_timeout=send_timeout,
idle_timeout=self._idle_timeout,
keep_alive_interval=self._keep_alive_interval,
**self._internal_kwargs
)
return handler
Expand Down Expand Up @@ -237,6 +243,11 @@ def from_connection_string(
:keyword str connection_verify: Path to the custom CA_BUNDLE file of the SSL certificate which is used to
authenticate the identity of the connection endpoint.
Default is None in which case `certifi.where()` will be used.
:keyword keep_alive_interval: If set, a coroutine will be started to keep the connection
alive during periods of user inactivity. The value will determine how long the
coroutine will sleep (in seconds) between pinging the connection. If 0 or None, no
coroutine will be started. Default is None.
:paramtype keep_alive_interval: int or None
:rtype: ~azure.eventhub.aio.EventHubProducerClient

.. admonition:: Example:
Expand Down