Message to a partitioned entity with duplicate detection enabled must have either PartitionKey or MessageId
See original GitHub issue- Package Name: azure-servicebus
- Package Version: 7.4.0
- Operating System: docker image python:3.8-buster
- Python Version: 3.8.12
Describe the bug
I create Standart SB Queue with enabled partitions and duplicate detection.
And for cases, when I send messages in the batch mode, I receive an error Message to a partitioned entity with duplicate detection enabled must have either PartitionKey or MessageId
. But when I send the same message one by one - it works ok.
To Reproduce Steps to reproduce the behavior:
- run this code
connectio_string = 'Endpoint=sb://MY_WORKER_HERE.servicebus.windows.net/;SharedAccessKeyName=ingest_rule;SharedAccessKey=MY_KEY_HERE;EntityPath=MY_QUEUE_NAME_HERE'
uamqp_logger = logging.getLogger('uamqp')
uamqp_logger.setLevel(logging.DEBUG)
_connection_info = parse_connection_string(connectio_string)
_client = ServiceBusClient.from_connection_string(conn_str=connectio_string, logging_enable=True)
with _client.get_queue_sender(_connection_info.entity_path) as sender:
service_bus_message = sender.create_message_batch()
service_bus_message.add_message(ServiceBusMessage('msg1', message_id=uuid.uuid4().hex), )
service_bus_message.add_message(ServiceBusMessage('msg2', message_id=uuid.uuid4().hex), )
sender.send_messages(service_bus_message)
and the result will be:
ClientMessageError Traceback (most recent call last)
/usr/local/lib/python3.8/site-packages/azure/servicebus/_base_handler.py in _do_retryable_operation(self, operation, timeout, **kwargs)
394 kwargs["timeout"] = remaining_timeout
--> 395 return operation(**kwargs)
396 except StopIteration:
/usr/local/lib/python3.8/site-packages/azure/servicebus/_servicebus_sender.py in _send(self, message, timeout, last_exception)
261 self._set_msg_timeout(timeout, last_exception)
--> 262 self._handler.send_message(message.message)
263 finally: # reset the timeout of the handler back to the default value
/usr/local/lib/python3.8/site-packages/uamqp/client.py in send_message(self, messages, close_on_done)
743 details['failed_messages'][failed_message] = exception
--> 744 raise errors.ClientMessageError(exception, info=details)
745 finally:
ClientMessageError: ErrorCodes.NotAllowed: Message to a partitioned entity with duplicate detection enabled must have either PartitionKey or MessageId set TrackingId:dbaf8438-ee39-4057-ad37-47371b8749cc_G23, SystemTracker:client-link425450073, Timestamp:2021-12-01T10:19:43
During handling of the above exception, another exception occurred:
ServiceBusError Traceback (most recent call last)
<ipython-input-64-489aa3b7946b> in <module>
6 service_bus_message.add_message(ServiceBusMessage('msg1', message_id=uuid.uuid4()), )
7 service_bus_message.add_message(ServiceBusMessage('msg2', message_id=uuid.uuid4()), )
----> 8 sender.send_messages(service_bus_message)
/usr/local/lib/python3.8/site-packages/azure/servicebus/_servicebus_sender.py in send_messages(self, message, **kwargs)
415 self._add_span_request_attributes(send_span)
416
--> 417 self._do_retryable_operation(
418 self._send,
419 message=obj_message,
/usr/local/lib/python3.8/site-packages/azure/servicebus/_base_handler.py in _do_retryable_operation(self, operation, timeout, **kwargs)
397 raise
398 except Exception as exception: # pylint: disable=broad-except
--> 399 last_exception = self._handle_exception(exception)
400 if require_last_exception:
401 kwargs["last_exception"] = last_exception
/usr/local/lib/python3.8/site-packages/azure/servicebus/_base_handler.py in _handle_exception(self, exception)
344 self._close_handler()
345 if not error._retryable:
--> 346 raise error
347
348 return error
ServiceBusError: Message to a partitioned entity with duplicate detection enabled must have either PartitionKey or MessageId set TrackingId:dbaf8438-ee39-4057-ad37-47371b8749cc_G23, SystemTracker:client-link425450073, Timestamp:2021-12-01T10:19:43 Error condition: ErrorCodes.NotAllowed.
Expected behavior Batch sending work as expected for queues, where duplicate detection and partition enabled. Potentially - here is an issue, that batching clear individual broker properties(as message ID) so it should not happen.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Duplicate detection - Service Bus Messaging - Microsoft Learn
This article explains how you can detect duplicates in Azure Service Bus messages. The duplicate message can be ignored and dropped.
Read more >How does Azure Service Bus identify a duplicate message?
Enabling duplicate detection helps keep track of the application-controlled MessageId of all messages sent into a queue or topic during a ...
Read more >Service Bus - duplicate detection for partitioned messaging ...
Enabling Duplicate detection helps to ensure that a duplicate message, which has the same message Id cannot be sent into a messaging entity...
Read more >Partitioning and de-duplication - ASP.NET Community Blogs
A queue is created with native de-duplication enabled. · It's partitioned. · A message with a calculated MessageId is sent to the queue....
Read more >Partition Enabled Service Bus Queues and Topics
If a Service Bus Queue or Topic is a duplicate detection enabled entity, then the message-id of the message will be treated as...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@flying-pi Thanks for your feedback, we’ll investigate asap.
@yunhaoling is the above a supported scenario?