Base solution for your next web application
Open Closed

Implementation of event bus #5923


User avatar
0
mirzanas created

Hello, I had my first experience with your implementation of the event bus. After some experiments, I am a bit confused about the way it works. Let me try to explain the situation:

Application service do database transaction and then triggers an event:

public class OfferAppService : ApplicationService { public IEventBus EventBus { get; set; }

<br> public OfferAppService() { EventBus = NullEventBus.Instance; }

public async Task AcceptOffer(AcceptOfferInput input) { //DATABASE TRANSACTION

await EventBus.TriggerAsync(new OfferAcceptedEvent { RequestId = input.RequestId }); or EventBus.Trigger(new OfferAcceptedEvent { RequestId = input.RequestId }); } }

<br> Two handlers waits for events and do other business.

public async Task HandleEventAsync(OfferAcceptedEvent eventData)

{ //DO STUFF await Task.Delay(5000); }

public async Task HandleEventAsync(OfferAcceptedEvent eventData) { //DO STUFF await Task.Delay(10000); }

After some tests I find out what AcceptOffer methods takes 15s to finish a execution. Should it be like this? I imagined what AcceptOffer should not wait until events will be processed.

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mirzanas

    ABP's implementation works like that. If you want to run non-blocking operations, you can try to use https://aspnetboilerplate.com/Pages/Documents/Background-Jobs-And-Workers

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    mmukkara created

    Hi @ismcagdas ,

    Do you have sample project on implementation of event bus?

    Thanks

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    aaron created
    Support Team

    There is only one implementation of Event Bus, in ABP: EventBus.cs

    If you mean Event Handler, there is: UserFriendCacheSyncronizer.cs

    If you mean Background Job, there is: UserCollectedDataPrepareJob.cs

    If you mean how to enqueue, there is: ProfileAppService.cs#L143

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    mmukkara created

    Thanks @aaron for the pointers.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)