CommandGateway send is not trigger the command handler in the aggregate

1,504 views
Skip to first unread message

Richard Valdivieso

unread,
Dec 1, 2016, 4:32:46 PM12/1/16
to Axon Framework Users
I am having the following issue:

I have the following Aggregate:















public class Account {

@AggregateIdentifier
private String accountEventId;

private String firstName;

private String lastName;

private String email;



@CommandHandler
public Account(CreateAccountCommand command) {

AccountCreatedEvent event = new AccountCreatedEvent(command.getAccountEventId(), command.getFirstName(), command.getLastName(),
command.getEmail());
apply(event);
}

@CommandHandler
public void handle(UpdateAccountCommand command) {
AccountUpdatedPasswordTokenEvent event = new AccountUpdatedPasswordTokenEvent(command.getAccountEventId(), command.getPasswordResetToken(), command.getEmail());
apply(event);
}

@EventSourcingHandler
protected void on(AccountEvent event) {
this.accountEventId = event.getAccountEventId();
this.firstName = event.getFirstName();
this.lastName = event.getLastName();
this.email = event.getEmail();
}

@EventSourcingHandler
protected void on(AccountUpdatedPasswordTokenEvent event) {
this.accountEventId = event.getAccountEventId();
this.passwordResetToken = event.getPasswordResetToken();
this.email = event.getEmail();
}


}

I have the following kotlin classes


class CreateAccountCommand(@TargetAggregateIdentifier val accountEventId: String, val firstName: String,
val lastName: String, val email: String)

class UpdateAccountCommand (@TargetAggregateIdentifier val accountEventId: String, val firstName: String, val lastName: String, val email: String)


//Events
abstract class AccountEvent (val accountEventId: String, val firstName: String, val lastName: String, val email: String)

class AccountCreatedEvent(
accountEventId: String, firstName: String, lastName: String, email: String) :
AccountEvent(accountEventId, firstName, lastName, email)

class AccountUpdatedPasswordTokenEvent (val accountEventId: String, val passwordResetToken: String, val email: String)

In one point I am calling the send method of the Gateway like so:

  commandGateway.send(updateAccountCommand);


However, it does not reach the above command handler and also it does not trigger any error. As extra note I have a CreateAccountCommand and that one works. Am I missing something?

Richard

Allard Buijze

unread,
Dec 1, 2016, 4:49:08 PM12/1/16
to Axon Framework Users
Hi Richard,

I don't see anything obviously wrong. However, the fact that you don't see any errors doesn't mean such, since you don't pass in a callback, or do anything with the result of the gateway.send() method. The latter returns a CompletableFuture that carries the result. If the command failed, it would be in that result, and not in the logs.

Try using
commandGateway.send(command, LoggingCallback.INSTANCE)
instead. That should give you some logging that may help debug the error.

Cheers,

Allard

PS. The next version (RC2) will always log an error, albeit in minimal form.

--
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.

Richard Valdivieso

unread,
Dec 1, 2016, 9:21:44 PM12/1/16
to Axon Framework Users
Thanks Allard. I did what you say and now I got the following:

org.axonframework.commandhandling.model.AggregateNotFoundException: The aggregate was not found in the event store
2016-12-01 21:18:28.838 at org.axonframework.eventsourcing.EventSourcingRepository.doLoadWithLock(EventSourcingRepository.java:172)
at org.axonframework.eventsourcing.EventSourcingRepository.doLoadWithLock(EventSourcingRepository.java:39)
 INFO at org.axonframework.commandhandling.model.LockingRepository.doLoad(LockingRepository.java:129)
  at org.axonframework.commandhandling.model.LockingRepository.doLoad(LockingRepository.java:48)
6973 at org.axonframework.commandhandling.model.AbstractRepository.lambda$load$9(AbstractRepository.java:100)
at java.util.HashMap.computeIfAbsent(HashMap.java:1118)
  at org.axonframework.commandhandling.model.AbstractRepository.load(AbstractRepository.java:99)
--- at org.axonframework.commandhandling.AggregateAnnotationCommandHandler$AggregateCommandHandler.handle(AggregateAnnotationCommandHandler.java:192)
  at org.axonframework.commandhandling.AggregateAnnotationCommandHandler$AggregateCommandHandler.handle(AggregateAnnotationCommandHandler.java:186)
[nio-9998-exec-5] at org.axonframework.commandhandling.AggregateAnnotationCommandHandler.handle(AggregateAnnotationCommandHandler.java:148)
  at org.axonframework.commandhandling.AggregateAnnotationCommandHandler.handle(AggregateAnnotationCommandHandler.java:40)
c.n.accountservice.util.LoggingCallback at org.axonframework.messaging.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:57)
  at org.axonframework.messaging.unitofwork.DefaultUnitOfWork.executeWithResult(DefaultUnitOfWork.java:69)
at org.axonframework.commandhandling.SimpleCommandBus.doDispatch(SimpleCommandBus.java:145)
at org.axonframework.commandhandling.SimpleCommandBus.doDispatch(SimpleCommandBus.java:118)
at org.axonframework.commandhandling.SimpleCommandBus.dispatch(SimpleCommandBus.java:88)
: at org.axonframework.commandhandling.gateway.AbstractCommandGateway.send(AbstractCommandGateway.java:79)
 Command failed: UpdateAccountCommand -> AggregateNotFoundException
at org.axonframework.commandhandling.gateway.DefaultCommandGateway.send(DefaultCommandGateway.java:90)
at com.norgay.accountservice.service.AccountService.sendEmail(AccountService.java:138)
at com.norgay.accountservice.controller.AccountController.sendPasswordResetEmail(AccountController.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:220)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:105)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:89)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:107)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

Is there something that I am missing?

Thanks in advance

Richard

Richard Valdivieso

unread,
Dec 2, 2016, 8:15:00 AM12/2/16
to Axon Framework Users
Hi Allard,

I found the solution. It turns out we were not sending the existing Aggregate Id from the database, but generating a different one when attempting to fetch and update the record from the database. The problem was fixed and now we are firing the command correctly. 

Thank you, 

Richard
Reply all
Reply to author
Forward
0 new messages