@Override public EventBus eventBus() { return config.eventBus(); }
/** * Returns the Event Store in this Configuration, if it is defined. If no Event Store is defined (but an Event Bus * instead), this method throws an {@link AxonConfigurationException}. * * @return the Event Store defined in this Configuration */ default EventStore eventStore() { EventBus eventBus = eventBus(); if (!(eventBus instanceof EventStore)) { throw new AxonConfigurationException("A component is requesting an Event Store, however, there is none configured"); } return (EventStore) eventBus; }
@SuppressWarnings("unchecked") private EventProcessor defaultEventProcessor(String name, Configuration conf, EventHandlerInvoker eventHandlerInvoker) { if (conf.eventBus() instanceof StreamableMessageSource) { return trackingEventProcessor(name, eventHandlerInvoker, conf.getComponent( TrackingEventProcessorConfiguration.class, TrackingEventProcessorConfiguration::forSingleThreadedProcessing), (StreamableMessageSource) conf.eventBus()); } else { return subscribingEventProcessor(name, conf, eventHandlerInvoker, Configuration::eventBus); } }
/** * Registers a {@link org.axonframework.eventhandling.TrackingEventProcessor} with given {@code name} within this * Configurer. * * @param name a {@link String} specifying the name of the {@link org.axonframework.eventhandling.TrackingEventProcessor} * being registered * @return the current {@link EventProcessingConfigurer} instance, for fluent interfacing */ default EventProcessingConfigurer registerTrackingEventProcessor(String name) { return registerTrackingEventProcessor(name, c -> { EventBus eventBus = c.eventBus(); if (!(eventBus instanceof StreamableMessageSource)) { throw new AxonConfigurationException("Cannot create Tracking Event Processor with name '" + name + "'. " + "The available EventBus does not support tracking processors."); } //noinspection unchecked return (StreamableMessageSource) eventBus; }); }
.aggregateModel(configurer.metaModel.get()) .entityManagerProvider(entityManagerProvider) .eventBus(c.eventBus()) .repositoryProvider(c::repository) .build();
() -> beanFactory.getBean(EntityManagerProvider.class) )) .eventBus(c.eventBus()) .repositoryProvider(c::repository) .build());
/** * Creates a Configuration for an aggregate of given {@code aggregateType}, which is mapped to a relational * database using an EntityManager provided by given {@code entityManagerProvider}. The given {@code aggregateType} * is expected to be a proper JPA Entity. * * @param aggregateType The type of Aggregate to configure * @param entityManagerProvider The provider for Axon to retrieve the EntityManager from * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType, EntityManagerProvider entityManagerProvider) { AggregateConfigurer<A> configurer = new AggregateConfigurer<>(aggregateType); return configurer.configureRepository( c -> GenericJpaRepository.builder(aggregateType) .aggregateModel(configurer.metaModel.get()) .entityManagerProvider(entityManagerProvider) .eventBus(c.eventBus()) .repositoryProvider(c::repository) .build() ); }
@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()))); }
"Repository<" + aggregate.getSimpleName() + ">", c -> { state(c.eventBus() instanceof EventStore, () -> "Default configuration requires the use of event sourcing. Either configure an Event " + "Store to use, or configure a specific repository implementation for " +
/** * Returns the Event Store in this Configuration, if it is defined. If no Event Store is defined (but an Event Bus * instead), this method throws an {@link AxonConfigurationException}. * * @return the Event Store defined in this Configuration */ default EventStore eventStore() { EventBus eventBus = eventBus(); if (!(eventBus instanceof EventStore)) { throw new AxonConfigurationException("A component is requesting an Event Store, however, there is none configured"); } return (EventStore) eventBus; }
/** * Returns the Event Store in this Configuration, if it is defined. If no Event Store is defined (but an Event Bus * instead), this method throws an {@link AxonConfigurationException}. * * @return the Event Store defined in this Configuration */ default EventStore eventStore() { EventBus eventBus = eventBus(); if (!(eventBus instanceof EventStore)) { throw new AxonConfigurationException("A component is requesting an Event Store, however, there is none configured"); } return (EventStore) eventBus; }
@SuppressWarnings("unchecked") private EventProcessor defaultEventProcessor(String name, Configuration conf, EventHandlerInvoker eventHandlerInvoker) { if (conf.eventBus() instanceof StreamableMessageSource) { return trackingEventProcessor(name, eventHandlerInvoker, conf.getComponent( TrackingEventProcessorConfiguration.class, TrackingEventProcessorConfiguration::forSingleThreadedProcessing), (StreamableMessageSource) conf.eventBus()); } else { return subscribingEventProcessor(name, conf, eventHandlerInvoker, Configuration::eventBus); } }
/** * Registers a {@link org.axonframework.eventhandling.TrackingEventProcessor} with given {@code name} within this * Configurer. * * @param name a {@link String} specifying the name of the {@link org.axonframework.eventhandling.TrackingEventProcessor} * being registered * @return the current {@link EventProcessingConfigurer} instance, for fluent interfacing */ default EventProcessingConfigurer registerTrackingEventProcessor(String name) { return registerTrackingEventProcessor(name, c -> { EventBus eventBus = c.eventBus(); if (!(eventBus instanceof StreamableMessageSource)) { throw new AxonConfigurationException("Cannot create Tracking Event Processor with name '" + name + "'. " + "The available EventBus does not support tracking processors."); } //noinspection unchecked return (StreamableMessageSource) eventBus; }); }
/** * Creates a Configuration for an aggregate of given {@code aggregateType}, which is mapped to a relational * database using an EntityManager provided by given {@code entityManagerProvider}. The given {@code aggregateType} * is expected to be a proper JPA Entity. * * @param aggregateType The type of Aggregate to configure * @param entityManagerProvider The provider for Axon to retrieve the EntityManager from * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType, EntityManagerProvider entityManagerProvider) { AggregateConfigurer<A> configurer = new AggregateConfigurer<>(aggregateType); return configurer.configureRepository( c -> new GenericJpaRepository<>(entityManagerProvider, configurer.metaModel.get(), c.eventBus(), (RepositoryProvider) c::repository)); }
/** * Creates a Configuration for an aggregate of given {@code aggregateType}, which is mapped to a relational * database using an EntityManager obtained from the main configuration. The given {@code aggregateType} * is expected to be a proper JPA Entity. * <p> * The EntityManagerProvider is expected to have been registered with the Configurer (which would be the case when * using {@link DefaultConfigurer#jpaConfiguration(EntityManagerProvider)}. If that is not the case, consider using * {@link #jpaMappedConfiguration(Class, EntityManagerProvider)} instead. * * @param aggregateType The type of Aggregate to configure * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType) { AggregateConfigurer<A> configurer = new AggregateConfigurer<>(aggregateType); return configurer.configureRepository( c -> new GenericJpaRepository<>(c.getComponent(EntityManagerProvider.class, () -> { throw new AxonConfigurationException(format( "JPA has not been correctly configured for aggregate [%s]. Either provide an EntityManagerProvider, or use DefaultConfigurer.jpaConfiguration(...) to define one for the entire configuration.", aggregateType.getSimpleName())); }), configurer.metaModel.get(), c.eventBus(), (RepositoryProvider) c::repository)); }
.aggregateModel(configurer.metaModel.get()) .entityManagerProvider(entityManagerProvider) .eventBus(c.eventBus()) .repositoryProvider(c::repository) .build();
/** * Creates a Configuration for an aggregate of given {@code aggregateType}, which is mapped to a relational * database using an EntityManager provided by given {@code entityManagerProvider}. The given {@code aggregateType} * is expected to be a proper JPA Entity. * * @param aggregateType The type of Aggregate to configure * @param entityManagerProvider The provider for Axon to retrieve the EntityManager from * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType, EntityManagerProvider entityManagerProvider) { AggregateConfigurer<A> configurer = new AggregateConfigurer<>(aggregateType); return configurer.configureRepository( c -> GenericJpaRepository.builder(aggregateType) .aggregateModel(configurer.metaModel.get()) .entityManagerProvider(entityManagerProvider) .eventBus(c.eventBus()) .repositoryProvider(c::repository) .build() ); }
new Component<>(() -> parent, name("aggregateFactory"), c -> new GenericAggregateFactory<>(aggregate)); repository = new Component<>(() -> parent, "Repository<" + aggregate.getSimpleName() + ">", c -> { Assert.state(c.eventBus() instanceof EventStore, () -> "Default configuration requires the use of event sourcing. Either configure an Event " + "Store to use, or configure a specific repository implementation for " +
"Repository<" + aggregate.getSimpleName() + ">", c -> { state(c.eventBus() instanceof EventStore, () -> "Default configuration requires the use of event sourcing. Either configure an Event " + "Store to use, or configure a specific repository implementation for " +