I’m trying to figure out the best way to handle calling an external system, i’m not sure if this code below is the best way to do it, because for example in case the database of projection is deleted how can i replay the events
@Aggregate
public class HtsAggregate {
@AggregateIdentifier
private String externalId;
private String userId;
private String phoneNumWallet;
private String countryIndicator;
private String branchId;
public HtsAggregate() {
}
@CommandHandler
public HtsAggregate(CreateCreditCardCommand cmd) {
apply(new CreditCardCreatedEvent(cmd.externalId, cmd.userId, cmd.phoneNumWallet,
cmd.countryIndicator, cmd.branchId));
}
@EventSourcingHandler
protected void on(CreditCardCreatedEvent evt) {
this.externalId = evt.externalId;
this.userId = evt.userId;
this.phoneNumWallet = evt.phoneNumWallet;
this.countryIndicator = evt.countryIndicator;
this.branchId = evt.branchId;
}
}
@EventHandler
public void on(CreditCardCreatedEvent event) {
try {
final Object response = webClient.post().uri(url).bodyValue(event).retrieve().bodyToMono(Object.class).block();
repoDone.save(response);
} catch(Exception e) {
repoError.save(e.getMessage());
}
}