static CommandBus commandBus = new SimpleCommandBus();
CommandGateway commandGateway = new DefaultCommandGateway(commandBus);
static EventStore eventStore = new EmbeddedEventStore(new InMemoryEventStorageEngine());
public static void main(String[] args) {
SpringApplication.run(DemandBiddingServiceApplication.class, args);
logger.info("Spring boot application started!");
EventSourcingRepository<BidAggregate> repository =
new EventSourcingRepository<>(BidAggregate.class, eventStore);
AggregateAnnotationCommandHandler<BidAggregate> messagesAggregateAggregateAnnotationCommandHandler =
new AggregateAnnotationCommandHandler<BidAggregate>(BidAggregate.class, repository);
messagesAggregateAggregateAnnotationCommandHandler.subscribe(commandBus);
final AnnotationEventListenerAdapter annotationEventListenerAdapter =
new AnnotationEventListenerAdapter(new BidsEventHandler());
eventStore.subscribe(eventMessages -> eventMessages.forEach(e -> {
try {
annotationEventListenerAdapter.handle(e);
} catch (Exception e1) {
throw new RuntimeException(e1);
}
}
));
I would like the same functionality, only with a JpaEventStore configured for PostgreSQL. I believe I may also require a JpaRepository, rather than an EventSourcingRepository.... I do not want to use the in memory store. Would you be able to show me how I can modify the selection above to achieve this? I have not been able to find any good examples online. I also read that the database is automatically populated, and I don't need to generate any tables -- is this the case?
I have made the following changes to my application.properties :
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url=jdbc:postgresql://localhost:5432/bidding_event_store
spring.datasource.username=user
spring.datasource.password=pass
# The SQL dialect makes Hibernate generate better SQL for the chosen database
##spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
#spring.jpa.hibernate.ddl-auto=validate
I am using the latest version of axon, 3.3.2
--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
@SpringBootApplication
@ComponentScan(basePackages = {"com.ge.energy.bids.demand.eventsourcing"})
@EntityScan(basePackages = {"com.ge.energy.bids.demand.eventsourcing",
"org.axonframework.eventsourcing.eventstore.jpa",
"org.axonframework.eventhandling.saga.repository.jpa",
"org.axonframework.eventhandling.tokenstore.jpa"})
@EnableJpaRepositories(basePackages = {"com.ge.energy.bids.demand.eventsourcing"})
public class DemandBiddingServiceApplication {
private static final Logger logger = LoggerFactory.getLogger(DemandBiddingServiceApplication.class);
static SimpleCommandBus commandBus = new SimpleCommandBus();
CommandGateway commandGateway = new DefaultCommandGateway(commandBus);
public static void main(String[] args) {
SpringApplication.run(DemandBiddingServiceApplication.class, args);
logger.info("Spring boot application started!");
}
// @Bean
// Repository<BidRepository> bidRepository(EntityManagerProvider entityManagerProvider, EventBus eventBus)
// {
// Repository<BidRepository> todoRepository = new GenericJpaRepository<BidRepository>(
// entityManagerProvider,
// BidRepository.class,
// eventBus
// );
// return todoRepository;
// }
@Bean
@Primary
public Serializer serializer() {
return new JacksonSerializer();
}
// @Bean
// public EventStorageEngine eventStorageEngine() throws Exception {
// return new JpaEventStorageEngine(entityManagerProvider(), springTransactionManager());
// }
//
// @Bean
// public EntityManagerProvider entityManagerProvider() {
// return new ContainerManagedEntityManagerProvider();
// }
//
// @Bean
// public SpringTransactionManager springTransactionManager() throws Exception {
// return new SpringTransactionManager(transactionManager());
// }
//
// @Bean
// public PlatformTransactionManager transactionManager() throws PropertyVetoException {
// return new JpaTransactionManager(entityManagerFactory);
// }
//
// @Bean
// public TransactionManagerFactoryBean transactionManagerFactoryBean() throws PropertyVetoException {
// TransactionManagerFactoryBean factoryBean = new TransactionManagerFactoryBean();
// factoryBean.setTransactionManager(transactionManager());
//
// return factoryBean;
// }
Here is my aggregate class:
@Aggregate
public class BidAggregate {
@AggregateIdentifier
private String mrid;
private String name;
private long fixedMw;
public BidAggregate()
{
System.out.println("--------------------------------------------------");
System.out.println("Loaded Aggregate");
System.out.println("--------------------------------------------------");
}
@CommandHandler
public BidAggregate(CreateBidCommand command)
{
apply(new BidCreatedEvent(command.getMrid(), command.getName(), command.getFixedMw()));
}
@EventHandler
public void on(BidCreatedEvent event)
{
this.mrid = event.getMrid();
this.name = event.getName();
this.fixedMw = event.getFixedMw();
}
@CommandHandler
public BidAggregate(AlterBidCommand command)
{
apply(new BidAlteredEvent(command.getMrid(), command.getName(), command.getFixedMw()));
}
@EventHandler
public void on(BidAlteredEvent event)
{
this.mrid = event.getMrid();
this.name = event.getName();
this.fixedMw = event.getFixedMw();
}
Here are my command classes:
@Value
public class AlterBidCommand {
@TargetAggregateIdentifier
private final String mrid;
private final String name;
private final long fixedMw;
public AlterBidCommand(String mrid, String name, long fixedMw) {
this.mrid = mrid;
this.name = name;
this.fixedMw = fixedMw;
}
public String getMrid() {
return mrid;
}
public String getName() {
return name;
}
public long getFixedMw()
{
return fixedMw;
}
@Value
public class CreateBidCommand {
@TargetAggregateIdentifier
private final String mrid;
private final String name;
private final long fixedMw;
public CreateBidCommand(String mrid, String name, long fixedMw) {
this.mrid = mrid;
this.name = name;
this.fixedMw = fixedMw;
}
public String getMrid() {
return mrid;
}
public String getName() {
return name;
}
public long getFixedMw()
{
return fixedMw;
}
Event classes:
@Value
public class BidAlteredEvent {
private String mrid;
private String name;
private long fixedMw;
public BidAlteredEvent(String mrid, String name, long fixedMw) {
this.mrid = mrid;
this.name = name;
this.fixedMw = fixedMw;
}
public String getMrid() {
return mrid;
}
public String getName() {
return name;
}
public long getFixedMw() {
return fixedMw;
}
@Value
public class BidCreatedEvent {
private String mrid;
private String name;
private long fixedMw;
public BidCreatedEvent(String mrid, String name, long fixedMw) {
this.mrid = mrid;
this.name = name;
this.fixedMw = fixedMw;
}
public String getMrid() {
return mrid;
}
public String getName() {
return name;
}
public long getFixedMw() {
return fixedMw;
}
I am trying to get a events to appear through my JPA connection. I can connect to my database and I do see the tables generated properly once the application kicks off. It just always complains about the handlers.
Finally my event handler class:
@Component
public class BidsEventHandler {
@EventHandler
public void handle(BidCreatedEvent event) {
System.out.println("Bid Created: " + event.getMrid() + " (" + event.getMrid() + ")");
}
@EventHandler
public void handle(BidAlteredEvent event) {
System.out.println("Bid Altered: " + event.getMrid() + " (" + event.getMrid() + ")");
}
Any help would be greatly appreciated, I can tell I am close -- but I'm clearly missing something inherent here.
Do I need any beans defined within my application or configuration class? I currently don't have any beans configured, based on your previous suggestion that I would not need to configure any of those items
@AggregateIdentifier
private String mrid;
Yet, I always seem to get a new aggregate, even when passing through the same mrid....