Skip to content

feat: bulk dispatch to support circuit breaking#3688

Merged
iancooper merged 6 commits into
BrighterCommand:masterfrom
mikechrisfreeman:feature/bulk-dispatch-to-use-iamcircuitbreaker
Aug 5, 2025
Merged

feat: bulk dispatch to support circuit breaking#3688
iancooper merged 6 commits into
BrighterCommand:masterfrom
mikechrisfreeman:feature/bulk-dispatch-to-use-iamcircuitbreaker

Conversation

@mikechrisfreeman

Copy link
Copy Markdown
Contributor

Currently only AzureServiceBusMessageProducer and InMemoryProduce implement IAmABulkMessageProducerAsync.

The current behaviour batches messages per topic and batch size then publishes the batch. If one batch fails an exception is raised and successful batches are not recorded. This therefore renders the MarkDispatchedAsync on successful messages useless.

Proposal is to bring the Bulk dispatch inline with the single dispatch implementation so that it can be wrapped in a retry and make use of IAmAnOutboxCircuitBreaker. A further benefit is individual batches can be retried as opposed to the entire list of messages and better control over implementation specific batching, asb can be quite funny.

@CLAassistant

CLAassistant commented Jul 31, 2025

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ mikechrisfreeman
✅ preardon
❌ Michael Freeman


Michael Freeman seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No application code in the PR — skipped Code Health checks.

See analysis details in CodeScene

Quality Gate Profile: Clean Code Collective
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

@mikechrisfreeman

Copy link
Copy Markdown
Contributor Author

@iancooper Added a proposal for circuit breaking to support bulk dispatching. I'll continue on the premise that this implementation is ok and make changes if we have differing opinions.

@iancooper iancooper added 2 - In Progress v10 .NET Pull requests that update .net code labels Jul 31, 2025

@iancooper iancooper left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, let's give it a shot. I've added to V10 as its a breaking change

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Gates Failed
Prevent hotspot decline (1 hotspot with Complex Method)
Enforce advisory code health rules (1 file with Complex Method)

Gates Passed
2 Quality Gates Passed

See analysis details in CodeScene

Reason for failure
Prevent hotspot decline Violations Code Health Impact
OutboxProducerMediator.cs 1 rule in this hotspot 7.16 → 6.97 Suppress
Enforce advisory code health rules Violations Code Health Impact
OutboxProducerMediator.cs 1 advisory rule 7.16 → 6.97 Suppress

Quality Gate Profile: Clean Code Collective
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

Comment on lines +824 to +827
private async Task BulkDispatchAsync(
IEnumerable<Message> posts,
RequestContext requestContext,
bool continueOnCapturedContext,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

❌ New issue: Complex Method
BulkDispatchAsync has a cyclomatic complexity of 10, threshold = 9

Suppress

@mikechrisfreeman mikechrisfreeman changed the title feat: add circuit breaking support to bulk disaptaching feat: bulk disaptach to support circuit breaking Aug 1, 2025

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Gates Failed
Prevent hotspot decline (1 hotspot with Complex Method)
Enforce advisory code health rules (1 file with Complex Method)

Gates Passed
2 Quality Gates Passed

See analysis details in CodeScene

Reason for failure
Prevent hotspot decline Violations Code Health Impact
OutboxProducerMediator.cs 1 rule in this hotspot 7.16 → 6.97 Suppress
Enforce advisory code health rules Violations Code Health Impact
OutboxProducerMediator.cs 1 advisory rule 7.16 → 6.97 Suppress

Quality Gate Profile: Clean Code Collective
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

/// Class MessageBatch
/// A collection of T <see cref="Message"/>
/// </summary>
public interface IAmAMessageBatch<out T> : IAmAMessageBatch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This abstraction allows for vendor specific batching to be implemented.. Currently our batching implementation is quite primitive - it fetches a batch of messages from the outbox and then attempt to batch them up, not considering whether it exceeds the vendor specific batching limitations.

We intend to add a further PR to fix this, for now its setting it up for that use case.

/// <exception cref="NotImplementedException"></exception>
public async Task SendAsync(IAmAMessageBatch batch, CancellationToken cancellationToken)
{
if (batch is not MessageBatch messageBatch)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

An azure specific message batch will be implemented later so that we can fine tune vendor specific constraints

@mikechrisfreeman mikechrisfreeman marked this pull request as ready for review August 1, 2025 10:54
@mikechrisfreeman mikechrisfreeman changed the title feat: bulk disaptach to support circuit breaking feat: bulk disptach to support circuit breaking Aug 1, 2025

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Gates Failed
Prevent hotspot decline (1 hotspot with Complex Method)
Enforce advisory code health rules (1 file with Complex Method)

Gates Passed
2 Quality Gates Passed

See analysis details in CodeScene

Reason for failure
Prevent hotspot decline Violations Code Health Impact
OutboxProducerMediator.cs 1 rule in this hotspot 7.16 → 6.97 Suppress
Enforce advisory code health rules Violations Code Health Impact
OutboxProducerMediator.cs 1 advisory rule 7.16 → 6.97 Suppress

Quality Gate Profile: Clean Code Collective
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

@preardon preardon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me, thanks for getting this in

@iancooper

Copy link
Copy Markdown
Member

@mikechrisfreeman Let us know when this is done, and I'll review

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Gates Failed
Prevent hotspot decline (1 hotspot with Complex Method)
Enforce advisory code health rules (1 file with Complex Method)

Gates Passed
2 Quality Gates Passed

See analysis details in CodeScene

Reason for failure
Prevent hotspot decline Violations Code Health Impact
OutboxProducerMediator.cs 1 rule in this hotspot 7.16 → 6.97 Suppress
Enforce advisory code health rules Violations Code Health Impact
OutboxProducerMediator.cs 1 advisory rule 7.16 → 6.97 Suppress

Quality Gate Profile: Clean Code Collective
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

@mikechrisfreeman

Copy link
Copy Markdown
Contributor Author

@mikechrisfreeman Let us know when this is done, and I'll review

Thanks @iancooper - Updated from main, resolved merge conflicts and ready for review.

I did notice that RocketMessageProducerFactory hasn't been updated to use the new IAmAMessageProducerFactory interface. Though i couldn't see any tests failing as a result. :/ Is that intentional?

@iancooper iancooper changed the title feat: bulk disptach to support circuit breaking feat: bulk dispatch to support circuit breaking Aug 5, 2025

@iancooper iancooper left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. Thanks for this @mikechrisfreeman

@iancooper iancooper merged commit 2946049 into BrighterCommand:master Aug 5, 2025
22 of 24 checks passed
DevJonny pushed a commit to DevJonny/Brighter that referenced this pull request Feb 28, 2026
* docs: update adr to include circuit breaking proposal for bulk dispatching

* feat: bulk dispatch to support circuit breaking

* fix: merge from main

---------

Co-authored-by: Michael Freeman <michael.freeman@flagstoneim.com>
Co-authored-by: Paul Reardon <Paul@ReardonTech.UK>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 - In Progress .NET Pull requests that update .net code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants