Axon 外部事件处理程序不工作并且 table 未创建

Axon external event handler not working and table not being created

我是轴突的新手。我想制作简单的轴突应用程序。

我是

  1. 使用两个实例(命令应用、查询应用)
  2. 使用轴突服务器
  3. 使用科特林
  4. 使用多模块
  5. 轴突框架 4.5

并且我检查了存储来自仪表板 (http://localhost:8024) 的事件数据的命令应用程序

但是,未调用事件处理程序

这是项目结构

practice-root
│
├── command
│   ├── build
│   ├── src
│   │    ├── main
│   │    │     ├ kotlin
│   │    │     │  └ com.cqrs.axon
│   │    │     │         ├ Application.kt
│   │    │     │         ├ SimpleDTO
│   │    │     │         ├ SimpleController
│   │    │     │         ...
│   │    │     └ resources
│   │    ├── test
│   │    │
│   └── build.gradle
│
├── query
│     ├ ...
│     ...
│
├── README
├── build.gradle
└── settings.gradle

这是我的代码

命令模块

Application.kt

@SpringBootApplication()
class Application

fun main(args: Array<String>) {
    runApplication<Application>(*args)
}

SimpleService.kt

@Service
class SimpleService(
    private val eventGateway: EventGateway
) {
    @CommandHandler
    fun createSimple(simpleDTO: SimpleDTO): Unit {
        return this.eventGateway.publish(
            SimpleEvent(
                id = UUID.randomUUID().toString(),
                data = simpleDTO.data
            )
        )
    }
}

SimpleDTO.kt

data class SimpleDTO (
    val data: String
)

SimpleController.kt


@RestController
class SimpleController(
    private val simpleService: SimpleService
    ) {

    @PostMapping("/simple")
    fun createSimple(@RequestBody simpleDTO: SimpleDTO): Unit {
        return simpleService.createSimple(simpleDTO)
    }
}

application.yml

---
server:
  port: 8080

spring:
  application:
    name: commandSpringApplication
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:33060/test?useSSL=false&characterEncoding=utf8&useUnicode=true
    username: userA
    password: u123

  jpa:
    show-sql: true
    properties:
      hibernate:
        dialect: org.hibernate.dialect.MySQL8Dialect
        ddl-auto: update
        format_sql: true
        jdbc:
          time_zone: UTC
    hibernate:
      naming:
        physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

axon:
  serializer:
    general: xstream
  axonserver:
    servers: localhost:8124

logging:
  level:
    com:
      cqrs:
        command: debug
    org:
      axonframework: debug

查询模块

Application.kt

@SpringBootApplication()
class Application

fun main(args: Array<String>) {
    runApplication<Application>(*args)
}

QuerySimpleProjection.kt

@Component
class QuerySimpleProjection (
    private val simpleRepository: QuerySimpleRepository
) {

    @EventHandler
    fun on(event: SimpleEvent, @Timestamp instant: Instant) {
        val simpleMV = SimpleMV(
            id = event.id,
            data = event.data
        )
        simpleRepository.save(simpleMV)
    }
}

QuerySimpleRepository.kt

@Repository
interface QuerySimpleRepository : JpaRepository<SimpleMV, String>

SimpleMV.kt

@Entity
@Table(name = "mv_simple")
data class SimpleMV (

    @Id
    val id: String,
    val data: String
)

AxonConfig.kt

@Configuration
class AxonConfig {

    @Autowired
    fun configureProcessorDefault(processingConfigurer: EventProcessingConfigurer) {
        processingConfigurer.usingSubscribingEventProcessors()
    }
}

application.yml

---
server:
  port: 9090

spring:
  application:
    name: querySpringApplication
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:33060/test?useSSL=false&characterEncoding=utf8&useUnicode=true
    username: userA
    password: u123

  jpa:
    show-sql: true
    properties:
      hibernate:
        dialect: org.hibernate.dialect.MySQL8Dialect
        ddl-auto: create
        format_sql: true
        jdbc:
          time_zone: UTC

axon:
  serializer:
    general: xstream
  axonserver:
    servers: localhost:8124


logging:
  level:
    com:
      cqrs:
        command: debug
    org:
      axonframework: debug

普通模块

SimpleEvent.kt

data class SimpleEvent (
    val id: String,
    val data: String
)
命令模块和查询模块

build.gradle

apply plugin: 'kotlin-jpa'
apply plugin: 'org.springframework.boot'
apply plugin: 'kotlin-allopen'
...
dependencies {
    implementation project(':common')
    implementation 'org.springframework.boot:spring-boot-starter-validation'

    implementation 'mysql:mysql-connector-java'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation "org.axonframework:axon-spring-boot-starter:4.5.8"
    implementation "org.axonframework:axon-configuration:4.5.8"
    implementation "org.axonframework:axon-server-connector:4.5.8"
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

我以为事件会存储在命令模块中 并且数据将包含在查询模块的 mv_simple table 中。 table 也未创建。

我应该怎么做才能让它发挥作用?


[更新]

我改成这个

 spring:
  jpa:
    show-sql: true
    properties:
      hibernate.hbm2ddl.auto: update
      ...

现在我可以看到创建的 table。 但仍然无法将数据存储到 mv_simple table.

未调用事件处理程序

将常用包名称更改为 com.cqrs.axon。 使用相同的包名很重要! 它在删除 Axonconfig.kt 以在上面的代码中使用跟踪事件处理器后工作。