/** * Registers a command handler bean with this configuration. The bean may be of any type. The actual command handler * methods will be detected based on the annotations present on the bean's methods. * <p> * The builder function receives the Configuration as input, and is expected to return a fully initialized instance * of the command handler bean. * * @param annotatedCommandHandlerBuilder The builder function of the Command Handler bean * @return the current instance of the Configurer, for chaining purposes */ default Configurer registerCommandHandler(Function<Configuration, Object> annotatedCommandHandlerBuilder) { return registerCommandHandler(0, annotatedCommandHandlerBuilder); }
@Test public void testDispatchCommand() { Configuration c = DefaultConfigurer.defaultConfiguration() .configureAggregate(TestAggregate.class) .registerCommandHandler(x -> new Handler()) .configureEmbeddedEventStore(x -> new InMemoryEventStorageEngine()) .buildConfiguration(); c.start(); CommandGateway gw = c.commandGateway(); gw.sendAndWait(new TestCommand()); }
@Test public void testStagedEventsLoadInCorrectOrder() { Configuration config = DefaultConfigurer.defaultConfiguration() .configureAggregate(TestAggregate.class) .registerCommandHandler(x -> new Handler()) .configureEmbeddedEventStore(x -> new InMemoryEventStorageEngine()) .registerComponent(List.class, c -> new CopyOnWriteArrayList()) .buildConfiguration(); config.start(); CommandGateway gw = config.commandGateway(); gw.sendAndWait(new Create("1")); gw.sendAndWait(new Test1()); gw.sendAndWait(new ShowItems("1", "from-eventstore")); config.shutdown(); assertEquals(asList("pre-rollback-first","pre-rollback-second", "post-rollback-first","post-rollback-second", "from-eventstore-first", "from-eventstore-second"), config.getComponent(List.class)); }
@Before public void setUp() { configuration = DefaultConfigurer.defaultConfiguration() .configureEmbeddedEventStore(c -> new InMemoryEventStorageEngine()) .configureAggregate(AggregateConfigurer.defaultConfiguration(MyAggregate.class) .configureAggregateFactory(c -> new AggregateFactory<MyAggregate>() { @Override public MyAggregate createAggregateRoot(String aggregateIdentifier, DomainEventMessage<?> firstEvent) { return new MyAggregate(aggregateIdentifier); } @Override public Class<MyAggregate> getAggregateType() { return MyAggregate.class; } })) .registerCommandHandler(c -> new MyCommandHandler(c.repository(MyAggregate.class), c.commandGateway())) .buildConfiguration(); configuration.start(); command = new MyCommand("outer", aggregateIdentifier, new MyCommand("middle", aggregateIdentifier, new MyCommand("inner", aggregateIdentifier))); }
/** * Registers a command handler bean with this configuration. The bean may be of any type. The actual command handler * methods will be detected based on the annotations present on the bean's methods. * <p> * The builder function receives the Configuration as input, and is expected to return a fully initialized instance * of the command handler bean. * * @param annotatedCommandHandlerBuilder The builder function of the Command Handler bean * @return the current instance of the Configurer, for chaining purposes */ default Configurer registerCommandHandler(Function<Configuration, Object> annotatedCommandHandlerBuilder) { return registerCommandHandler(0, annotatedCommandHandlerBuilder); }
/** * Registers a command handler bean with this configuration. The bean may be of any type. The actual command handler * methods will be detected based on the annotations present on the bean's methods. * <p> * The builder function receives the Configuration as input, and is expected to return a fully initialized instance * of the command handler bean. * * @param annotatedCommandHandlerBuilder The builder function of the Command Handler bean * @return the current instance of the Configurer, for chaining purposes */ default Configurer registerCommandHandler(Function<Configuration, Object> annotatedCommandHandlerBuilder) { return registerCommandHandler(0, annotatedCommandHandlerBuilder); }