Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to make LocalDistributedEventBus able to use outbox/inbox patterns #21965

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

NunoGamaVieira
Copy link

@NunoGamaVieira NunoGamaVieira commented Jan 21, 2025

Description

The existing LocalDistributedEventBus doesn't make use of the outbox/inbox patterns if these are enabled.
With these changes, we make it possible to use those mechanisms while still publishing through LocalEventBus.

Resolve #22053

Checklist

  • I fully tested it as developer / designer and created unit / integration tests
  • I documented it (or no need to document or I will create a separate documentation issue)

@CLAassistant
Copy link

CLAassistant commented Jan 21, 2025

CLA assistant check
All committers have signed the CLA.

@maliming maliming requested review from maliming and hikalkan January 23, 2025 09:25
@maliming maliming added this to the 9.3-preview milestone Jan 23, 2025
@maliming
Copy link
Member

@hikalkan Do you think the LocalDistributedEventBus should support outbox/inbox?

@hikalkan
Copy link
Member

@maliming Yes, it should support. This is necessary for modular monolith applications where each module has a separate physical database.

@maliming maliming self-assigned this Jan 27, 2025
@maliming maliming modified the milestones: 9.3-preview, 9.1-final Jan 28, 2025
@maliming maliming marked this pull request as draft January 29, 2025 05:53
@maliming
Copy link
Member

maliming commented Jan 29, 2025

I will add a test app to make sure it works as expected

@maliming maliming marked this pull request as ready for review February 3, 2025 01:18
@maliming
Copy link
Member

maliming commented Feb 3, 2025

hi @hikalkan

If this is not a design, you can merge this PR, I have tested it in a real application.


You have return true if an event has been added to one of Outbox, but Inbox has a different logic. It will try to add events to all Inboxes.

I changed the code to add an event to all inboxes/outboxes. 95bd271

await eventOutbox.EnqueueAsync(outgoingEventInfo);
return true;

foreach (var outboxConfig in AbpDistributedEventBusOptions.Outboxes.Values.OrderBy(x => x.Selector is null))
{
if (outboxConfig.Selector == null || outboxConfig.Selector(eventType))
{
var eventOutbox = (IEventOutbox)unitOfWork.ServiceProvider.GetRequiredService(outboxConfig.ImplementationType);
var eventName = EventNameAttribute.GetNameOrDefault(eventType);
await OnAddToOutboxAsync(eventName, eventType, eventData);
var outgoingEventInfo = new OutgoingEventInfo(
GuidGenerator.Create(),
eventName,
Serialize(eventData),
Clock.Now
);
var correlationId = CorrelationIdProvider.Get();
if (correlationId != null)
{
outgoingEventInfo.SetCorrelationId(correlationId);
}
await eventOutbox.EnqueueAsync(outgoingEventInfo);
return true;

using (var scope = ServiceScopeFactory.CreateScope())
{
foreach (var inboxConfig in AbpDistributedEventBusOptions.Inboxes.Values.OrderBy(x => x.EventSelector is null))
{
if (inboxConfig.EventSelector == null || inboxConfig.EventSelector(eventType))
{
var eventInbox =
(IEventInbox)scope.ServiceProvider.GetRequiredService(inboxConfig.ImplementationType);
if (!messageId.IsNullOrEmpty())
{
if (await eventInbox.ExistsByMessageIdAsync(messageId!))
{
continue;
}
}
var incomingEventInfo = new IncomingEventInfo(
GuidGenerator.Create(),
messageId!,
eventName,
Serialize(eventData),
Clock.Now
);
incomingEventInfo.SetCorrelationId(correlationId!);
await eventInbox.EnqueueAsync(incomingEventInfo);
}
}
}
return true;

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

Attention: Patch coverage is 44.73684% with 63 lines in your changes missing coverage. Please review.

Project coverage is 52.02%. Comparing base (0a1c637) to head (fea2a39).
Report is 3 commits behind head on dev.

Files with missing lines Patch % Lines
...p/EventBus/Distributed/LocalDistributedEventBus.cs 43.01% 51 Missing and 2 partials ⚠️
...bp/EventBus/Distributed/DistributedEventBusBase.cs 50.00% 4 Missing ⚠️
....EventBus/Volo/Abp/EventBus/Local/LocalEventBus.cs 0.00% 3 Missing ⚠️
...ntBus/Volo/Abp/EventBus/Local/NullLocalEventBus.cs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #21965      +/-   ##
==========================================
+ Coverage   52.01%   52.02%   +0.01%     
==========================================
  Files        3183     3184       +1     
  Lines      102337   102380      +43     
  Branches     7773     7780       +7     
==========================================
+ Hits        53227    53260      +33     
- Misses      47462    47469       +7     
- Partials     1648     1651       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants