Skip to content

Conversation

kashifkhan
Copy link
Member

This PR addresses an issue where batched messages that were sent to a session & partition enabled queue could not be sent. The error was happening because we not setting the application properties and session id on the batch for the messages. Singular messages would work just fine

We followed the pattern in .NET AMQP here https://github.com/Azure/azure-sdk-for-net/blob/a1af2cbe8117b706ce2c99ac04c084eea1e24334/sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpMessageConverter.cs#L102

code to repro the issue

from azure.servicebus import ServiceBusClient, ServiceBusMessage,TransportType

import logging

import uuid


connection_str = ""

queue_name = "sessionqueue"


logging.basicConfig(level=logging.DEBUG)

servicebus_client = ServiceBusClient.from_connection_string(conn_str=connection_str, logging_enable=True)


sender = servicebus_client.get_queue_sender(queue_name)

messages = [ServiceBusMessage("Message 1", session_id="mySessionId", message_id=uuid.uuid4(), partition_key="mySessionId"), ServiceBusMessage("Message 2", session_id="mySessionId", message_id=uuid.uuid4(), partition_key="mySessionId")]


with sender:

    sender.send_messages(messages)


print("Message sent successfully")

@kashifkhan
Copy link
Member Author

/azp run python - servicebus - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kashifkhan
Copy link
Member Author

/azp run python - servicebus - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@skarri-microsoft skarri-microsoft marked this pull request as ready for review August 27, 2025 23:54
@Copilot Copilot AI review requested due to automatic review settings August 27, 2025 23:54
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where batched messages with session IDs and partition keys could not be sent to Service Bus queues. The problem occurred because the batch envelope wasn't properly configured with the necessary properties and annotations from the individual messages.

Key changes:

  • Added utility functions to set message properties and annotations on AMQP messages
  • Modified the batch message creation to populate the batch envelope with session ID, message ID, and partition key from the first message
  • Followed the .NET SDK pattern for handling batched message properties

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/utils.py Added utility functions set_message_properties and set_message_annotations for configuring AMQP message properties
sdk/servicebus/azure-servicebus/azure/servicebus/_common/message.py Modified batch message logic to populate envelope properties from the first message when creating batches

@kashifkhan
Copy link
Member Author

/azp run python - servicebus - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kashifkhan
Copy link
Member Author

/azp run python - servicebus - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kashifkhan
Copy link
Member Author

/azp run python - servicebus - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kashifkhan
Copy link
Member Author

/azp run python - servicebus - tests

@kashifkhan
Copy link
Member Author

/azp run python - eventhub - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

1 similar comment
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kashifkhan
Copy link
Member Author

/azp run python - servicebus - tests

@kashifkhan
Copy link
Member Author

/azp run python - eventhub - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

1 similar comment
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kashifkhan kashifkhan enabled auto-merge (squash) September 15, 2025 16:10
@kashifkhan
Copy link
Member Author

/check-enforcer override

@kashifkhan kashifkhan merged commit 5dd225d into Azure:main Sep 18, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants