dotnetcore / CAP

Distributed transaction solution in micro-service base on eventually consistency, also an eventbus with Outbox pattern
http://cap.dotnetcore.xyz
MIT License
6.61k stars 1.28k forks source link

Add GroupConcurrent option to support subscriber concurrent execution #1537

Closed yang-xiaodong closed 3 months ago

yang-xiaodong commented 3 months ago

Description:

CAP currently supports specifying the number of parallel execution threads for subscribers through the global parameter SubscriberParallelExecuteThreadCount. However, in some scenarios, some subscribers may need to execute serially while others may need to execute in parallel.

Subscribers need to provide a configuration to support the above behavior, while SubscriberParallelExecuteThreadCount still takes effect, which can be used to set the parallelism for subscribers who are not individually configured.

Issue(s) addressed:

Changes:

  1. Removal of UseDispatchingPerGroup

The UseDispatchingPerGroup configuration has been removed and is now the default behavior.

  1. Addition of GroupConcurrent parameter to [CapSubscribe]

A new GroupConcurrent parameter has been added to the [CapSubscribe] attribute for concurrent execution of subscriber methods. Now, the Group corresponds to consumers on independent threads.

Usage & Example:

[CapSubscribe("sample.rabbitmq.hello", Group = "A", GroupConcurrent = 3)]
public void Subscriber(DateTime dateTime)
{
}

By specifying the value of the GroupConcurrent parameter, you set the degree of parallel execution for the subscriber, meaning that the Subscriber method can have up to 3 degrees of parallelism.

Parallel execution requires independent threads, so if no Group parameter is specified, CAP will automatically create a Group using the Name value.

If you have multiple subscribers set to the same Group and have also set the GroupConcurrent value for these subscribers, only the value set by the first subscriber will take effect.

Affected components:

Checklist:

Reviewers: