Skip to content

fix(azservicebus): Read max-message-batch-size vendor property for batch sizing#26530

Open
EldertGrootenboer wants to merge 5 commits intoAzure:mainfrom
EldertGrootenboer:fix/servicebus-batch-size-vendor-property
Open

fix(azservicebus): Read max-message-batch-size vendor property for batch sizing#26530
EldertGrootenboer wants to merge 5 commits intoAzure: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 Go SDK reads max-message-size (via MaxMessageSize()) for batch sizing in NewMessageBatch(), so batches up to 100 MB are accepted client-side and then rejected by the broker.

Related: 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. Fall back to MaxMessageSize() when the vendor property is absent.

Changes

  • sender.go: Read vendor property from Properties() in NewMessageBatch(); prefer it over MaxMessageSize()
  • amqpwrap.go: Add Properties() map[string]any to AMQPSender interface and AMQPSenderWrapper, matching the existing pattern on AMQPReceiver
  • Mock/test updates: Add Properties() to MockAMQPSender, MockAMQPSenderCloser, FakeAMQPSender, rpcTester; add default expectation in mock_data_sender.go
  • sender_unit_test.go: 3 new tests: vendor property overrides MaxMessageSize, fallback when absent, user MaxBytes override

Cross-SDK alignment

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

…tch 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
- Add Properties() method to AMQPSender interface, matching the
  existing pattern on AMQPReceiver
- Falls back to MaxMessageSize() when vendor property is absent
- Add unit tests for vendor property override, absent fallback,
  and user MaxBytes override
Copilot AI review requested due to automatic review settings April 8, 2026 16:09
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 fixes Sender.NewMessageBatch() sizing for Service Bus entities that support large message sizes by reading the AMQP sender link’s vendor property com.microsoft:max-message-batch-size (broker-enforced batch limit), falling back to MaxMessageSize() when absent.

Changes:

  • Prefer com.microsoft:max-message-batch-size over MaxMessageSize() when computing the default MessageBatch max size.
  • Extend the AMQPSender abstraction (and mocks/fakes) with a Properties() accessor to expose link attach properties.
  • Add unit tests covering vendor-property override, fallback behavior, and user MaxBytes override.

Reviewed changes

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

Show a summary per file
File Description
sdk/messaging/azservicebus/sender.go Use sender link properties to pick the correct batch size limit (vendor property preferred).
sdk/messaging/azservicebus/sender_unit_test.go Adds unit tests validating vendor-property behavior and user override.
sdk/messaging/azservicebus/internal/rpc_test.go Updates test RPC sender implementation to satisfy the expanded sender interface.
sdk/messaging/azservicebus/internal/mock/mock_amqp.go Regenerates/updates gomock types for the new Properties() method on senders.
sdk/messaging/azservicebus/internal/mock/emulation/mock_data_sender.go Adds default Properties() expectation for mocked senders.
sdk/messaging/azservicebus/internal/amqpwrap/mock_amqp_test.go Updates amqpwrap mocks to include Properties() for sender interfaces.
sdk/messaging/azservicebus/internal/amqpwrap/amqpwrap.go Adds Properties() to AMQPSender and forwards it in AMQPSenderWrapper.
sdk/messaging/azservicebus/internal/amqp_test_utils.go Updates FakeAMQPSender to implement Properties().

Comment thread sdk/messaging/azservicebus/sender.go
Comment thread sdk/messaging/azservicebus/sender_unit_test.go Outdated
Comment thread sdk/messaging/azservicebus/sender_unit_test.go Outdated
- Use type switch for numeric types (uint64, uint32, int64, int) instead
  of single uint64 assertion for vendor property value
- Rename tests to match existing TestSenderNewMessageBatch_ pattern
- Simplify test comments
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 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread sdk/messaging/azservicebus/sender_unit_test.go 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 8 out of 8 changed files in this pull request and generated no new comments.

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 9 out of 9 changed files in this pull request and generated no new comments.

@EldertGrootenboer
Copy link
Copy Markdown
Contributor Author

/azp run go - pullrequest

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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.

4 participants