Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Perform a multitude of config changes
Browse files Browse the repository at this point in the history
- Make all config class names singular
- Create caching repo's for all aggregates
- Set the repository for each aggregate through the annotation
- Add the two command publishing event handlers to a
'commandPublishingEventHandlers' processing group
- Add todo to CompanyConfig to move the snapshot trigger def bean to
another config file
- Remove all redundant declarations from the OrderConfig
- Change the buy/sell TradeSagas to be backed by a
TrackingEventProcessor
- Remove all redundant declarations from the UserConfig

#28
  • Loading branch information
smcvb committed Jun 1, 2018
1 parent 01b24fc commit 5e7b255
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 284 deletions.
Expand Up @@ -31,7 +31,7 @@
* This listener is used to create order book instances when we have created a new company</p>
*/
@Service
@ProcessingGroup("companiesEventProcessor")
@ProcessingGroup("commandPublishingEventHandlers")
public class CompanyOrderBookListener {

private static final Logger logger = LoggerFactory.getLogger(CompanyOrderBookListener.class);
Expand Down
Expand Up @@ -25,10 +25,11 @@
import org.springframework.context.annotation.Configuration;

@Configuration
public class CompaniesConfig {
public class CompanyConfig {

private static final int SNAPSHOT_THRESHOLD = 50;

//TODO #28 this should become an overall snapshot trigger definition i.o. in the company config
@Bean
public SnapshotTriggerDefinition snapshotTriggerDefinition(Snapshotter snapshotter) {
return new EventCountSnapshotTriggerDefinition(snapshotter, SNAPSHOT_THRESHOLD);
Expand Down
Expand Up @@ -40,7 +40,7 @@
* When buying items you need to reserve cash. Reservations need to be confirmed or cancelled. It is up to the user
* to confirm and cancel the right amounts. The Portfolio does not keep track of it.
*/
@Aggregate
@Aggregate(repository = "portfolioRepository")
public class Portfolio {

private static final long DEFAULT_ITEM_VALUE = 0L;
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.axonframework.samples.trader.orders.command;

import org.axonframework.commandhandling.gateway.CommandGateway;
import org.axonframework.config.ProcessingGroup;
import org.axonframework.eventhandling.EventHandler;
import org.axonframework.samples.trader.api.portfolio.CreatePortfolioCommand;
import org.axonframework.samples.trader.api.portfolio.PortfolioId;
Expand All @@ -30,6 +31,7 @@
* TODO #28 might benefit from a cleaner approach still. Think about this
*/
@Service
@ProcessingGroup("commandPublishingEventHandlers")
public class PortfolioManagementUserListener {

private static final Logger logger = LoggerFactory.getLogger(PortfolioManagementUserListener.class);
Expand Down
Expand Up @@ -25,7 +25,7 @@

import static org.axonframework.commandhandling.model.AggregateLifecycle.apply;

@Aggregate
@Aggregate(repository = "transactionRepository")
public class Transaction {

@AggregateIdentifier
Expand Down
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2010-2016. Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.axonframework.samples.trader.orders.config;

import org.axonframework.commandhandling.model.Repository;
import org.axonframework.common.caching.Cache;
import org.axonframework.config.SagaConfiguration;
import org.axonframework.eventsourcing.AggregateFactory;
import org.axonframework.eventsourcing.CachingEventSourcingRepository;
import org.axonframework.eventsourcing.SnapshotTriggerDefinition;
import org.axonframework.eventsourcing.eventstore.EventStore;
import org.axonframework.samples.trader.orders.command.BuyTradeManagerSaga;
import org.axonframework.samples.trader.orders.command.Portfolio;
import org.axonframework.samples.trader.orders.command.SellTradeManagerSaga;
import org.axonframework.samples.trader.orders.command.Transaction;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OrderConfig {

@Bean(name = "portfolioRepository")
public Repository<Portfolio> portfolioRepository(AggregateFactory<Portfolio> portfolioAggregateFactory,
EventStore eventStore,
Cache cache,
SnapshotTriggerDefinition snapshotTriggerDefinition) {
return new CachingEventSourcingRepository<>(
portfolioAggregateFactory,
eventStore,
cache,
snapshotTriggerDefinition);
}

@Bean(name = "transactionRepository")
public Repository<Transaction> transactionRepository(AggregateFactory<Transaction> transactionAggregateFactory,
EventStore eventStore,
Cache cache,
SnapshotTriggerDefinition snapshotTriggerDefinition) {
return new CachingEventSourcingRepository<>(
transactionAggregateFactory,
eventStore,
cache,
snapshotTriggerDefinition);
}


@Bean
public SagaConfiguration<BuyTradeManagerSaga> buyTradeSagaConfiguration() {
return SagaConfiguration.trackingSagaManager(BuyTradeManagerSaga.class);
}

@Bean
public SagaConfiguration<SellTradeManagerSaga> sellTradeSagaConfiguration() {
return SagaConfiguration.trackingSagaManager(SellTradeManagerSaga.class);
}
}

This file was deleted.

@@ -0,0 +1,39 @@
/*
* Copyright (c) 2010-2016. Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.axonframework.samples.trader.users.config;

import org.axonframework.commandhandling.model.Repository;
import org.axonframework.common.caching.Cache;
import org.axonframework.eventsourcing.AggregateFactory;
import org.axonframework.eventsourcing.CachingEventSourcingRepository;
import org.axonframework.eventsourcing.SnapshotTriggerDefinition;
import org.axonframework.eventsourcing.eventstore.EventStore;
import org.axonframework.samples.trader.users.command.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class UserConfig {

@Bean(name = "userRepository")
public Repository<User> userRepository(AggregateFactory<User> userAggregateFactory,
EventStore eventStore,
Cache cache,
SnapshotTriggerDefinition snapshotTriggerDefinition) {
return new CachingEventSourcingRepository<>(userAggregateFactory, eventStore, cache, snapshotTriggerDefinition);
}
}

0 comments on commit 5e7b255

Please sign in to comment.