Last active
October 12, 2016 14:01
-
-
Save lc-nyovchev/fc5d8c373a4f21770f9c5b4b2f2870b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@Import(CassandraTestConfig.class) | |
public class AxonTestContext { | |
@Bean | |
public EventStorageEngine eventStorageEngine(Cluster cluster){ | |
return new CassandraEventStorageEngine(cluster, new XStreamSerializer()); | |
} | |
@Bean | |
public EventStore eventStore(EventStorageEngine eventStorageEngine){ | |
return new AbstractEventStore(eventStorageEngine) { | |
@Override | |
public TrackingEventStream streamEvents(TrackingToken trackingToken) { | |
return null; | |
} | |
}; | |
} | |
@Bean | |
public EventSourcingRepository<TestAggregate> aggregateEventSourcingRepository(EventStore eventStore){ | |
return new EventSourcingRepository<>(TestAggregate.class, eventStore); | |
} | |
@Bean | |
public CommandBus commandBus(){ | |
CommandBus commandBus = new AsynchronousCommandBus(); | |
AnnotationCommandHandlerAdapter annotationCommandHandlerAdapter = new AnnotationCommandHandlerAdapter( | |
new TestAggregate() | |
); | |
commandBus.subscribe(TestAggregateCreateCommand.class.getName(), annotationCommandHandlerAdapter); | |
commandBus.subscribe(TestAggregateNameChangeCommand.class.getName(), annotationCommandHandlerAdapter); | |
return commandBus; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NoArgsConstructor | |
public class TestAggregate { | |
@AggregateIdentifier private UUID someAggregateId; | |
private String name; | |
@CommandHandler | |
public TestAggregate(TestAggregateCreateCommand testAggregateCreateCommand){ | |
apply(new TestAggregateCreatedEvent(testAggregateCreateCommand.getTestAggregateId())); | |
} | |
@CommandHandler | |
public void setName(TestAggregateNameChangeCommand testAggregateNameChangeCommand){ | |
apply(new TestAggregateNameChangedEvent( | |
testAggregateNameChangeCommand.getTestAggregateId(), | |
testAggregateNameChangeCommand.getName() | |
)); | |
} | |
@EventSourcingHandler | |
public void on(TestAggregateCreatedEvent createdEvent){ | |
this.someAggregateId = createdEvent.getSomeAggregateId(); | |
} | |
@EventSourcingHandler | |
public void on(TestAggregateNameChangedEvent testAggregateNameChangedEvent){ | |
this.name = testAggregateNameChangedEvent.getName(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out the method: AnnotationCommandHandlerAdapter.subscribe(). It will automatically subscribe itself as the handler for all known Command types.