Hi Allard,
Let me be as detailed as I can:
- I’m running on a MacBook Pro with the latest version of OS X.
- I have the JDK 8 102 installed (latest)
- I have Maven v3.3.9 installed
- I am developing with IntelliJ 2016.2.2
- I did a pull now (2016-8-27) and it fails with the same error I reported yesterday. See attached Maven log for details.
Migration path:
I am using @AnnotationDriven and all my command handler methods are annotated with @CommandHandler. Currently my command handler methods are not on the aggregate but in a separate class marked @Component.
-
I removed all “extends AbstractAnnotatedAggregateRoot” from my aggregates
-
I statically imported this in my aggregates
import static org.axonframework.commandhandling.model.AggregateLifecycle.apply;
import static org.axonframework.commandhandling.model.AggregateLifecycle.markDeleted;
-
I updated the import statements for:
import org.axonframework.eventsourcing.annotation.AggregateIdentifier;
import org.axonframework.eventsourcing.annotation.EventSourcingHandler;
import org.axonframework.commandhandling.annotation.CommandHandler;
import org.axonframework.eventstore.mongo.MongoTemplate;
to
import org.axonframework.commandhandling.model.AggregateIdentifier;
import org.axonframework.eventsourcing.EventSourcingHandler;
import org.axonframework.commandhandling.CommandHandler;
import org.axonframework.mongo.eventsourcing.eventstore.MongoTemplate;
- I updated my event sourcing repositories:
@Bean(name = “attractionAggregateRepository”)
public EventSourcingRepository attractionAggregateRepository() {
EventSourcingRepository repository = new EventSourcingRepository<>(AttractionAggregate.class, eventStore, lockManager);
repository.setEventBus(eventBus);
return repository;
}
to
@Bean(name = “attractionAggregateRepository”)
public Repository attractionAggregateRepository() {
return new EventSourcingRepository<>(AttractionAggregate.class, eventStore);
}
- Updated my Spring bean config:
@Bean(name = “commandBus”, destroyMethod = “shutdown”)
public AsynchronousCommandBus commandBus() {
AsynchronousCommandBus commandBus = new AsynchronousCommandBus();
List interceptors = new ArrayList<>(1);
interceptors.add(new BeanValidationInterceptor());
commandBus.setDispatchInterceptors(interceptors);
return commandBus;
}
@Bean(name = “commandGateway”)
public CommandGateway commandGateway() {
CommandGateway commandGateway = null;
CommandGatewayFactoryBean factory = new CommandGatewayFactoryBean();
factory.setCommandBus(commandBus());
// create a retry scheduler to re-run the command that failed with an exception
// I put this in place to contend with concurrency exceptions [BH]
ScheduledExecutorService ses = Executors.newScheduledThreadPool(1);
factory.setRetryScheduler(new IntervalRetryScheduler(ses, 500, 2));
try {
factory.afterPropertiesSet();
commandGateway = (CommandGateway) factory.getObject();
} catch (Exception e) {
throw new RuntimeException(e);
}
return commandGateway;
}
@Bean(name = “eventBus”)
public EventBus eventBus() {
EventBus eventBus = new SimpleEventBus();
return eventBus;
}
@Bean(name = “lockManager”)
public LockManager lockManager() {
PessimisticLockManager lockManager = new PessimisticLockManager(); // default Axon lock manager
return lockManager;
}
@Bean(name = “axonMongoTemplate”)
public AxonMongoTemplate axonMongoTemplate() {
return new AxonMongoTemplate(mongoDbFactory);
}
@Bean(name = “axonSagaMongoTemplate”)
public AxonSagaMongoTemplate mongoSagaTemplate() {
return new AxonSagaMongoTemplate(mongoDbFactory);
}
@Bean(name = “eventStore”)
public MongoEventStore eventStore() {
XStreamSerializer xStreamSerializer = new XStreamSerializer(xStream);
return new MongoEventStore(xStreamSerializer, axonMongoTemplate());
}
@Bean(name = “snapshotter”)
public Snapshotter snapshotter() {
SpringAggregateSnapshotter sas = new SpringAggregateSnapshotter();
sas.setEventStore(eventStore());
sas.setExecutor(taskExecutor);
return sas;
}
to
@Bean(name = “commandBus”)
public CommandBus commandBus() {
SimpleCommandBus commandBus = new SimpleCommandBus();
return commandBus;
}
@Bean(name = “commandGateway”)
public CommandGateway commandGateway() {
return new DefaultCommandGateway(commandBus());
}
@Bean(name = “eventBus”)
public EventBus eventBus() {
return new SimpleEventBus();
}
@Bean(name = “axonMongoTemplate”)
public AxonMongoTemplate axonMongoTemplate() {
return new AxonMongoTemplate(mongoDbFactory);
}
@Bean(name = “axonSagaMongoTemplate”)
public AxonSagaMongoTemplate mongoSagaTemplate() {
return new AxonSagaMongoTemplate(mongoDbFactory);
}
@Bean(name = “storageStrategy”)
public StorageStrategy storageStrategy() {
return new DocumentPerEventStorageStrategy();
}
@Bean(name = “xStreamSerializer”)
public XStreamSerializer xStreamSerializer() {
return new XStreamSerializer(xStream);
}
@Bean(name = “eventStore”)
public EventStore eventStore() {
return new EmbeddedEventStore(
new MongoEventStorageEngine(axonMongoTemplate(), storageStrategy())
);
}
- There was no documentation or examples on the updated version of FutureCallback so I removed the few places I had been using it.
- I updated all my command handler method to use the new callback lambda syntax:
RateAggregate aggregate = new RateAggregate(command.getRateIdentifier(), command.getRate());
rateAggregateRepository.add(aggregate);
return command.getRateIdentifier();
to
return repository.newInstance(() ->
new RateAggregate(
command.getRateIdentifier(),
command.getRate()
)
).invoke(Function.identity());
Some takeaways from this:
- I don’t know how to inject my custom xStreamSerializer anymore
- FutureCallback needs a good a example
- I can’t figure out how to configure SpringAggregateSnapshotter anymore
This is when everything started compiling again. I started the app but when my commands started dispatching they failed with errors stating that no Command Handlers could be found to catch those events. At that point, I started looking at the latest code to see if there were any clues as to whether the command handler instantiation had changed. That’s when I see the AxonSpringConfiguration class under quickstart and how repositories are instantiated differently. How you have @CommandHandler directly on the aggregate methods. How you instantiate the AggregateAnnotationCommandHandler. And the eventProcessor:
@Bean
public Repository repository(ParameterResolverFactory parameterResolverFactory) {
return new EventSourcingRepository<>(new GenericAggregateFactory<>(ToDoItem.class), eventStore(), parameterResolverFactory,
NoSnapshotTriggerDefinition.INSTANCE);
}
@Bean
public AggregateAnnotationCommandHandler aggregateAnnotationCommandHandler(ParameterResolverFactory parameterResolverFactory, Repository repository) {
AggregateAnnotationCommandHandler ch = new AggregateAnnotationCommandHandler<>(ToDoItem.class, repository, new AnnotationCommandTargetResolver(), parameterResolverFactory);
ch.subscribe(commandBus());
return ch;
}
@Bean
public ToDoEventHandler eventHandler() {
return new ToDoEventHandler();
}
@Bean
public SubscribingEventProcessor eventProcessor() {
SubscribingEventProcessor eventProcessor = new SubscribingEventProcessor(“eventProcessor”, new SimpleEventHandlerInvoker(eventHandler()), eventStore());
eventProcessor.start();
return eventProcessor;
}
At this point I couldn’t explore any further because there are classes here that don’t exist in M3 and I was failing to start the app. The last error I had before I gave up was:
Caused by: java.lang.NoSuchMethodError: com.thoughtworks.xstream.XStream.addImmutableType(Ljava/lang/Class;Z)V
at org.axonframework.serialization.AbstractXStreamSerializer.(AbstractXStreamSerializer.java:129) ~[axon-core-3.0-M3.jar:3.0-M3]
at org.axonframework.serialization.AbstractXStreamSerializer.(AbstractXStreamSerializer.java:103) ~[axon-core-3.0-M3.jar:3.0-M3]
at org.axonframework.serialization.AbstractXStreamSerializer.(AbstractXStreamSerializer.java:78) ~[axon-core-3.0-M3.jar:3.0-M3]
at org.axonframework.serialization.AbstractXStreamSerializer.(AbstractXStreamSerializer.java:67) ~[axon-core-3.0-M3.jar:3.0-M3]
at org.axonframework.serialization.xml.XStreamSerializer.(XStreamSerializer.java:49) ~[axon-core-3.0-M3.jar:3.0-M3]
at org.axonframework.eventsourcing.eventstore.AbstractEventStorageEngine.(AbstractEventStorageEngine.java:37) ~[axon-core-3.0-M3.jar:3.0-M3]
at org.axonframework.eventsourcing.eventstore.BatchingEventStorageEngine.(BatchingEventStorageEngine.java:40) ~[axon-core-3.0-M3.jar:3.0-M3]
at org.axonframework.eventsourcing.eventstore.mongo.MongoEventStorageEngine.(MongoEventStorageEngine.java:66) ~[axon-mongo-3.0-M3.jar:3.0-M3]
at com.traveliko.platform.persistence.mongo.config.AxonCQRSConfig.eventStore(AxonCQRSConfig.java:129) ~[traveliko-persistence-mongo-0.0.4-SNAPSHOT.jar:
maven_log_error.txt (6.71 KB)