Skip to content

Latest commit

 

History

History
54 lines (37 loc) · 2.87 KB

README.md

File metadata and controls

54 lines (37 loc) · 2.87 KB

Multi-tenant playground

This simple app allows you to experiment with multi-tenancy feature in Axon Framework. By using Multitenancy extension this app can connect to multiple contexts at once dynamicly. Using Vaadin UI, explore how to create tenants in runtime and dispatch messages to them.

Requirements

  • Requires Axon Server 2024.1+ with a valid license
  • Axon Framework 4.10.1+
  • Multitenancy extension
  • Uses In-Memory H2 Database for projections - DB per tenant

How to start

While in src/main/docker type in terminal docker-compose up to start Axon Server EE.

Make sure to replace content of axoniq.license with a valid license.

Start application with mvn spring-boot:run or manually via favorite IDE.

After starting application visit and interact with UI at localhost:8080

You may start by registering a new tenant.

With UI you can:

  • Login as existing tenant
  • Register new tenant at runtime
  • Send commands, queries, events
  • Reset projections
  • Explore H2 Database used for projections - per tenant

How it works

Multi-tenant configuration

MultiTenantConfig#tenantFilter configures application to connect to any context which name starts with tenant-. If new context is created during runtime that matches the filter, application will automatically connect to that tenant.

MultiTenantConfig#tenantDataSourceResolver configures application to use DB for projections per tenant. It defines datasource properties for tenant. Important: DB needs to be created and schema needs to be initialiesd before context is created, otherwise you will see exception such as DB/Table not found...

CreateTenantService#createTenant uses Admin API to interact with Axon Server and create tenant context. Before creating context it creates embedded H2 database. As H2 database is in memory, it will not be persistent after application restart, while Axon Server contexts will. Be sure to clean up contexts if you are planing to play with this application multiple times or you may expect to see some exceptions.

MessageService routes messages to specific tenant by setting TENANT_CORRELATION_KEY MetaData to initial message.

ResetService lists all event processors and resets one for specificity tenant. Convention is that Event Processor name contains original event processor name and tenant name. Such as even_processor_name@tenant_name.