Created
April 16, 2019 06:05
-
-
Save dadepo/9685f77eae07ac8a49188699b9068a56 to your computer and use it in GitHub Desktop.
This file contains 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
// Axon dependencies in pom.xml | |
<dependency> | |
<groupId>org.axonframework</groupId> | |
<artifactId>axon-eventsourcing</artifactId> | |
<version>${axon.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.axonframework</groupId> | |
<artifactId>axon-modelling</artifactId> | |
<version>${axon.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.axonframework</groupId> | |
<artifactId>axon-messaging</artifactId> | |
<version>${axon.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.axonframework</groupId> | |
<artifactId>axon-configuration</artifactId> | |
<version>${axon.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.axonframework</groupId> | |
<artifactId>axon-spring</artifactId> | |
<version>${axon.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.axonframework</groupId> | |
<artifactId>axon-test</artifactId> | |
<version>${axon.version}</version> | |
</dependency> | |
// context configuration | |
@Configuration | |
public class AppConfiguration { | |
@Bean | |
public DataSource dataSource() { | |
return DataSourceBuilder | |
.create() | |
.username("sa") | |
.password("") | |
.url("jdbc:h2:mem:exploredb") | |
.driverClassName("org.h2.Driver") | |
.build(); | |
} | |
@Bean | |
EventProcessingModule eventProcessingModule() { | |
return new EventProcessingModule(); | |
} | |
@Bean | |
EventStore embeddedEventStore() throws SQLException { | |
return EmbeddedEventStore.builder() | |
.storageEngine(new InMemoryEventStorageEngine()) | |
.build(); | |
} | |
@Bean | |
public SimpleCommandBus commandBus() { | |
return SimpleCommandBus.builder().build(); | |
} | |
@Bean | |
public DefaultCommandGateway commandGateway() { | |
return DefaultCommandGateway.builder() | |
.commandBus(commandBus()) | |
.build(); | |
} | |
@Bean | |
public Repository<Account> eventSourcingRepository() throws SQLException { | |
return EventSourcingRepository.builder(Account.class) | |
.eventStore(embeddedEventStore()) | |
.build(); | |
} | |
@Bean | |
public AggregateAnnotationCommandHandler aggregateAnnotationCommandHandler() throws SQLException { | |
AggregateAnnotationCommandHandler<Account> handler = AggregateAnnotationCommandHandler.<Account>builder() | |
.aggregateType(Account.class) | |
.repository(eventSourcingRepository()) | |
.build(); | |
for (String supportedCommand : handler.supportedCommandNames()) { | |
commandBus().subscribe(supportedCommand, handler); | |
} | |
return handler; | |
} | |
// main class | |
@SpringBootApplication | |
public class ExploringAxonApplication { | |
@Autowired | |
public void configure(EventProcessingConfigurer configurer) { | |
// some Event Handlers are annotated with @ProcessingGroup("normalProcessor") | |
configurer.registerTrackingEventProcessor("normalProcessor"); | |
} | |
public static void main(String[] args) { | |
SpringApplication.run(ExploringAxonApplication.class, args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment