Trigger azure function when new event is commited #860
-
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Hi, for this kind of tasks, I use Subscribers. Here is the docs: https://docs.geteventflow.net/Subscribers.html. |
Beta Was this translation helpful? Give feedback.
-
@ProH4Ck thanks and inside that subscriber I make a http call to azure function for example ? |
Beta Was this translation helpful? Give feedback.
-
Yes! This is a sample subscriber from my latest project used to send emails: public class ReservationConfirmedEventSubscriber
: ISubscribeSynchronousTo<ReservationAggregate, ReservationId, ReservationCreatedEvent>
{
private readonly IQueryProcessor _queryProcessor;
private readonly IEmailService _emailService;
private readonly IUserInfoService _userInfoService;
public ReservationConfirmedEventSubscriber(IQueryProcessor queryProcessor, IEmailService emailService,
IUserInfoService userInfoService)
{
_queryProcessor = queryProcessor;
_emailService = emailService;
_userInfoService = userInfoService;
}
public async Task HandleAsync(
IDomainEvent<ReservationAggregate, ReservationId, ReservationCreatedEvent> domainEvent,
CancellationToken cancellationToken)
{
// get show
ShowReadModel showData =
await _queryProcessor.ProcessAsync(
new ReadModelByIdQuery<ShowReadModel>(domainEvent.AggregateEvent.Show),
cancellationToken);
// get movie
MovieReadModel movieData =
await _queryProcessor.ProcessAsync(new ReadModelByIdQuery<MovieReadModel>(showData.MovieId),
cancellationToken);
// get user info
User userData = await _userInfoService.GetUserInfo(domainEvent.AggregateEvent.UserId);
string mail = await _userInfoService.GetUserMail(domainEvent.AggregateEvent.UserId);
var emailData = new ReservationConfirmationData();
<< OMITTED CODE >>
await _emailService.SendReservationConfirmationEmail(mail, emailData);
}
} |
Beta Was this translation helpful? Give feedback.
-
cool ! thanks man |
Beta Was this translation helpful? Give feedback.
Yes! This is a sample subscriber from my latest project used to send emails: