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.


4 Answer(s)