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

Question: How to publish an outbox-using distributed event that is compatible with the local event bus provider. #11100

Closed
gdlcf88 opened this issue Dec 28, 2021 · 6 comments
Assignees
Milestone

Comments

@gdlcf88
Copy link
Contributor

gdlcf88 commented Dec 28, 2021

Assume I am deleting a Book entity, and I want to send a notification email to the author if the deletion success.

After #10008, using the distributed event bus with outbox may be a good way since it ensures the UOW completion success and then publishes the domain events. When the IDistributedEventHandler<EntityDeletedEto<BookEto>> executes, the book entity must have been deleted.

But the question is, I noticed that the LocalDistributedEventBus does not handle the param useOutbox = true:

public Task PublishAsync<TEvent>(TEvent eventData, bool onUnitOfWorkComplete = true, bool useOutbox = true) where TEvent : class
{
return _localEventBus.PublishAsync(eventData, onUnitOfWorkComplete);
}
public Task PublishAsync(Type eventType, object eventData, bool onUnitOfWorkComplete = true, bool useOutbox = true)
{
return _localEventBus.PublishAsync(eventType, eventData, onUnitOfWorkComplete);
}

This presents a problem because it invokes the handlers as a local event before the UOW saves changes. The book has not been deleted or even will fail to delete.

If the above business is in a module, I don't know whether the app developers are using a real distributed event bus provider or not. So what should I do as a module developer? Or, is there any deviation in my understanding of this design?

Thanks.

:)

@gdlcf88 gdlcf88 changed the title Question: How to publish a distributed event that is compatible with the local event implementation. Question: How to publish a distributed event that is compatible with the local event bus provider. Dec 28, 2021
@gdlcf88 gdlcf88 changed the title Question: How to publish a distributed event that is compatible with the local event bus provider. Question: How to publish outbox-using distributed event that is compatible with the local event bus provider. Dec 28, 2021
@gdlcf88 gdlcf88 changed the title Question: How to publish outbox-using distributed event that is compatible with the local event bus provider. Question: How to publish an outbox-using distributed event that is compatible with the local event bus provider. Dec 28, 2021
@maliming
Copy link
Member

The local handler is run on the same UOW and will publish onUnitOfWorkComplete.

@gdlcf88
Copy link
Contributor Author

gdlcf88 commented Dec 29, 2021

Take the above example IDistributedEventHandler<EntityDeletedEto<BookEto>>.

image
image

If I send the email in this event handler (after ABP 5.0), I cannot ensure that the DB transaction commits success (since the app developers may use the LocalDistributedEventBus).

@gdlcf88
Copy link
Contributor Author

gdlcf88 commented Jan 6, 2022

Thank you @maliming for eae8d63.

The local distributed event bus has the same behavior now:
image

@jortygu
Copy link

jortygu commented Sep 25, 2022

@maliming commit:eae8d63 canceled? latest code don't contain commit content.

@maliming
Copy link
Member

hi @jortygu

#12385 (comment)

@jortygu
Copy link

jortygu commented Sep 30, 2022

@maliming is there any chance use outbox pattern in local event,i want to save data and event in same transaction and then trigger event by background worker (with retry system),i don't want to use real distributed event bus.

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

No branches or pull requests

3 participants