Skip to content

fix(ServiceBus): Read max-message-batch-size vendor property for batch sizing#57941

Merged
EldertGrootenboer merged 5 commits into
Azure:mainfrom
EldertGrootenboer:fix/servicebus-batch-size-vendor-property
Apr 8, 2026
Merged

fix(ServiceBus): Read max-message-batch-size vendor property for batch sizing#57941
EldertGrootenboer merged 5 commits into
Azure:mainfrom
EldertGrootenboer:fix/servicebus-batch-size-vendor-property

Conversation

@EldertGrootenboer
Copy link
Copy Markdown
Contributor

Problem

On Premium large-message Service Bus entities, the AMQP link's max-message-size can be up to 100 MB, but the broker enforces a 1 MB limit for batch sends. The .NET SDK hardcodes DefaultMaxBatchSize = 1048576 (1 MB) and MaxMessageCount = 4500 as a workaround — correct behavior but not reading from the link property.

Related: #44914, #44916, azure-service-bus#708

Fix

Read the com.microsoft:max-message-batch-size vendor property from the AMQP sender link attach frame, which the service now correctly reports as 256 KB (Standard) / 1 MB (Premium) independent of entity-level max-message-size. Fall back to DefaultMaxBatchSize (1 MB) when the vendor property is absent. Remove the 4,500 message count cap — the service has no count limit, and the byte size limit naturally caps count.

Changes

  • AmqpClientConstants.cs: Add MaxMessageBatchSizeName constant for com.microsoft:max-message-batch-size
  • AmqpSender.cs: Read vendor property via link.Settings.Properties.TryGetValue<long>(); remove MaxMessageCount property and 4,500 default
  • AmqpSenderTests.cs: 4 new tests: vendor property on Premium large-message (100 MB entity → 1 MB batch), Standard tier (256 KB), absent fallback, count cap removal (>4500 messages fit in byte-limited batch)

Resolves #44914. Related to #44916.

Cross-SDK alignment

SDK Status
Java PR #48214
JS Separate PR (same branch pattern)
Go Separate PR (same branch pattern)
Python Separate PR (same branch pattern)

…h sizing

- Read com.microsoft:max-message-batch-size from AMQP sender link
  properties to correctly limit batch size on Premium large-message
  entities where max-message-size can be up to 100 MB but the batch
  limit is 1 MB
- Remove hardcoded 4,500 message count cap; the service has no
  count limit and the byte size limit naturally caps message count
- Falls back to DefaultMaxBatchSize (1 MB) when vendor property
  is absent (backward compatibility)
- Add unit tests for vendor property scenarios (Premium large-message,
  Standard tier, absent fallback, count cap removal)
Copy link
Copy Markdown
Contributor

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 updates the Service Bus AMQP sender to size message batches using the broker-provided vendor link property (com.microsoft:max-message-batch-size) rather than relying on the link’s max-message-size, addressing incorrect batching behavior for Premium large-message entities.

Changes:

  • Add a new AMQP vendor property constant for com.microsoft:max-message-batch-size.
  • Update AmqpSender to read the vendor batch-size limit from the sender link attach properties (with fallback to the existing 1 MB default) and remove the previous 4,500 message count cap.
  • Add unit tests covering vendor-property-based batch sizing, fallback behavior, and count-cap removal.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpClientConstants.cs Adds the AMQP symbol constant for the vendor batch-size link property.
sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpSender.cs Uses the vendor link property to set MaxBatchSize and removes the default message-count cap wiring.
sdk/servicebus/Azure.Messaging.ServiceBus/tests/Amqp/AmqpSenderTests.cs Adds tests for vendor-property sizing behavior and verifies removal of the message-count limit.

Comment thread sdk/servicebus/Azure.Messaging.ServiceBus/tests/Amqp/AmqpSenderTests.cs Outdated
- Use 10 MB batch limit in count cap test to ensure all 6000 messages
  fit regardless of AMQP envelope overhead variations
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpSender.cs Outdated
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Copy link
Copy Markdown
Contributor

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

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

Comment thread sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpSender.cs Outdated
Comment thread sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpSender.cs Outdated
Comment thread sdk/servicebus/Azure.Messaging.ServiceBus/tests/Amqp/AmqpSenderTests.cs Outdated
…ge test helper

- Trim verbose vendor property comment to avoid staleness
- Use link.Settings?.Properties.TryGetValue instead of explicit null check
- Merge SetLinkLimitsWithBatchSize into SetLinkLimits with optional maxBatchSize param
Copy link
Copy Markdown
Contributor

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

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

Comment thread sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpSender.cs
Copy link
Copy Markdown
Contributor

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

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

Comment thread sdk/servicebus/Azure.Messaging.ServiceBus/src/Amqp/AmqpSender.cs
Comment thread sdk/servicebus/Azure.Messaging.ServiceBus/tests/Amqp/AmqpSenderTests.cs Outdated
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@EldertGrootenboer EldertGrootenboer merged commit 0a0a774 into Azure:main Apr 8, 2026
28 checks passed
haiyuazhang pushed a commit that referenced this pull request Apr 14, 2026
…h sizing (#57941)

* fix(ServiceBus): Read max-message-batch-size vendor property for batch sizing

- Read com.microsoft:max-message-batch-size from AMQP sender link
  properties to correctly limit batch size on Premium large-message
  entities where max-message-size can be up to 100 MB but the batch
  limit is 1 MB
- Remove hardcoded 4,500 message count cap; the service has no
  count limit and the byte size limit naturally caps message count
- Falls back to DefaultMaxBatchSize (1 MB) when vendor property
  is absent (backward compatibility)
- Add unit tests for vendor property scenarios (Premium large-message,
  Standard tier, absent fallback, count cap removal)

* fix: address Copilot review - robust count cap test

- Use 10 MB batch limit in count cap test to ensure all 6000 messages
  fit regardless of AMQP envelope overhead variations

* fix: address jsquire review - simplify comment, null-conditional, merge test helper

- Trim verbose vendor property comment to avoid staleness
- Use link.Settings?.Properties.TryGetValue instead of explicit null check
- Merge SetLinkLimitsWithBatchSize into SetLinkLimits with optional maxBatchSize param

* docs: add CHANGELOG entry for batch size vendor property fix

---------

Co-authored-by: Eldert Grootenboer (from Dev Box) <egrootenboer@microsoft.com>
@EldertGrootenboer EldertGrootenboer deleted the fix/servicebus-batch-size-vendor-property branch May 8, 2026 03:50
EldertGrootenboer added a commit to Azure/azure-sdk-for-js that referenced this pull request May 8, 2026
…ch sizing (#38049)

## Problem

On Premium large-message Service Bus entities, the AMQP link's
`max-message-size` can be up to 100 MB, but the broker enforces a 1 MB
limit for batch sends. The JS SDK reads `max-message-size` (via
`this.link.maxMessageSize`) for batch sizing, so `createMessageBatch()`
accepts batches up to 100 MB that the broker then rejects.

Related:
[azure-service-bus#708](Azure/azure-service-bus#708)

## Fix

Read the `com.microsoft:max-message-batch-size` vendor property from the
AMQP sender link attach frame, which correctly reports 256 KB (Standard)
/ 1 MB (Premium) independent of entity-level `max-message-size`. When
the vendor property is absent (older service versions), fall back to
`Math.min(maxMessageSize, defaultMaxBatchSize)` where
`defaultMaxBatchSize` is 1 MB — this caps the batch size to prevent
using the raw `max-message-size` (which can be up to 100 MB on Premium
large-message entities).

### Changes

- **`messageSender.ts`**: Add `defaultMaxBatchSize` constant (1 MB); add
`getMaxBatchSizeFromLink()` that reads the vendor property from
`this.link.properties`, falling back to `Math.min(maxMessageSize,
defaultMaxBatchSize)`; update `createBatch()` to use the new method
- **`messageSender.spec.ts`**: Unit tests for vendor property present,
absent (with 1 MB cap), undefined properties, wrong type, zero value,
user override, rejection of oversized `maxSizeInBytes`, Standard tier

### Cross-SDK alignment

| SDK | Status |
|-----|--------|
| .NET | [PR
#57941](Azure/azure-sdk-for-net#57941) |
| Java | [PR
#48214](Azure/azure-sdk-for-java#48214) |
| Go | [PR #26530](Azure/azure-sdk-for-go#26530)
|
| Python | [PR
#46197](Azure/azure-sdk-for-python#46197) |

---------

Co-authored-by: Eldert Grootenboer (from Dev Box) <egrootenboer@microsoft.com>
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.

[Service Bus] Apply link metadata for the maximum message batch size

4 participants