Flexbase
Search…
INSERT : PostBus Subscriber
BasicCRUD Insert Query with Bridge
Now we will look at the subscriber, will go back to our solution. If you notice, we have the Handler executed and the Handler raises the event called CustomerAdded.
So if we go to the endpoint, we have our subscriber configured to listen to the Handler End point. Whatever events are being fired from the Handler will be executed by the subscriber and the subscriber has the bus gamma default subscriber. This is configured in the common messages That all the subscriber interfaces will be available in the messages, which is used commonly across all the other Solutions.
1
public class SendEmailToCustomerOnAddedBusGammaSubscriber : IAmBusGammaSubscriber<CustomerAdded>
2
{
3
ILogger<SendEmailToCustomerOnAddedBusGammaSubscriber> _logger;
4
ISendEmailToCustomerOnAdded _subscriber;
5
/// <summary>
6
///
7
/// </summary>
8
/// <param name="logger"></param>
9
public SendEmailToCustomerOnAddedBusGammaSubscriber(ILogger<SendEmailToCustomerOnAddedBusGammaSubscriber> logger, ISendEmailToCustomerOnAdded subscriber)
10
{
11
_logger = logger;
12
_subscriber = subscriber;
13
}
14
15
/// <summary>
16
///
17
/// </summary>
18
/// <param name="message"></param>
19
/// <param name="context"></param>
20
/// <returns></returns>
21
public async Task Handle(CustomerAdded message, IMessageHandlerContext context)
22
{
23
await _subscriber.Execute(message, new BusGammaHandlerContextBridge(context, message.HostContextInfo));
24
}
25
}
Copied!
Bus gamma subscriber receives the event and the subscriber's execute method is called where the way it is written and it is like this because again we are decoupling from the bus and the logic relies with the subscriber file, this can be swapped with any other bus implementation.
1
public async Task Execute(CustomerAdded @event, IFlexServiceBusContext serviceBusContext)
2
{
3
//TODO: Write your business logic here:
4
5
_logger.LogInformation(@event.Id);
6
7
//TODO: Specify your condition to raise event here...
8
//TODO: Set the value of OnRaiseEventCondition according to your business logic
9
10
OnRaiseEventCondition = CONDITION_ONSUCCESS;
11
12
RaiseEventCondition raiseEventCondition = new RaiseEventCondition(OnRaiseEventCondition);
13
await raiseEventCondition.RaiseEvent<SendEmailToCustomerOnAdded>(this, new object[] { serviceBusContext });
14
}
Copied!
1
private async Task OnSuccess(IFlexServiceBusContextBridge serviceBusContext)
2
{
3
4
EmailSentToCustomerOnAdded @event = new EmailSentToCustomerOnAdded
5
{
6
HostContextInfo=serviceBusContext.HostContextInfo,
7
8
//Add your properties here
9
};
10
11
await serviceBusContext.Publish(@event);
12
}
Copied!
Last modified 1yr ago
Copy link