/** * Configures an Aggregate using default settings. This means the aggregate is expected to be Event Sourced if an * Event Store present in the configuration. Otherwise, an explicit repository must be configured and the * {@link #configureAggregate(AggregateConfiguration)} must be used to register the aggregate. * * @param aggregate The aggregate type to register with the Configuration * @param <A> The type of aggregate * @return the current instance of the Configurer, for chaining purposes */ default <A> Configurer configureAggregate(Class<A> aggregate) { return configureAggregate(AggregateConfigurer.defaultConfiguration(aggregate)); }
configurer.configureAggregate(aggregateConf);
@Before public void setUp() { EventStore eventStore = spy(EmbeddedEventStore.builder() .storageEngine(new InMemoryEventStorageEngine()) .build()); Configurer configurer = DefaultConfigurer.defaultConfiguration(); configurer.eventProcessing() .usingSubscribingEventProcessors() .registerSaga(MySaga.class); configuration = configurer.configureEventStore(c -> eventStore) .configureAggregate(MyAggregate.class) .registerComponent(DeadlineManager.class, this::buildDeadlineManager) .start(); published = new CopyOnWriteArrayList<>(); configuration.eventBus().subscribe(msgs -> msgs.forEach(msg -> published.add(msg.getPayload()))); }
@Before public void setUp() { Configuration configuration = DefaultConfigurer.defaultConfiguration() .configureEmbeddedEventStore(c -> new InMemoryEventStorageEngine()) .configureAggregate(StubAggregate.class) .buildConfiguration(); configuration.start(); commandGateway = configuration.commandGateway(); }
@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))); }
/** * Configures an Aggregate using default settings. This means the aggregate is expected to be Event Sourced if an * Event Store present in the configuration. Otherwise, an explicit repository must be configured and the * {@link #configureAggregate(AggregateConfiguration)} must be used to register the aggregate. * * @param aggregate The aggregate type to register with the Configuration * @param <A> The type of aggregate * @return the current instance of the Configurer, for chaining purposes */ default <A> Configurer configureAggregate(Class<A> aggregate) { return configureAggregate(AggregateConfigurer.defaultConfiguration(aggregate)); }
/** * Configures an Aggregate using default settings. This means the aggregate is expected to be Event Sourced if an * Event Store present in the configuration. Otherwise, an explicit repository must be configured and the * {@link #configureAggregate(AggregateConfiguration)} must be used to register the aggregate. * * @param aggregate The aggregate type to register with the Configuration * @param <A> The type of aggregate * @return the current instance of the Configurer, for chaining purposes */ default <A> Configurer configureAggregate(Class<A> aggregate) { return configureAggregate(AggregateConfigurer.defaultConfiguration(aggregate)); }
.configureCommandBus(conf -> commandBus) .configureEventStore(conf -> eventStore) .configureAggregate(User.class) .configureAggregate(Company.class) .configureAggregate(Portfolio.class) .configureAggregate(Transaction.class) .configureAggregate(OrderBook.class) .registerModule(queryModelConfiguration) .registerModule(commandPublisherConfiguration)
@SneakyThrows public static void disabledMain(String[] args) { final Configuration configuration = DefaultConfigurer.defaultConfiguration() .configureAggregate(Entrance.class) .configureAggregate(Guest.class) .configureEmbeddedEventStore(c -> new InMemoryEventStorageEngine()) .configureCommandBus(c -> new AsynchronousCommandBus()) .buildConfiguration(); configuration.start(); final CommandBus commandBus = configuration.commandBus(); commandBus.dispatch(asCommandMessage(new RegisterEntranceCommand("main"))); commandBus.dispatch(asCommandMessage(new UnlockEntranceCommand("main"))); commandBus.dispatch(asCommandMessage(new UnregisterEntranceCommand("main")) ); TimeUnit.SECONDS.sleep(1L); } }
public static void main(String args[]){ Configuration config = DefaultConfigurer.defaultConfiguration() .configureAggregate(BankAccount.class) .configureEmbeddedEventStore(c -> new InMemoryEventStorageEngine()) .buildConfiguration(); config.start(); AccountId id = new AccountId(); config.commandGateway().send(new CreateAccountCommand(id, "MyAccount",1000)); config.commandGateway().send(new WithdrawMoneyCommand(id, 500)); config.commandGateway().send(new WithdrawMoneyCommand(id, 500)); /*config.commandBus().dispatch(asCommandMessage(new CreateAccountCommand(id, "MyAccount", 1000))); config.commandBus().dispatch(asCommandMessage(new WithdrawMoneyCommand(id, 500)));*/ }