Skip to content

Conversation

@maggsimo
Copy link

@maggsimo maggsimo commented Jan 12, 2026

feat: test queue and topic send using CreateMessageBatchAsync to avoi…

What this PR does / why we need it:
This PR introduce a way to test topic or queue using send grant to avoid that we force to provide management roles to implement the hc

Which issue(s) this PR fixes:
Please reference the issue this PR will close: #555
Please reference the issue this PR will close: #727

Special notes for your reviewer:
i'm leveraging CreateMessageBatchAsync since it does a network call to the Service Bus to fetch entity properties, such as MaxMessageSize.

Therefore, it verifies:

  • The entity exists
  • User connection and permissions allow access (send link)
  • User know the maximum allowed message size

It does NOT send messages, so no DLQ or queue pollution occurs

Potentially could be possible also to use a probe message to verify that the configuration of the message is valid.

Sample

  .AddAzureServiceBusQueue(publisherQueueConnectionString,
                          publisherQueueName,
                          configure: (op) =>
                          {
                              op.UsePeekMode = false;
                              op.UseCreateMessageBatchAsyncMode = true;
                          },
                          name: "test queue publish lib",
                          timeout: TimeSpan.FromSeconds(20))
  .AddAzureServiceBusTopic(publisherTopicConnectionString,
                          publisherTopicName,
                          configure: (op) =>
                          {
                              op.UseCreateMessageBatchAsyncMode = true;
                          },
                          name: "test topic publish lib",
                          timeout: TimeSpan.FromSeconds(20))

Does this PR introduce a user-facing change?:
Yes.
For the queue, since queue can be consumed in both SEND and LISTEN mode, to mirror existing implementation i've set UseCreateMessageBatchAsyncMode = true as default.
This implies that if you want to test only LISTEN, is mandatory to explicitely set configure in AddAzureServiceBusQueue call, to maintein the same behaviour of current implementation, like:

  .AddAzureServiceBusQueue(subscriberQueueConnectionString,
                          subscriberQueueName,
                          configure: (op) =>
                          {
                              op.UsePeekMode = true;
                              op.UseCreateMessageBatchAsyncMode = false;
                          },
                          name: "test queue subscriber",
                          timeout: TimeSpan.FromSeconds(20))

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Unit tests passing
  • End-to-end tests passing
  • Extended the documentation
  • Provided sample for the feature

Simone Maggiani (MSC Technology Italia) added 2 commits January 12, 2026 10:07
@maggsimo
Copy link
Author

@dotnet-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant