跳到主要内容
版本:latest

注解解析器

简介

聚合根注解中的大部分配置用于聚合根的运行性能调优,不限于运行模式、攒批次数、快照间隔等,然而在实际生产运行中,需要通过修改代码的方式来让注解生效是十分不利于频繁的压测以及紧急配置修复的。 因此 Phoenix 内置了注解解析器用于将 Spring 的配置解析成聚合根的注解配置,可用于以下两种类型:

  • @EntityAggregateAnnotation: 实体聚合根注解
  • @TransactionAggregateAnnotation: 事务聚合根注解

从 Phoenix 2.2.4开始,依赖了 phoenix-stater 的环境下,聚合根支持从启动参数/环境变量/配置文件中读取参数。

在 Phoenix 2.6.0 开始,事务支持也支持注解解析

配置优先级:启动参数 > 环境变量 > 配置文件 > 代码注解自定义 > 注解默认值

聚合根 Spring 的通用配置层次如下:

quantex:
phoenix:
server:
<注解类型:entityAggregate/transactionAggregate>:
<聚合根类型: XX>
<注解配置1: surviveTime>: 1000
<注解配置2: batchWeight>: 200

实体聚合根注解

实体聚合根的注解以:quantex.phoenix.server.entityAggregate 开头, 并在后面附加聚合根类型和实际注解

配置项描述类型对应的注解函数
{aggregateRootType}聚合根类型,无法从配置文件中读取stringaggregateRootType
quantex.phoenix.server.entityAggregate.{aggregateRootType}.surviveTime聚合根允许生存的时间(在内存中活跃)longsurviveTime
quantex.phoenix.server.entityAggregate.{aggregateRootType}.passivationTime聚合根允许钝化的时间(在EventStore存储)longpassivationTime
quantex.phoenix.server.entityAggregate.{aggregateRootType}.allowPassivation聚合根是否允许钝化booleanallowPassivation
quantex.phoenix.server.entityAggregate.{aggregateRootType}.snapshotMode快照模式enumsnapshotMode
quantex.phoenix.server.entityAggregate.{aggregateRootType}.snapshotInterval快照间隔longsnapshotInterval
quantex.phoenix.server.entityAggregate.{aggregateRootType}.numberOfRetainSnapshots需要保留的快照数量longnumberOfRetainSnapshots
quantex.phoenix.server.entityAggregate.{aggregateRootType}.idempotentSize聚合根幂等集合大小longidempotentSize
quantex.phoenix.server.entityAggregate.{aggregateRootType}.bloomSize布隆过滤器大小longbloomSize
quantex.phoenix.server.entityAggregate.{aggregateRootType}.dispatcher聚合根运行线程池stringdispatcher
quantex.phoenix.server.entityAggregate.{aggregateRootType}.runningMode聚合根运行模式enum stringrunningMode
quantex.phoenix.server.entityAggregate.{aggregateRootType}.batchWeight聚合根消息攒批的最大批次intbatchWeight
quantex.phoenix.server.entityAggregate.{aggregateRootType}.bufferSize异步模式下,持久化时允许缓存的消息批次(package)数量intbufferSize
quantex.phoenix.server.entityAggregate.{aggregateRootType}.heartbeatInterval聚合根心跳频率(ms), 心跳负责淘汰和自身信息上报longheartbeatInterval
quantex.phoenix.server.entityAggregate.{aggregateRootType}.trialHeartbeatInterval试算聚合根心跳频率(ms), 心跳期间没有消息则会将试算聚合根从内存中清理(仅增量试算)longtrialHeartbeatInterval
quantex.phoenix.server.entityAggregate.{aggregateRootType}.trialDispatcher试算聚合根运行线程池stringtrialDispatcher
quantex.phoenix.server.entityAggregate.{aggregateRootType}.aggregateIdSize聚合根 ID 最大长度限制intaggregateIdSize
quantex.phoenix.server.entityAggregate.{aggregateRootType}.aggregateIdTruncate聚合根 ID 自动截断, 超出配置的大小的 ID 自动截断到合适的长度并添加十六进制哈希booleanaggregateIdTruncate

以yaml配置文件为例:

当使用了@EntityAggregateAnnotation,并且aggregateRootTypeBankAccount。则:

quantex:
phoenix:
server:
entityAggregate:
BankAccount: # {aggregateRootType}
surviveTime: 10
snapshotInterval: 10
idempotentSize: 10
bloomSize: 10

事务聚合根注解

事务聚合根的注解以:quantex.phoenix.server.transactionAggregate 开头, 并在后面附加聚合根类型和实际注解

配置项描述类型对应的注解函数
{aggregateRootType}聚合根类型,无法从配置文件中读取StringaggregateRootType
quantex.phoenix.server.transactionAggregate.{aggregateRootType}.heartbeatTickInterval心跳滴答间隔(秒)intheartbeatTickInterval
quantex.phoenix.server.transactionAggregate.{aggregateRootType}.heartbeatCheckInterval心跳检查间隔(秒)intheartbeatCheckInterval
quantex.phoenix.server.transactionAggregate.{aggregateRootType}.retryStrategy重试策略(指数退避和固定频率)enumretryStrategy
quantex.phoenix.server.transactionAggregate.{aggregateRootType}.maxRetryNum事务总超时次数(最大心跳检查间隔)longmaxRetryNum
quantex.phoenix.server.transactionAggregate.{aggregateRootType}.batchWeight聚合根消息攒批的最大批次intbatchWeight

以yaml配置文件为例:

当使用了@TransactionAggregateAnnotation,并且aggregateRootTypeBankTransferSaga。则:

quantex:
phoenix:
server:
transactionAggregate:
BankTransferSaga: # {aggregateRootType}
heartbeatTickInterval: 2
heartbeatCheckInterval: 2
maxRetryNum: 10