Event Handler not called

38 views
Skip to first unread message

wc...@masonite.com

unread,
Nov 30, 2016, 11:39:46 AM11/30/16
to Axon Framework Users
Hi,

I try to figure out why @EventHandler method outside Aggregate not being called while the @CommandHandler and @EventSourcingHandler are called successfully. How do I find out the event handler is registered in the event bus?

I am using Axon-RC1

Here is the command

@Data
@AllArgsConstructor
public class CreateAccountCommand {

@TargetAggregateIdentifier
private String accountId;

private String firstName;

private String lastName;


}


Here is the code for Aggregate:


@NoArgsConstructor
@Aggregate
@Data
public class Account {

@AggregateIdentifier
private String accountId;

private String firstName;

private String lastName;

@CommandHandler
public Account(CreateAccountCommand command) {
AccountCreatedEvent event = new AccountCreatedEvent(command.getAccountId(), command.getFirstName(), command.getLastName());
apply(event);
}

@EventSourcingHandler
protected void on(AccountCreatedEvent event) {
this.accountId = event.getAccountId();
this.firstName = event.getFirstName();
this.lastName = event.getLastName();

}
}



Here is my independent EventHandler class which is not called 

@RestController
public class AccountEventHandler {

AccountRepository accountRepository;
private final Logger log = LoggerFactory.getLogger(this.getClass());

public AccountEventHandler(AccountRepository accountRepository) {
this.accountRepository = accountRepository;
}


@EventHandler
public void on(AccountCreatedEvent event) {

AccountEntity accountEntity = new AccountEntity();
try {
accountEntity.setFirstName(event.getFirstName());
accountEntity.setLastName(event.getLastName());

accountRepository.save(accountEntity);

}catch (Exception ex) {
log.info(ex.getStackTrace().toString());
}

}
}

Thanks in advance

Sammy




Allard Buijze

unread,
Nov 30, 2016, 5:31:54 PM11/30/16
to Axon Framework Users
Hi Sammy,

your classes seem alright. Can you share your configuration? Do you use the axon-spring-boot-starter module?

Cheers,

Allard

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages