-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[ServiceBus] expand kwargs in public API #22353
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
Changes from 3 commits
21efe9d
5be09e8
03a93bb
9171e49
4983f60
ef19350
c9e0c95
7b40dbc
dc554cc
6bc5129
b1a646e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,12 @@ | |
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| from typing import Any, Union, TYPE_CHECKING | ||
| from typing import Any, Dict, Union, Optional, TYPE_CHECKING | ||
| import logging | ||
| from weakref import WeakSet | ||
|
|
||
| import uamqp | ||
| from uamqp.constants import TransportType | ||
|
swathipil marked this conversation as resolved.
Outdated
|
||
|
|
||
| from ._base_handler import ( | ||
| _parse_conn_str, | ||
|
|
@@ -15,16 +16,27 @@ | |
| ) | ||
| from ._servicebus_sender import ServiceBusSender | ||
| from ._servicebus_receiver import ServiceBusReceiver | ||
| from ._common.auto_lock_renewer import AutoLockRenewer | ||
| from ._common._configuration import Configuration | ||
| from ._common.utils import ( | ||
| create_authentication, | ||
| generate_dead_letter_entity_name, | ||
| strip_protocol_from_uri, | ||
| ) | ||
| from ._common.constants import ServiceBusSubQueue | ||
| from ._common.constants import ( | ||
| ServiceBusSubQueue, | ||
| ServiceBusReceiveMode, | ||
| ServiceBusSessionFilter | ||
| ) | ||
| from ._retry import RetryMode | ||
|
|
||
| if TYPE_CHECKING: | ||
| from azure.core.credentials import TokenCredential, AzureSasCredential, AzureNamedKeyCredential | ||
| from azure.core.credentials import ( | ||
| TokenCredential, | ||
| AzureSasCredential, | ||
| AzureNamedKeyCredential, | ||
| ) | ||
|
|
||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -74,15 +86,40 @@ class ServiceBusClient(object): | |
|
|
||
| """ | ||
|
|
||
| def __init__(self, fully_qualified_namespace, credential, **kwargs): | ||
| # type: (str, Union[TokenCredential, AzureSasCredential, AzureNamedKeyCredential], Any) -> None | ||
| def __init__( | ||
| self, | ||
| fully_qualified_namespace: str, | ||
| credential: Union[ | ||
| "TokenCredential", "AzureSasCredential", "AzureNamedKeyCredential" | ||
| ], | ||
| *, | ||
| http_proxy: Optional[Dict[str, Any]] = None, | ||
| user_agent: Optional[str] = None, | ||
| logging_enable: Optional[bool] = False, | ||
| transport_type: Optional[TransportType] = TransportType.Amqp, | ||
|
swathipil marked this conversation as resolved.
Outdated
swathipil marked this conversation as resolved.
Outdated
|
||
| retry_total: int = 3, | ||
| retry_backoff_factor: float = 0.8, | ||
| retry_backoff_max: int = 120, | ||
| retry_mode: RetryMode = RetryMode.EXPONENTIAL, | ||
| **kwargs: Any | ||
| ) -> None: | ||
| # If the user provided http:// or sb://, let's be polite and strip that. | ||
| self.fully_qualified_namespace = strip_protocol_from_uri( | ||
| fully_qualified_namespace.strip() | ||
| ) | ||
|
|
||
| self._credential = credential | ||
| self._config = Configuration(**kwargs) | ||
| self._config = Configuration( | ||
| http_proxy=http_proxy, | ||
| user_agent=user_agent, | ||
| logging_enable=logging_enable, | ||
| transport_type=transport_type, | ||
| retry_total=retry_total, | ||
| retry_backoff_factor=retry_backoff_factor, | ||
| retry_backoff_max=retry_backoff_max, | ||
| retry_mode=retry_mode, | ||
| **kwargs | ||
| ) | ||
| self._connection = None | ||
| # Optional entity name, can be the name of Queue or Topic. Intentionally not advertised, typically be needed. | ||
| self._entity_name = kwargs.get("entity_name") | ||
|
|
@@ -133,8 +170,20 @@ def close(self): | |
| self._connection.destroy() | ||
|
|
||
| @classmethod | ||
| def from_connection_string(cls, conn_str, **kwargs): | ||
| # type: (str, Any) -> ServiceBusClient | ||
| def from_connection_string( | ||
| cls, | ||
| conn_str: str, | ||
| *, | ||
| http_proxy: Optional[Dict[str, Any]] = None, | ||
| user_agent: Optional[str] = None, | ||
| logging_enable: bool = False, | ||
| transport_type: TransportType = TransportType.Amqp, | ||
|
swathipil marked this conversation as resolved.
Outdated
|
||
| retry_total: int = 3, | ||
| retry_backoff_factor: float = 0.8, | ||
| retry_backoff_max: int = 120, | ||
| retry_mode: RetryMode = RetryMode.EXPONENTIAL, | ||
| **kwargs: Any | ||
| ) -> "ServiceBusClient": | ||
| """ | ||
| Create a ServiceBusClient from a connection string. | ||
|
|
||
|
|
@@ -179,6 +228,14 @@ def from_connection_string(cls, conn_str, **kwargs): | |
| fully_qualified_namespace=host, | ||
| entity_name=entity_in_conn_str or kwargs.pop("entity_name", None), | ||
| credential=credential, # type: ignore | ||
| http_proxy=http_proxy, | ||
| user_agent=user_agent, | ||
| logging_enable=logging_enable, | ||
| transport_type=transport_type, | ||
| retry_total=retry_total, | ||
| retry_backoff_factor=retry_backoff_factor, | ||
| retry_backoff_max=retry_backoff_max, | ||
| retry_mode=retry_mode, | ||
| **kwargs | ||
| ) | ||
|
|
||
|
|
@@ -225,15 +282,27 @@ def get_queue_sender(self, queue_name, **kwargs): | |
| self._handlers.add(handler) | ||
| return handler | ||
|
|
||
| def get_queue_receiver(self, queue_name, **kwargs): | ||
| # type: (str, Any) -> ServiceBusReceiver | ||
| def get_queue_receiver( | ||
| self, | ||
| queue_name: str, | ||
| *, | ||
| session_id: Optional[Union[str, ServiceBusSessionFilter]] = None, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
what mypy error are you getting with this:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removing for now. BUT NEED TO REVISIT!! |
||
| sub_queue: Optional[Union[ServiceBusSubQueue, str]] = None, | ||
| receive_mode: Union[ | ||
| ServiceBusReceiveMode, str | ||
| ] = ServiceBusReceiveMode.PEEK_LOCK, | ||
| max_wait_time: Optional[float] = None, | ||
| auto_lock_renewer: Optional[AutoLockRenewer] = None, | ||
| prefetch_count: int = 0, | ||
| **kwargs: Any | ||
| ) -> ServiceBusReceiver: | ||
| """Get ServiceBusReceiver for the specific queue. | ||
|
|
||
| :param str queue_name: The path of specific Service Bus Queue the client connects to. | ||
| :keyword session_id: A specific session from which to receive. This must be specified for a | ||
| sessionful queue, otherwise it must be None. In order to receive messages from the next available | ||
| session, set this to ~azure.servicebus.NEXT_AVAILABLE_SESSION. | ||
| :paramtype session_id: Union[str, ~azure.servicebus.NEXT_AVAILABLE_SESSION] | ||
| :paramtype session_id: Optional[Union[str, ~azure.servicebus.NEXT_AVAILABLE_SESSION]] | ||
|
swathipil marked this conversation as resolved.
Outdated
|
||
| :keyword Optional[Union[ServiceBusSubQueue, str]] sub_queue: If specified, the subqueue this receiver will | ||
| connect to. | ||
| This includes the DEAD_LETTER and TRANSFER_DEAD_LETTER queues, holds messages that can't be delivered to any | ||
|
|
@@ -278,8 +347,7 @@ def get_queue_receiver(self, queue_name, **kwargs): | |
| "the connection string used to construct the ServiceBusClient." | ||
| ) | ||
|
|
||
| sub_queue = kwargs.get("sub_queue", None) | ||
| if sub_queue and kwargs.get("session_id"): | ||
| if sub_queue and session_id: | ||
| raise ValueError( | ||
| "session_id and sub_queue can not be specified simultaneously. " | ||
| "To connect to the sub queue of a sessionful queue, " | ||
|
|
@@ -312,6 +380,12 @@ def get_queue_receiver(self, queue_name, **kwargs): | |
| retry_total=self._config.retry_total, | ||
| retry_backoff_factor=self._config.retry_backoff_factor, | ||
| retry_backoff_max=self._config.retry_backoff_max, | ||
| session_id=session_id, | ||
| sub_queue=sub_queue, | ||
| receive_mode=receive_mode, | ||
| max_wait_time=max_wait_time, | ||
| auto_lock_renewer=auto_lock_renewer, | ||
| prefetch_count=prefetch_count, | ||
| **kwargs | ||
| ) | ||
| self._handlers.add(handler) | ||
|
|
@@ -359,8 +433,21 @@ def get_topic_sender(self, topic_name, **kwargs): | |
| self._handlers.add(handler) | ||
| return handler | ||
|
|
||
| def get_subscription_receiver(self, topic_name, subscription_name, **kwargs): | ||
| # type: (str, str, Any) -> ServiceBusReceiver | ||
| def get_subscription_receiver( | ||
| self, | ||
| topic_name: str, | ||
| subscription_name: str, | ||
| *, | ||
| session_id: Optional[Union[str, ServiceBusSessionFilter]] = None, | ||
| sub_queue: Optional[Union[ServiceBusSubQueue, str]] = None, | ||
| receive_mode: Union[ | ||
| ServiceBusReceiveMode, str | ||
| ] = ServiceBusReceiveMode.PEEK_LOCK, | ||
| max_wait_time: Optional[float] = None, | ||
| auto_lock_renewer: Optional[AutoLockRenewer] = None, | ||
| prefetch_count: int = 0, | ||
| **kwargs: Any | ||
| ) -> ServiceBusReceiver: | ||
| """Get ServiceBusReceiver for the specific subscription under the topic. | ||
|
|
||
| :param str topic_name: The name of specific Service Bus Topic the client connects to. | ||
|
|
@@ -369,7 +456,7 @@ def get_subscription_receiver(self, topic_name, subscription_name, **kwargs): | |
| :keyword session_id: A specific session from which to receive. This must be specified for a | ||
| sessionful subscription, otherwise it must be None. In order to receive messages from the next available | ||
| session, set this to ~azure.servicebus.NEXT_AVAILABLE_SESSION. | ||
| :paramtype session_id: Union[str, ~azure.servicebus.NEXT_AVAILABLE_SESSION] | ||
| :paramtype session_id: Optional[Union[str, ~azure.servicebus.NEXT_AVAILABLE_SESSION]] | ||
| :keyword Optional[Union[ServiceBusSubQueue, str]] sub_queue: If specified, the subqueue this receiver will | ||
| connect to. | ||
| This includes the DEAD_LETTER and TRANSFER_DEAD_LETTER queues, holds messages that can't be delivered to any | ||
|
|
@@ -415,8 +502,7 @@ def get_subscription_receiver(self, topic_name, subscription_name, **kwargs): | |
| "the connection string used to construct the ServiceBusClient." | ||
| ) | ||
|
|
||
| sub_queue = kwargs.get("sub_queue", None) | ||
| if sub_queue and kwargs.get("session_id"): | ||
| if sub_queue and session_id: | ||
| raise ValueError( | ||
| "session_id and sub_queue can not be specified simultaneously. " | ||
| "To connect to the sub queue of a sessionful subscription, " | ||
|
|
@@ -444,6 +530,12 @@ def get_subscription_receiver(self, topic_name, subscription_name, **kwargs): | |
| retry_total=self._config.retry_total, | ||
| retry_backoff_factor=self._config.retry_backoff_factor, | ||
| retry_backoff_max=self._config.retry_backoff_max, | ||
| session_id=session_id, | ||
| sub_queue=sub_queue, | ||
| receive_mode=receive_mode, | ||
| max_wait_time=max_wait_time, | ||
| auto_lock_renewer=auto_lock_renewer, | ||
| prefetch_count=prefetch_count, | ||
| **kwargs | ||
| ) | ||
| except ValueError: | ||
|
|
@@ -465,6 +557,12 @@ def get_subscription_receiver(self, topic_name, subscription_name, **kwargs): | |
| retry_total=self._config.retry_total, | ||
| retry_backoff_factor=self._config.retry_backoff_factor, | ||
| retry_backoff_max=self._config.retry_backoff_max, | ||
| session_id=session_id, | ||
| sub_queue=sub_queue, | ||
| receive_mode=receive_mode, | ||
| max_wait_time=max_wait_time, | ||
| auto_lock_renewer=auto_lock_renewer, | ||
| prefetch_count=prefetch_count, | ||
| **kwargs | ||
| ) | ||
| self._handlers.add(handler) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.