diff --git a/sdk/servicebus/azure-servicebus/CHANGELOG.md b/sdk/servicebus/azure-servicebus/CHANGELOG.md index 0e7cc22991c3..d029bb3cc44a 100644 --- a/sdk/servicebus/azure-servicebus/CHANGELOG.md +++ b/sdk/servicebus/azure-servicebus/CHANGELOG.md @@ -46,6 +46,13 @@ now raise more concrete exception other than `MessageSettleFailed` and `ServiceB - Changed `ServiceBusReceivedMessage.renew_lock` to `ServiceBusReceiver.renew_message_lock` * `AutoLockRenewer.register` now takes `ServiceBusReceiver` as a positional parameter. * Removed `encoding` support from `ServiceBusMessage`. +* `ServiceBusMessage.amqp_message` has been renamed to `ServiceBusMessage.amqp_annotated_message` for cross-sdk consistency. +* All `name` parameters in `ServiceBusAdministrationClient` are now precisely specified ala `queue_name` or `rule_name` +* `ServiceBusMessage.via_partition_key` is no longer exposed, this is pending a full implementation of transactions as it has no external use. If needed, the underlying value can still be accessed in `ServiceBusMessage.amqp_annotated_message.annotations`. +* `ServiceBusMessage.properties` has been renamed to `ServiceBusMessage.application_properties` for consistency with service verbiage. +* Sub-client (`ServiceBusSender` and `ServiceBusReceiver`) `from_connection_string` initializers have been made internal until needed. Clients should be initialized from root `ServiceBusClient`. +* `ServiceBusMessage.label` has been renamed to `ServiceBusMessage.subject`. +* `ServiceBusMessage.amqp_annotated_message` has had its type renamed from `AMQPMessage` to `AMQPAnnotatedMessage` **BugFixes** diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py index aa6c4cb0c2a8..f2b1600b14a2 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py @@ -22,7 +22,6 @@ _X_OPT_SEQUENCE_NUMBER, _X_OPT_ENQUEUE_SEQUENCE_NUMBER, _X_OPT_PARTITION_KEY, - _X_OPT_VIA_PARTITION_KEY, _X_OPT_LOCKED_UNTIL, _X_OPT_LOCK_TOKEN, _X_OPT_SCHEDULED_ENQUEUE_TIME, @@ -30,7 +29,6 @@ PROPERTIES_DEAD_LETTER_REASON, PROPERTIES_DEAD_LETTER_ERROR_DESCRIPTION, ANNOTATION_SYMBOL_PARTITION_KEY, - ANNOTATION_SYMBOL_VIA_PARTITION_KEY, ANNOTATION_SYMBOL_SCHEDULED_ENQUEUE_TIME, ANNOTATION_SYMBOL_KEY_MAP ) @@ -49,22 +47,21 @@ class ServiceBusMessage(object): # pylint: disable=too-many-public-methods,too- :param body: The data to send in a single message. :type body: Union[str, bytes] - :keyword dict properties: The user defined properties on the message. + :keyword dict application_properties: The user defined properties on the message. :keyword str session_id: The session identifier of the message for a sessionful entity. :keyword str message_id: The id to identify the message. :keyword datetime.datetime scheduled_enqueue_time_utc: The utc scheduled enqueue time to the message. :keyword datetime.timedelta time_to_live: The life duration of a message. :keyword str content_type: The content type descriptor. :keyword str correlation_id: The correlation identifier. - :keyword str label: The application specific label. + :keyword str subject: The application specific subject, sometimes referred to as label. :keyword str partition_key: The partition key for sending a message to a partitioned entity. - :keyword str via_partition_key: The partition key for sending a message into an entity via a partitioned - transfer queue. :keyword str to: The `to` address used for auto_forward chaining scenarios. :keyword str reply_to: The address of an entity to send replies to. :keyword str reply_to_session_id: The session identifier augmenting the `reply_to` address. - :ivar AMQPMessage amqp_message: Advanced use only. The internal AMQP message payload that is sent or received. + :ivar AMQPAnnotatedMessage amqp_annotated_message: Advanced use only. + The internal AMQP message payload that is sent or received. .. admonition:: Example: @@ -92,7 +89,7 @@ def __init__(self, body, **kwargs): self._amqp_header = self.message.header else: self._build_message(body) - self.properties = kwargs.pop("properties", None) + self.application_properties = kwargs.pop("application_properties", None) self.session_id = kwargs.pop("session_id", None) self.message_id = kwargs.get("message_id", None) self.content_type = kwargs.pop("content_type", None) @@ -100,13 +97,13 @@ def __init__(self, body, **kwargs): self.to = kwargs.pop("to", None) self.reply_to = kwargs.pop("reply_to", None) self.reply_to_session_id = kwargs.pop("reply_to_session_id", None) - self.label = kwargs.pop("label", None) + self.subject = kwargs.pop("subject", None) self.scheduled_enqueue_time_utc = kwargs.pop("scheduled_enqueue_time_utc", None) self.time_to_live = kwargs.pop("time_to_live", None) self.partition_key = kwargs.pop("partition_key", None) - self.via_partition_key = kwargs.pop("via_partition_key", None) - # If message is the full message, amqp_message is the "public facing interface" for what we expose. - self.amqp_message = AMQPMessage(self.message) # type: AMQPMessage + + # If message is the full message, amqp_annotated_message is the "public facing interface" for what we expose. + self.amqp_annotated_message = AMQPAnnotatedMessage(self.message) # type: AMQPAnnotatedMessage def __str__(self): return str(self.message) @@ -167,7 +164,7 @@ def session_id(self, value): self._amqp_properties.group_id = value @property - def properties(self): + def application_properties(self): # type: () -> dict """The user defined properties on the message. @@ -175,8 +172,8 @@ def properties(self): """ return self.message.application_properties - @properties.setter - def properties(self, value): + @application_properties.setter + def application_properties(self, value): # type: (dict) -> None self.message.application_properties = value @@ -207,33 +204,6 @@ def partition_key(self, value): # type: (str) -> None self._set_message_annotations(_X_OPT_PARTITION_KEY, value) - @property - def via_partition_key(self): - # type: () -> Optional[str] - """ The partition key for sending a message into an entity via a partitioned transfer queue. - - If a message is sent via a transfer queue in the scope of a transaction, this value selects the transfer - queue partition: This is functionally equivalent to `partition_key` and ensures that messages are kept - together and in order as they are transferred. - - See Transfers and Send Via in - `https://docs.microsoft.com/azure/service-bus-messaging/service-bus-transactions#transfers-and-send-via`. - - :rtype: str - """ - via_p_key = None - try: - via_p_key = self.message.annotations.get(_X_OPT_VIA_PARTITION_KEY) or \ - self.message.annotations.get(ANNOTATION_SYMBOL_VIA_PARTITION_KEY) - return via_p_key.decode('UTF-8') - except (AttributeError, UnicodeDecodeError): - return via_p_key - - @via_partition_key.setter - def via_partition_key(self, value): - # type: (str) -> None - self._set_message_annotations(_X_OPT_VIA_PARTITION_KEY, value) - @property def time_to_live(self): # type: () -> Optional[datetime.timedelta] @@ -349,9 +319,9 @@ def correlation_id(self, val): self._amqp_properties.correlation_id = val @property - def label(self): + def subject(self): # type: () -> str - """The application specific label. + """The application specific subject, sometimes referred to as a label. This property enables the application to indicate the purpose of the message to the receiver in a standardized fashion, similar to an email subject line. @@ -363,8 +333,8 @@ def label(self): except (AttributeError, UnicodeDecodeError): return self._amqp_properties.subject - @label.setter - def label(self, val): + @subject.setter + def subject(self, val): # type: (str) -> None self._amqp_properties.subject = val @@ -624,17 +594,16 @@ def _to_outgoing_message(self): body=body, content_type=self.content_type, correlation_id=self.correlation_id, - label=self.label, + subject=self.subject, message_id=self.message_id, partition_key=self.partition_key, - properties=self.properties, + application_properties=self.application_properties, reply_to=self.reply_to, reply_to_session_id=self.reply_to_session_id, session_id=self.session_id, scheduled_enqueue_time_utc=self.scheduled_enqueue_time_utc, time_to_live=self.time_to_live, - to=self.to, - via_partition_key=self.via_partition_key + to=self.to ) @property @@ -798,7 +767,7 @@ def locked_until_utc(self): return self._expiry -class AMQPMessage(object): +class AMQPAnnotatedMessage(object): """ The internal AMQP message that this ServiceBusMessage represents. Is read-only. """ diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py index 852c5ee82a7e..f042bc92a0d0 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_receiver.py @@ -2,7 +2,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import datetime import time import logging import functools @@ -48,6 +47,7 @@ if TYPE_CHECKING: + import datetime from azure.core.credentials import TokenCredential _LOGGER = logging.getLogger(__name__) @@ -152,6 +152,8 @@ def __iter__(self): return self._iter_contextual_wrapper() def _iter_contextual_wrapper(self, max_wait_time=None): + """The purpose of this wrapper is to allow both state restoration (for multiple concurrent iteration) + and per-iter argument passing that requires the former.""" # pylint: disable=protected-access original_timeout = None while True: @@ -404,7 +406,7 @@ def get_streaming_message_iter(self, max_wait_time=None): return self._iter_contextual_wrapper(max_wait_time) @classmethod - def from_connection_string( + def _from_connection_string( cls, conn_str, **kwargs diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_sender.py b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_sender.py index 4d073a924b22..a32cb7a5421f 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_sender.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/_servicebus_sender.py @@ -27,8 +27,7 @@ MGMT_REQUEST_MESSAGE, MGMT_REQUEST_MESSAGES, MGMT_REQUEST_MESSAGE_ID, - MGMT_REQUEST_PARTITION_KEY, - MGMT_REQUEST_VIA_PARTITION_KEY + MGMT_REQUEST_PARTITION_KEY ) if TYPE_CHECKING: @@ -76,8 +75,6 @@ def _build_schedule_request(cls, schedule_time_utc, *messages): message_data[MGMT_REQUEST_SESSION_ID] = message.session_id if message.partition_key: message_data[MGMT_REQUEST_PARTITION_KEY] = message.partition_key - if message.via_partition_key: - message_data[MGMT_REQUEST_VIA_PARTITION_KEY] = message.via_partition_key message_data[MGMT_REQUEST_MESSAGE] = bytearray(message.message.encode_message()) request_body[MGMT_REQUEST_MESSAGES].append(message_data) return request_body @@ -271,7 +268,7 @@ def cancel_scheduled_messages(self, sequence_numbers, **kwargs): ) @classmethod - def from_connection_string( + def _from_connection_string( cls, conn_str, **kwargs diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py index 6f9d11d78a81..7dddfaede3e8 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_receiver_async.py @@ -405,7 +405,7 @@ def get_streaming_message_iter( return self._IterContextualWrapper(self, max_wait_time) @classmethod - def from_connection_string( + def _from_connection_string( cls, conn_str: str, **kwargs: Any diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_sender_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_sender_async.py index 14ba56b2b351..d2a016c9b50b 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_sender_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/_servicebus_sender_async.py @@ -217,7 +217,7 @@ async def cancel_scheduled_messages(self, sequence_numbers: Union[int, List[int] ) @classmethod - def from_connection_string( + def _from_connection_string( cls, conn_str: str, **kwargs: Any diff --git a/sdk/servicebus/azure-servicebus/migration_guide.md b/sdk/servicebus/azure-servicebus/migration_guide.md index cb2884fd8316..338d493310ae 100644 --- a/sdk/servicebus/azure-servicebus/migration_guide.md +++ b/sdk/servicebus/azure-servicebus/migration_guide.md @@ -84,6 +84,11 @@ semantics with the sender or receiver lifetime. |---|---|---| | `azure.servicebus.AutoLockRenew().shutdown()` | `azure.servicebus.AutoLockRenewer().close()` | [Close an auto-lock-renewer](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/servicebus/azure-servicebus/samples/sync_samples/auto_lock_renew.py) | +### Working with Message properties +| In v0.50 | Equivalent in v7 | Sample | +|---|---|---| +| `azure.servicebus.Message.user_properties` | `azure.servicebus.ServiceBusMessage.application_properties` | Some message properties have been renamed, e.g. accessing the application specific properties of a message. | + ## Migration samples diff --git a/sdk/servicebus/azure-servicebus/samples/async_samples/sample_code_servicebus_async.py b/sdk/servicebus/azure-servicebus/samples/async_samples/sample_code_servicebus_async.py index 32a5fe94f736..24e5d4702c45 100644 --- a/sdk/servicebus/azure-servicebus/samples/async_samples/sample_code_servicebus_async.py +++ b/sdk/servicebus/azure-servicebus/samples/async_samples/sample_code_servicebus_async.py @@ -57,7 +57,7 @@ async def example_create_servicebus_sender_async(): from azure.servicebus.aio import ServiceBusSender servicebus_connection_str = os.environ['SERVICE_BUS_CONNECTION_STR'] queue_name = os.environ['SERVICE_BUS_QUEUE_NAME'] - queue_sender = ServiceBusSender.from_connection_string( + queue_sender = ServiceBusSender._from_connection_string( conn_str=servicebus_connection_str, queue_name=queue_name ) @@ -111,7 +111,7 @@ async def example_create_servicebus_receiver_async(): from azure.servicebus.aio import ServiceBusReceiver servicebus_connection_str = os.environ['SERVICE_BUS_CONNECTION_STR'] queue_name = os.environ['SERVICE_BUS_QUEUE_NAME'] - queue_receiver = ServiceBusReceiver.from_connection_string( + queue_receiver = ServiceBusReceiver._from_connection_string( conn_str=servicebus_connection_str, queue_name=queue_name ) diff --git a/sdk/servicebus/azure-servicebus/samples/sync_samples/sample_code_servicebus.py b/sdk/servicebus/azure-servicebus/samples/sync_samples/sample_code_servicebus.py index a4edf2546694..2aba764e7b56 100644 --- a/sdk/servicebus/azure-servicebus/samples/sync_samples/sample_code_servicebus.py +++ b/sdk/servicebus/azure-servicebus/samples/sync_samples/sample_code_servicebus.py @@ -53,7 +53,7 @@ def example_create_servicebus_sender_sync(): from azure.servicebus import ServiceBusSender servicebus_connection_str = os.environ['SERVICE_BUS_CONNECTION_STR'] queue_name = os.environ['SERVICE_BUS_QUEUE_NAME'] - queue_sender = ServiceBusSender.from_connection_string( + queue_sender = ServiceBusSender._from_connection_string( conn_str=servicebus_connection_str, queue_name=queue_name ) @@ -107,7 +107,7 @@ def example_create_servicebus_receiver_sync(): from azure.servicebus import ServiceBusReceiver servicebus_connection_str = os.environ['SERVICE_BUS_CONNECTION_STR'] queue_name = os.environ['SERVICE_BUS_QUEUE_NAME'] - queue_receiver = ServiceBusReceiver.from_connection_string( + queue_receiver = ServiceBusReceiver._from_connection_string( conn_str=servicebus_connection_str, queue_name=queue_name ) @@ -244,7 +244,7 @@ def example_send_and_receive_sync(): print("Sequence number: {}".format(message.sequence_number)) print("Enqueued Sequence numger: {}".format(message.enqueued_sequence_number)) print("Partition Key: {}".format(message.partition_key)) - print("Properties: {}".format(message.properties)) + print("Application Properties: {}".format(message.application_properties)) print("Delivery count: {}".format(message.delivery_count)) print("Message ID: {}".format(message.message_id)) print("Locked until: {}".format(message.locked_until_utc)) diff --git a/sdk/servicebus/azure-servicebus/tests/async_tests/test_queues_async.py b/sdk/servicebus/azure-servicebus/tests/async_tests/test_queues_async.py index 17e6850489f0..6af877989aeb 100644 --- a/sdk/servicebus/azure-servicebus/tests/async_tests/test_queues_async.py +++ b/sdk/servicebus/azure-servicebus/tests/async_tests/test_queues_async.py @@ -422,8 +422,8 @@ async def test_async_queue_by_servicebus_client_iter_messages_with_retrieve_defe print_message(_logger, message) assert message.dead_letter_reason == 'Testing reason' assert message.dead_letter_error_description == 'Testing description' - assert message.properties[b'DeadLetterReason'] == b'Testing reason' - assert message.properties[b'DeadLetterErrorDescription'] == b'Testing description' + assert message.application_properties[b'DeadLetterReason'] == b'Testing reason' + assert message.application_properties[b'DeadLetterErrorDescription'] == b'Testing description' await receiver.complete_message(message) assert count == 10 @@ -539,8 +539,8 @@ async def test_async_queue_by_servicebus_client_receive_batch_with_deadletter(se count += 1 assert message.dead_letter_reason == 'Testing reason' assert message.dead_letter_error_description == 'Testing description' - assert message.properties[b'DeadLetterReason'] == b'Testing reason' - assert message.properties[b'DeadLetterErrorDescription'] == b'Testing description' + assert message.application_properties[b'DeadLetterReason'] == b'Testing reason' + assert message.application_properties[b'DeadLetterErrorDescription'] == b'Testing description' assert count == 10 @pytest.mark.liveTest @@ -581,8 +581,8 @@ async def test_async_queue_by_servicebus_client_receive_batch_with_retrieve_dead print_message(_logger, message) assert message.dead_letter_reason == 'Testing reason' assert message.dead_letter_error_description == 'Testing description' - assert message.properties[b'DeadLetterReason'] == b'Testing reason' - assert message.properties[b'DeadLetterErrorDescription'] == b'Testing description' + assert message.application_properties[b'DeadLetterReason'] == b'Testing reason' + assert message.application_properties[b'DeadLetterErrorDescription'] == b'Testing description' await receiver.complete_message(message) count += 1 assert count == 10 @@ -1255,7 +1255,7 @@ def message_content(): for i in range(20): yield ServiceBusMessage( body="ServiceBusMessage no. {}".format(i), - label='1st' + subject='1st' ) sender = sb_client.get_queue_sender(servicebus_queue.name) @@ -1281,12 +1281,12 @@ def message_content(): receive_counter += 1 for message in messages: print_message(_logger, message) - if message.label == '1st': + if message.subject == '1st': message_1st_received_cnt += 1 await receiver.complete_message(message) - message.label = '2nd' + message.subject = '2nd' await sender.send_messages(message) # resending received message - elif message.label == '2nd': + elif message.subject == '2nd': message_2nd_received_cnt += 1 await receiver.complete_message(message) diff --git a/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py b/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py index 64e86d266772..0c2fdd7438be 100644 --- a/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py +++ b/sdk/servicebus/azure-servicebus/tests/async_tests/test_sessions_async.py @@ -267,8 +267,8 @@ async def test_async_session_by_servicebus_client_iter_messages_with_retrieve_de print_message(_logger, message) assert message.dead_letter_reason == 'Testing reason' assert message.dead_letter_error_description == 'Testing description' - assert message.properties[b'DeadLetterReason'] == b'Testing reason' - assert message.properties[b'DeadLetterErrorDescription'] == b'Testing description' + assert message.application_properties[b'DeadLetterReason'] == b'Testing reason' + assert message.application_properties[b'DeadLetterErrorDescription'] == b'Testing description' await receiver.complete_message(message) assert count == 10 @@ -372,8 +372,8 @@ async def test_async_session_by_servicebus_client_fetch_next_with_retrieve_deadl print_message(_logger, message) assert message.dead_letter_reason == 'Testing reason' assert message.dead_letter_error_description == 'Testing description' - assert message.properties[b'DeadLetterReason'] == b'Testing reason' - assert message.properties[b'DeadLetterErrorDescription'] == b'Testing description' + assert message.application_properties[b'DeadLetterReason'] == b'Testing reason' + assert message.application_properties[b'DeadLetterErrorDescription'] == b'Testing description' await receiver.complete_message(message) count += 1 assert count == 10 diff --git a/sdk/servicebus/azure-servicebus/tests/async_tests/test_subscriptions_async.py b/sdk/servicebus/azure-servicebus/tests/async_tests/test_subscriptions_async.py index 485cc5de8d8d..6d5288b9f662 100644 --- a/sdk/servicebus/azure-servicebus/tests/async_tests/test_subscriptions_async.py +++ b/sdk/servicebus/azure-servicebus/tests/async_tests/test_subscriptions_async.py @@ -153,6 +153,6 @@ async def test_topic_by_servicebus_client_receive_batch_with_deadletter(self, se count += 1 assert message.dead_letter_reason == 'Testing reason' assert message.dead_letter_error_description == 'Testing description' - assert message.properties[b'DeadLetterReason'] == b'Testing reason' - assert message.properties[b'DeadLetterErrorDescription'] == b'Testing description' + assert message.application_properties[b'DeadLetterReason'] == b'Testing reason' + assert message.application_properties[b'DeadLetterErrorDescription'] == b'Testing description' assert count == 10 diff --git a/sdk/servicebus/azure-servicebus/tests/test_queues.py b/sdk/servicebus/azure-servicebus/tests/test_queues.py index abf03b962a7e..950c02fca95b 100644 --- a/sdk/servicebus/azure-servicebus/tests/test_queues.py +++ b/sdk/servicebus/azure-servicebus/tests/test_queues.py @@ -120,13 +120,12 @@ def test_queue_by_queue_client_conn_str_receive_handler_peeklock(self, servicebu with sb_client.get_queue_sender(servicebus_queue.name) as sender: for i in range(10): message = ServiceBusMessage("Handler message no. {}".format(i)) - message.properties = {'key': 'value'} - message.label = 'label' + message.application_properties = {'key': 'value'} + message.subject = 'label' message.content_type = 'application/text' message.correlation_id = 'cid' message.message_id = str(i) message.partition_key = 'pk' - message.via_partition_key = 'via_pk' message.to = 'to' message.reply_to = 'reply_to' sender.send_messages(message) @@ -136,14 +135,13 @@ def test_queue_by_queue_client_conn_str_receive_handler_peeklock(self, servicebu for message in receiver: print_message(_logger, message) assert message.delivery_count == 0 - assert message.properties - assert message.properties[b'key'] == b'value' - assert message.label == 'label' + assert message.application_properties + assert message.application_properties[b'key'] == b'value' + assert message.subject == 'label' assert message.content_type == 'application/text' assert message.correlation_id == 'cid' assert message.message_id == str(count) assert message.partition_key == 'pk' - assert message.via_partition_key == 'via_pk' assert message.to == 'to' assert message.reply_to == 'reply_to' assert message.sequence_number @@ -175,11 +173,9 @@ def test_queue_by_queue_client_send_multiple_messages(self, servicebus_namespace for i in range(10): message = ServiceBusMessage("Handler message no. {}".format(i)) message.partition_key = 'pkey' - message.via_partition_key = 'vpkey' message.time_to_live = timedelta(seconds=60) message.scheduled_enqueue_time_utc = utc_now() + timedelta(seconds=60) message.partition_key = None - message.via_partition_key = None message.time_to_live = None message.scheduled_enqueue_time_utc = None message.session_id = None @@ -191,12 +187,11 @@ def test_queue_by_queue_client_send_multiple_messages(self, servicebus_namespace for message in receiver: print_message(_logger, message) assert message.delivery_count == 0 - assert not message.properties - assert not message.label + assert not message.application_properties + assert not message.subject assert not message.content_type assert not message.correlation_id assert not message.partition_key - assert not message.via_partition_key assert not message.to assert not message.reply_to assert not message.scheduled_enqueue_time_utc @@ -228,12 +223,11 @@ def test_queue_by_queue_client_conn_str_receive_handler_receiveanddelete(self, s receive_mode=ReceiveMode.ReceiveAndDelete, max_wait_time=8) as receiver: for message in receiver: - assert not message.properties - assert not message.label + assert not message.application_properties + assert not message.subject assert not message.content_type assert not message.correlation_id assert not message.partition_key - assert not message.via_partition_key assert not message.to assert not message.reply_to assert not message.scheduled_enqueue_time_utc @@ -526,8 +520,8 @@ def test_queue_by_servicebus_client_iter_messages_with_retrieve_deferred_receive print_message(_logger, message) assert message.dead_letter_reason == 'Testing reason' assert message.dead_letter_error_description == 'Testing description' - assert message.properties[b'DeadLetterReason'] == b'Testing reason' - assert message.properties[b'DeadLetterErrorDescription'] == b'Testing description' + assert message.application_properties[b'DeadLetterReason'] == b'Testing reason' + assert message.application_properties[b'DeadLetterErrorDescription'] == b'Testing description' receiver.complete_message(message) assert count == 10 @@ -653,8 +647,8 @@ def test_queue_by_servicebus_client_receive_batch_with_deadletter(self, serviceb count += 1 assert message.dead_letter_reason == 'Testing reason' assert message.dead_letter_error_description == 'Testing description' - assert message.properties[b'DeadLetterReason'] == b'Testing reason' - assert message.properties[b'DeadLetterErrorDescription'] == b'Testing description' + assert message.application_properties[b'DeadLetterReason'] == b'Testing reason' + assert message.application_properties[b'DeadLetterErrorDescription'] == b'Testing description' assert count == 10 @pytest.mark.liveTest @@ -701,8 +695,8 @@ def test_queue_by_servicebus_client_receive_batch_with_retrieve_deadletter(self, print_message(_logger, message) assert message.dead_letter_reason == 'Testing reason' assert message.dead_letter_error_description == 'Testing description' - assert message.properties[b'DeadLetterReason'] == b'Testing reason' - assert message.properties[b'DeadLetterErrorDescription'] == b'Testing description' + assert message.application_properties[b'DeadLetterReason'] == b'Testing reason' + assert message.application_properties[b'DeadLetterErrorDescription'] == b'Testing description' dl_receiver.complete_message(message) count += 1 assert count == 10 @@ -767,13 +761,12 @@ def test_queue_by_servicebus_client_browse_messages_with_receiver(self, serviceb for i in range(5): message = ServiceBusMessage( body="Test message", - properties={'key': 'value'}, - label='label', + application_properties={'key': 'value'}, + subject='label', content_type='application/text', correlation_id='cid', message_id='mid', partition_key='pk', - via_partition_key='via_pk', to='to', reply_to='reply_to', time_to_live=timedelta(seconds=60) @@ -786,13 +779,12 @@ def test_queue_by_servicebus_client_browse_messages_with_receiver(self, serviceb for message in messages: print_message(_logger, message) assert b''.join(message.body) == b'Test message' - assert message.properties[b'key'] == b'value' - assert message.label == 'label' + assert message.application_properties[b'key'] == b'value' + assert message.subject == 'label' assert message.content_type == 'application/text' assert message.correlation_id == 'cid' assert message.message_id == 'mid' assert message.partition_key == 'pk' - assert message.via_partition_key == 'via_pk' assert message.to == 'to' assert message.reply_to == 'reply_to' assert message.time_to_live == timedelta(seconds=60) @@ -804,13 +796,12 @@ def test_queue_by_servicebus_client_browse_messages_with_receiver(self, serviceb cnt = 0 for message in receiver: assert b''.join(message.body) == b'Test message' - assert message.properties[b'key'] == b'value' - assert message.label == 'label' + assert message.application_properties[b'key'] == b'value' + assert message.subject == 'label' assert message.content_type == 'application/text' assert message.correlation_id == 'cid' assert message.message_id == 'mid' assert message.partition_key == 'pk' - assert message.via_partition_key == 'via_pk' assert message.to == 'to' assert message.reply_to == 'reply_to' assert message.time_to_live == timedelta(seconds=60) @@ -1154,13 +1145,12 @@ def test_queue_message_batch(self, servicebus_namespace_connection_string, servi def message_content(): for i in range(5): message = ServiceBusMessage("ServiceBusMessage no. {}".format(i)) - message.properties = {'key': 'value'} - message.label = 'label' + message.application_properties = {'key': 'value'} + message.subject = 'label' message.content_type = 'application/text' message.correlation_id = 'cid' message.message_id = str(i) message.partition_key = 'pk' - message.via_partition_key = 'via_pk' message.to = 'to' message.reply_to = 'reply_to' message.time_to_live = timedelta(seconds=60) @@ -1184,14 +1174,13 @@ def message_content(): count = 0 for message in messages: assert message.delivery_count == 0 - assert message.properties - assert message.properties[b'key'] == b'value' - assert message.label == 'label' + assert message.application_properties + assert message.application_properties[b'key'] == b'value' + assert message.subject == 'label' assert message.content_type == 'application/text' assert message.correlation_id == 'cid' assert message.message_id == str(count) assert message.partition_key == 'pk' - assert message.via_partition_key == 'via_pk' assert message.to == 'to' assert message.reply_to == 'reply_to' assert message.sequence_number @@ -1262,12 +1251,11 @@ def test_queue_schedule_multiple_messages(self, servicebus_namespace_connection_ message_b.message_id = message_id_b message_arry = [message_a, message_b] for message in message_arry: - message.properties = {'key': 'value'} - message.label = 'label' + message.application_properties = {'key': 'value'} + message.subject = 'label' message.content_type = 'application/text' message.correlation_id = 'cid' message.partition_key = 'pk' - message.via_partition_key = 'via_pk' message.to = 'to' message.reply_to = 'reply_to' @@ -1291,13 +1279,12 @@ def test_queue_schedule_multiple_messages(self, servicebus_namespace_connection_ assert messages[0].scheduled_enqueue_time_utc == scheduled_enqueue_time assert messages[0].scheduled_enqueue_time_utc <= messages[0].enqueued_time_utc.replace(microsecond=0) assert messages[0].delivery_count == 0 - assert messages[0].properties - assert messages[0].properties[b'key'] == b'value' - assert messages[0].label == 'label' + assert messages[0].application_properties + assert messages[0].application_properties[b'key'] == b'value' + assert messages[0].subject == 'label' assert messages[0].content_type == 'application/text' assert messages[0].correlation_id == 'cid' assert messages[0].partition_key == 'pk' - assert messages[0].via_partition_key == 'via_pk' assert messages[0].to == 'to' assert messages[0].reply_to == 'reply_to' assert messages[0].sequence_number @@ -1514,28 +1501,26 @@ def test_queue_message_properties(self): scheduled_enqueue_time = (utc_now() + timedelta(seconds=20)).replace(microsecond=0) message = ServiceBusMessage( body='data', - properties={'key': 'value'}, + application_properties={'key': 'value'}, session_id='sid', - label='label', + subject='label', content_type='application/text', correlation_id='cid', message_id='mid', partition_key='pk', - via_partition_key='via_pk', to='to', reply_to='reply_to', reply_to_session_id='reply_to_sid', scheduled_enqueue_time_utc=scheduled_enqueue_time ) - assert message.properties - assert message.properties['key'] == 'value' - assert message.label == 'label' + assert message.application_properties + assert message.application_properties['key'] == 'value' + assert message.subject == 'label' assert message.content_type == 'application/text' assert message.correlation_id == 'cid' assert message.message_id == 'mid' assert message.partition_key == 'pk' - assert message.via_partition_key == 'via_pk' assert message.to == 'to' assert message.reply_to == 'reply_to' assert message.session_id == 'sid' @@ -1543,11 +1528,9 @@ def test_queue_message_properties(self): assert message.scheduled_enqueue_time_utc == scheduled_enqueue_time message.partition_key = 'updated' - message.via_partition_key = 'updated' new_scheduled_time = (utc_now() + timedelta(hours=5)).replace(microsecond=0) message.scheduled_enqueue_time_utc = new_scheduled_time assert message.partition_key == 'updated' - assert message.via_partition_key == 'updated' assert message.scheduled_enqueue_time_utc == new_scheduled_time message.partition_key = None @@ -1555,7 +1538,6 @@ def test_queue_message_properties(self): message.scheduled_enqueue_time_utc = None assert message.partition_key is None - assert message.via_partition_key is None assert message.scheduled_enqueue_time_utc is None try: @@ -1574,25 +1556,20 @@ def test_queue_message_properties(self): ) received_message = ServiceBusReceivedMessage(uamqp_received_message, receiver=None) assert received_message.partition_key == 'r_key' - assert received_message.via_partition_key == 'r_via_key' assert received_message.scheduled_enqueue_time_utc == new_scheduled_time new_scheduled_time = utc_now() + timedelta(hours=1, minutes=49, seconds=32) received_message.partition_key = 'new_r_key' - received_message.via_partition_key = 'new_r_via_key' received_message.scheduled_enqueue_time_utc = new_scheduled_time assert received_message.partition_key == 'new_r_key' - assert received_message.via_partition_key == 'new_r_via_key' assert received_message.scheduled_enqueue_time_utc == new_scheduled_time received_message.partition_key = None - received_message.via_partition_key = None received_message.scheduled_enqueue_time_utc = None assert message.partition_key is None - assert message.via_partition_key is None assert message.scheduled_enqueue_time_utc is None @pytest.mark.liveTest @@ -1608,13 +1585,12 @@ def message_content(): for i in range(20): yield ServiceBusMessage( body="Test message", - properties={'key': 'value'}, - label='1st', + application_properties={'key': 'value'}, + subject='1st', content_type='application/text', correlation_id='cid', message_id='mid', partition_key='pk', - via_partition_key='via_pk', to='to', reply_to='reply_to', time_to_live=timedelta(seconds=60) @@ -1642,22 +1618,21 @@ def message_content(): for message in messages: print_message(_logger, message) assert b''.join(message.body) == b'Test message' - assert message.properties[b'key'] == b'value' + assert message.application_properties[b'key'] == b'value' assert message.content_type == 'application/text' assert message.correlation_id == 'cid' assert message.message_id == 'mid' assert message.partition_key == 'pk' - assert message.via_partition_key == 'via_pk' assert message.to == 'to' assert message.reply_to == 'reply_to' assert message.time_to_live == timedelta(seconds=60) - if message.label == '1st': + if message.subject == '1st': message_1st_received_cnt += 1 receiver.complete_message(message) - message.label = '2nd' + message.subject = '2nd' sender.send_messages(message) # resending received message - elif message.label == '2nd': + elif message.subject == '2nd': message_2nd_received_cnt += 1 receiver.complete_message(message) @@ -1796,6 +1771,7 @@ def test_queue_receiver_respects_max_wait_time_overrides(self, servicebus_namesp with sb_client.get_queue_receiver(servicebus_queue.name, max_wait_time=5) as receiver: time_1 = receiver._handler._counter.get_current_ms() + time_3 = time_1 # In case inner loop isn't hit, fail sanely. for message in receiver.get_streaming_message_iter(max_wait_time=10): messages.append(message) receiver.complete_message(message) @@ -1883,20 +1859,20 @@ def test_message_inner_amqp_properties(self, servicebus_namespace_connection_str message = ServiceBusMessage("body") with pytest.raises(AttributeError): # Note: If this is made read-writeable, this would be TypeError - message.amqp_message.properties = {"properties":1} + message.amqp_annotated_message.properties = {"properties":1} # NOTE: These are disabled pending cross-language-sdk consensus on sendability/writeability. - # message.amqp_message.properties.subject = "subject" + # message.amqp_annotated_message.properties.subject = "subject" # - # message.amqp_message.application_properties = {b"application_properties":1} + # message.amqp_annotated_message.application_properties = {b"application_properties":1} # - # message.amqp_message.annotations = {b"annotations":2} - # message.amqp_message.delivery_annotations = {b"delivery_annotations":3} + # message.amqp_annotated_message.annotations = {b"annotations":2} + # message.amqp_annotated_message.delivery_annotations = {b"delivery_annotations":3} # # with pytest.raises(TypeError): - # message.amqp_message.header = {"header":4} - # message.amqp_message.header.priority = 5 + # message.amqp_annotated_message.header = {"header":4} + # message.amqp_annotated_message.header.priority = 5 # - # message.amqp_message.footer = {b"footer":6} + # message.amqp_annotated_message.footer = {b"footer":6} with ServiceBusClient.from_connection_string( servicebus_namespace_connection_string, logging_enable=False) as sb_client: @@ -1905,21 +1881,21 @@ def test_message_inner_amqp_properties(self, servicebus_namespace_connection_str sender.send_messages(message) with sb_client.get_queue_receiver(servicebus_queue.name, max_wait_time=5) as receiver: message = receiver.receive_messages()[0] - assert message.amqp_message.application_properties == None \ - and message.amqp_message.annotations != None \ - and message.amqp_message.delivery_annotations != None \ - and message.amqp_message.footer == None \ - and message.amqp_message.properties != None \ - and message.amqp_message.header != None + assert message.amqp_annotated_message.application_properties == None \ + and message.amqp_annotated_message.annotations != None \ + and message.amqp_annotated_message.delivery_annotations != None \ + and message.amqp_annotated_message.footer == None \ + and message.amqp_annotated_message.properties != None \ + and message.amqp_annotated_message.header != None # NOTE: These are disabled pending cross-language-sdk consensus on sendability/writeability. # - # assert message.amqp_message.properties.subject == b"subject" - # assert message.amqp_message.application_properties[b"application_properties"] == 1 - # assert message.amqp_message.annotations[b"annotations"] == 2 + # assert message.amqp_annotated_message.properties.subject == b"subject" + # assert message.amqp_annotated_message.application_properties[b"application_properties"] == 1 + # assert message.amqp_annotated_message.annotations[b"annotations"] == 2 # # delivery_annotations and footer disabled pending uamqp bug https://github.com/Azure/azure-uamqp-python/issues/169 - # #assert message.amqp_message.delivery_annotations[b"delivery_annotations"] == 3 - # assert message.amqp_message.header.priority == 5 - # #assert message.amqp_message.footer[b"footer"] == 6 + # #assert message.amqp_annotated_message.delivery_annotations[b"delivery_annotations"] == 3 + # assert message.amqp_annotated_message.header.priority == 5 + # #assert message.amqp_annotated_message.footer[b"footer"] == 6 @pytest.mark.liveTest @pytest.mark.live_test_only diff --git a/sdk/servicebus/azure-servicebus/tests/test_sb_client.py b/sdk/servicebus/azure-servicebus/tests/test_sb_client.py index f40a76e9d8e8..1acb94af9d88 100644 --- a/sdk/servicebus/azure-servicebus/tests/test_sb_client.py +++ b/sdk/servicebus/azure-servicebus/tests/test_sb_client.py @@ -135,13 +135,13 @@ def test_sb_client_incorrect_queue_conn_str(self, servicebus_queue_authorization # Now do the same but with direct connstr initialization. with pytest.raises(ServiceBusAuthenticationError): - with ServiceBusSender.from_connection_string( + with ServiceBusSender._from_connection_string( servicebus_queue_authorization_rule_connection_string, queue_name=wrong_queue.name, ) as sender: sender.send_messages(ServiceBusMessage("test")) - with ServiceBusSender.from_connection_string( + with ServiceBusSender._from_connection_string( servicebus_queue_authorization_rule_connection_string, queue_name=servicebus_queue.name, ) as sender: diff --git a/sdk/servicebus/azure-servicebus/tests/test_sessions.py b/sdk/servicebus/azure-servicebus/tests/test_sessions.py index 2d2828a665fa..071a779a688e 100644 --- a/sdk/servicebus/azure-servicebus/tests/test_sessions.py +++ b/sdk/servicebus/azure-servicebus/tests/test_sessions.py @@ -65,12 +65,11 @@ def test_session_by_session_client_conn_str_receive_handler_peeklock(self, servi for i in range(3): message = ServiceBusMessage("Handler message no. {}".format(i)) message.session_id = session_id - message.properties = {'key': 'value'} - message.label = 'label' + message.application_properties = {'key': 'value'} + message.subject = 'label' message.content_type = 'application/text' message.correlation_id = 'cid' message.message_id = str(i) - message.via_partition_key = 'via_pk' message.to = 'to' message.reply_to = 'reply_to' message.reply_to_session_id = 'reply_to_session_id' @@ -84,13 +83,12 @@ def test_session_by_session_client_conn_str_receive_handler_peeklock(self, servi for message in receiver: print_message(_logger, message) assert message.delivery_count == 0 - assert message.properties - assert message.properties[b'key'] == b'value' - assert message.label == 'label' + assert message.application_properties + assert message.application_properties[b'key'] == b'value' + assert message.subject == 'label' assert message.content_type == 'application/text' assert message.correlation_id == 'cid' assert message.partition_key == session_id - assert message.via_partition_key == 'via_pk' assert message.to == 'to' assert message.reply_to == 'reply_to' assert message.sequence_number @@ -347,8 +345,8 @@ def test_session_by_servicebus_client_iter_messages_with_retrieve_deferred_recei print_message(_logger, message) assert message.dead_letter_reason == 'Testing reason' assert message.dead_letter_error_description == 'Testing description' - assert message.properties[b'DeadLetterReason'] == b'Testing reason' - assert message.properties[b'DeadLetterErrorDescription'] == b'Testing description' + assert message.application_properties[b'DeadLetterReason'] == b'Testing reason' + assert message.application_properties[b'DeadLetterErrorDescription'] == b'Testing description' receiver.complete_message(message) assert count == 10 @@ -461,8 +459,8 @@ def test_session_by_servicebus_client_receive_with_retrieve_deadletter(self, ser receiver.complete_message(message) assert message.dead_letter_reason == 'Testing reason' assert message.dead_letter_error_description == 'Testing description' - assert message.properties[b'DeadLetterReason'] == b'Testing reason' - assert message.properties[b'DeadLetterErrorDescription'] == b'Testing description' + assert message.application_properties[b'DeadLetterReason'] == b'Testing reason' + assert message.application_properties[b'DeadLetterErrorDescription'] == b'Testing description' count += 1 assert count == 10 diff --git a/sdk/servicebus/azure-servicebus/tests/test_subscriptions.py b/sdk/servicebus/azure-servicebus/tests/test_subscriptions.py index 0a6ecc63ff57..6cc946ff68a9 100644 --- a/sdk/servicebus/azure-servicebus/tests/test_subscriptions.py +++ b/sdk/servicebus/azure-servicebus/tests/test_subscriptions.py @@ -173,6 +173,6 @@ def test_subscription_by_servicebus_client_receive_batch_with_deadletter(self, s count += 1 assert message.dead_letter_reason == 'Testing reason' assert message.dead_letter_error_description == 'Testing description' - assert message.properties[b'DeadLetterReason'] == b'Testing reason' - assert message.properties[b'DeadLetterErrorDescription'] == b'Testing description' + assert message.application_properties[b'DeadLetterReason'] == b'Testing reason' + assert message.application_properties[b'DeadLetterErrorDescription'] == b'Testing description' assert count == 10 diff --git a/sdk/servicebus/azure-servicebus/tests/utilities.py b/sdk/servicebus/azure-servicebus/tests/utilities.py index 649848297bef..cd0ca6cb958b 100644 --- a/sdk/servicebus/azure-servicebus/tests/utilities.py +++ b/sdk/servicebus/azure-servicebus/tests/utilities.py @@ -35,7 +35,7 @@ def print_message(_logger, message): _logger.debug("Sequence number: {}".format(message.sequence_number)) _logger.debug("Enqueue Sequence numger: {}".format(message.enqueued_sequence_number)) _logger.debug("Partition Key: {}".format(message.partition_key)) - _logger.debug("Properties: {}".format(message.properties)) + _logger.debug("Application Properties: {}".format(message.application_properties)) _logger.debug("Delivery count: {}".format(message.delivery_count)) try: _logger.debug("Locked until: {}".format(message.locked_until_utc))