Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Axon Framework Resource Reference Doc

This document is a collation of resources for understanding actual practical usage of the Axon Framework:

  • Feel free to:
    • use it to lookup something (code snippets/examples/tips).
    • contribute a change if something is wrong or missing.
    • fork it and make a better/derivative version.

Contents

Project Structure (Start Here)

See:

  1. The quick start application.
    • It is based on Axon 3 but the API is more or less the same for Axon 4.
    • Gives you a solid base in which you can learn:
      • The typical Axon CQRS project structure.
      • Axon Framework APIs (@CommandHandler, @EventSourcingHandler, @EventHandler, @QueryHandler, etc).
      • Important: How to test your application (see test suite).
  2. The associated Webinar
    • Ideal to watch at 1.5x/2x speed.
    • A good walkthrough of the structure.

Open Source Example Projects

Examples of testing

@Aggregate Tips

Creating an @Aggregate

From another aggregate (using AggregateLifecycle.createNew(Class<T>, Callable<T>))

See:

@Repository<T> Tips

Occasionally, we need to write a @Component which has access to an underlying Axon Repository<T>.

  • Sometimes dealing with a @Repository<T> can be slightly annoying (I think it is because of the generic type <T>).
  • Follow the tips in the code snippets below when you have a problem.

Autowiring a @Repository<T>

  • You need to add a @Lazy to the parameter in the constructor in your @Component (assuming constructor injection and all final fields).
  • If you do not do this your application context may fail to load because of an NPE.

Manually creating a @Repository<T> bean

Backed by an EventStore repository

  @Bean
  public Repository<GiftCard> giftCardRepository(EventStore eventStore, Cache cache) {
      return EventSourcingRepository.builder(GiftCard.class)
                                    .cache(cache)
                                    .eventStore(eventStore)
                                    .build();
  }

For original code source, see: giftcard-demo.

Examples of snapshotting

The digital restaurant application contains examples of how to define snapshotting for your aggregates From the README:

A Snapshot is a denormalization of the current state of an aggregate at a given point in time
It represents the state when all events to that point in time have been replayed
They are used as a heuristic to prevent the need to load all events for the entire history of an aggregate

Each aggregate defines a snapshot trigger:

@Aggregate(snapshotTriggerDefinition = "courierSnapshotTriggerDefinition")
Feel free to configure a treshold (number of events) that should trigger the snapshot creation. This treshold is externalized as a property axon.snapshot.trigger.treshold.courier

Tracking Event Processor

Configuring properties

Examples of configuring tracking event processors:

See:

Resetting a tracking event processor

See:

Subscription Queries

Videos

Example Code

(Kotlin) nklmish/axon-casino:

  • Example 1:
    • SingleWalletSummaryQuery Subscription Query (line 167):
      val queryResult = queryGateway.subscriptionQuery(
          SingleWalletSummaryQuery(cmd.walletId),                     // 1
          ResponseTypes.instanceOf(WalletSummary::class.java),        // 2
          ResponseTypes.instanceOf(WalletSummaryUpdate::class.java))  // 3
      • 1: Subscribe to SingleWalletSummaryQuery.
      • 2: Initial subscription will return the response type: ResponseTypes.instanceOf(WalletSummary::class.java)
      • 3: Subsequent updates in the subscription will be of the response type: ResponseTypes.instanceOf(WalletSummaryUpdate::class.java)
    • SingleWalletSummaryQuery @QueryHandler:
      • Provides the initial result to the SingleWalletSummaryQuery subscription query.
      • This initial result is of type: WalletSummary.
    • SingleWalletSummaryQuery queryUpdateEmitter.emit(..):
      • Provides the subsequent updates to the SingleWalletSummaryQuery subscription query.
      • These are updates are of the type WalletSummaryUpdate.
      • There are multiple @EventHandlers which do this.
        • Search for queryUpdateEmitter.emit( on the page to see them e.g. line 41, 49, 58, etc.
  • Example 2:
    • TotalDepositedQuery Subscription Query (line 20):
      return queryGateway.subscriptionQuery(TotalDepositedQuery(),                   // 1
             ResponseTypes.multipleInstancesOf(TotalDepositedSample::class.java),    // 2
             ResponseTypes.instanceOf(TotalDepositedSample::class.java)).updates()   // 3
      • 1: Subscribe to TotalDepositedQuery.
      • 2: Initial subscription will return the response type: ResponseTypes.multipleInstancesOf(TotalDepositedSample::class.java)
      • 3: Subsequent updates in the subscription will be of the response type: ResponseTypes.instanceOf(TotalDepositedSample::class.java)
    • TotalDepositedQuery @QueryHandler:
      • Provides the initial result to the TotalDepositedQuery subscription query.
      • This initial result is of type: List<TotalDepositedSample>.
    • TotalDepositedQuery queryUpdateEmitter.emit(..):
      • Provides the subsequent updates to the TotalDepositedSample subscription query.
      • These are updates are of the type TotalDepositedSample.

(Java) fransvanbuul/sq-webinar:

  • FetchCardSummariesQuery Subscription Query:
     return queryGateway.subscriptionQuery(
            new FetchCardSummariesQuery(0,1, new CardSummaryFilter("")), // 1
            ResponseTypes.multipleInstancesOf(CardSummary.class),        // 2
            ResponseTypes.instanceOf(CardSummary.class)).updates();      // 3
    • 1: Subscribe to FetchCardSummariesQuery.
    • 2: Initial subscription will return the response type: ResponseTypes.multipleInstancesOf(CardSummary.class)
    • 3: Subsequent updates in the subscription will be of the response type: ResponseTypes.instanceOf(CardSummary.class)
  • FetchCardSummariesQuery @QueryHandler:
    • Provides the initial result to the FetchCardSummariesQuery subscription query.
    • The initial result is of type: List<CardSummary>
  • FetchCardSummariesQuery queryUpdateEmitter.emit(..):
    • Provides the subsequent updates to the FetchCardSummariesQuery subscription query.
    • These are updates are of the type CardSummary.

(Kotlin) idugalic/digital-restaurant:

  • Lots of examples in this repo.

About

Reference of resources for understanding the Axon Framework.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages