Axon 参考指南
  • 介绍
  • 架构概览
    • DDD & CQRS 概念
    • 事件溯源
    • 事件驱动的微服务
  • Axon Server
  • 发行说明
    • Axon Framework
      • Major Releases
      • Minor Releases
    • Axon Server
      • Major Releases
      • Minor Releases Standard Edition
      • Minor Releases Enterprise Edition
    • Axon Framework Extensions
      • AMQP
        • Major Releases
      • CDI
        • Major Releases
      • JGroups
        • Major Releases
      • Kafka
        • Major Releases
        • Minor Releases
      • Kotlin
        • Experimental Releases
      • Mongo
        • Major Releases
        • Minor Releases
      • Reactor
        • Major Releases
        • Minor Releases
      • Spring Cloud
        • Major Releases
        • Minor Releases
      • Tracing
        • Major Releases
        • Minor Releases
  • Getting Started
    • 快速开始
  • Axon Framework
    • 介绍
    • 消息传递概念
      • 消息剖析
      • 消息关联
      • 消息拦截
      • 支持带注解的处理程序
      • 异常处理
      • 工作单元
    • 命令
      • 建模
        • 聚合
        • 多实体聚合
        • 聚合状态存储
        • 从另一个聚合创建聚合
        • 聚合多态性
        • 解决冲突
      • 命令调度器
      • 命令处理程序
      • 基础设施
      • 配置
    • 事件
      • 事件调度器
      • 事件处理程序
      • 事件处理器
        • 订阅事件处理器
        • 流式事件处理器
      • 事件总线和事件存储
      • 事件版本控制
    • 查询
      • 查询处理
      • 查询调度器
      • 查询处理程序
      • 实现
      • 配置
    • 长时处理过程(Sagas)
      • 实现
      • 关联
      • 基础设施
    • Deadlines
      • Deadline Managers
      • Event Schedulers
    • 测试
      • 命令 / 事件
      • 长时处理过程(Sagas)
    • 序列化
    • 调整
      • 事件快照
      • 事件处理
      • 命令处理
    • 监控和指标
    • Spring Boot 集成
    • 模块
  • Axon Server
    • 介绍
    • 安装
      • 本地安装
        • Axon Server SE
        • Axon Server EE
      • Docker / K8s
        • Axon Server SE
        • Axon Server EE
    • 管理
      • 配置
        • System Properties
        • Command Line Interface
        • REST API
        • GRPC API
      • Monitoring
        • Actuator Endpoints
        • gRPC Metrics
        • Heartbeat Monitoring
      • Clusters
      • Replication Groups
      • Multi-Context
      • Tagging
      • Backup and Messaging-only Nodes
      • Backups
      • Recovery
      • Plugins
      • Error Codes
    • 安全
      • SSL
      • 访问控制
      • 访问控制 - 标准版
      • 访问控制 - 企业版
      • 访问控制 - 客户端应用程序
      • 访问控制 - 命令行
      • 访问控制 - REST API
      • 访问控制 - LDAP
      • 访问控制 - OAuth 2.0
    • 性能
      • 事件段
      • 流量控制
    • 迁移
      • Standard to Enterprise Edition
      • Non-Axon Server to Axon Server
  • Extensions
    • Spring AMQP
    • JGroups
    • Kafka
    • Kotlin
    • Mongo
    • Reactor
      • Reactor Gateways
    • Spring Cloud
    • Tracing
  • Appendices
    • A. RDBMS Tuning
    • B. Message Handler Tuning
      • 参数解析器
      • 处理程序增强
    • C. 元数据注解
    • D. 标识符生成
    • E. Axon Server Query Language
由 GitBook 提供支持
在本页
  • Supported Parameters for Command Handlers
  • Supported Parameters for Event Handlers
  • Supported Parameters for Query Handlers
  1. Axon Framework
  2. 消息传递概念

支持带注解的处理程序

Supported Parameters for Annotated Handlers

上一页消息拦截下一页异常处理

最后更新于2年前

This chapter provides an exhaustive list of all the possible parameters for annotated message handling functions. The framework resolves the parameters for any message handling function through an internal mechanism, called the ParameterResolver. The ParameterResolver, built by a ParameterResolverFactory, is in charge of inserting the parameters for the command, event and query handlers.

The set of ParameterResolvers can be extended if custom (or not yet) supported parameters should be injected in to your annotated handlers. You can configure additional ParameterResolvers by implementing the ParameterResolverFactory interface and configuring the new implementation. For more specifics on configuring custom ParameterResolvers we suggest reading section.

Supported Parameters for Command Handlers

By default, @CommandHandler annotated methods allow the following parameter types:

  • The first parameter is always the payload of the command message. It may also be of type Message or CommandMessage, if the @CommandHandler annotation explicitly defined the name of the command the handler can process. By default, a command name is the fully qualified class name of the command its payload.

  • Parameters of type MetaData will have the entire metadata of a CommandMessage injected.

  • Parameters annotated with @MetaDataValue will resolve the metadata value with the key as indicated on the annotation. If required is false (default), null is passed when the metadata value is not present. If required is true, the resolver will not match and prevent the method from being invoked when the metadata value is not present.

  • Parameters of type Message, or CommandMessage will get the complete message, with both the payload and the metadata. Resolving the entire Message is helpful if a method needs several metadata fields or other properties of the message.

  • Parameters of type UnitOfWork get the current injected. The UnitOfWork allows command handlers to register actions to be performed at specific stages of the unit of work or gain access to the resources registered with it.

  • A parameter of type String annotated with @MessageIdentifier will resolve the identifier of the handled CommandMessage.

  • Parameters of type ConflictResolver will resolve the configured ConflictResolver instance. See the section for specifics on this topic.

  • Parameters of type InterceptorChain will resolve the chain of MessageHandlerInterceptors for a CommandMessage. You should use this feature in conjunction with a @CommandHandlerInterceptor annotated method. For more specifics on this it is recommended to read section.

  • The parameter resolvers can resolve a ScopeDescriptor too. The scope descriptor is helpful when through the DeadlineManager. Note that the ScopeDescriptor only makes sense from within the scope of an Aggregate or Saga.

  • If the application runs in a Spring environment, any Spring Bean can be resolved. To that end, we should annotate the desired Spring bean with @Autowired. We can extend the annotation with @Qualifier if a specific version of the bean should be wired.

Supported Parameters for Event Handlers

By default, @EventHandler annotated methods allow the following parameter types:

  • The first parameter is the payload of the event message. If the event handler does not need access to the payload of the message, you can specify the expected payload type on the @EventHandler annotation. Do not configure the payload type on the annotation if you want the payload passed as a parameter.

  • Parameters of type MetaData will have the entire metadata of an EventMessage injected.

  • Parameters annotated with @MetaDataValue will resolve the metadata value with the key as indicated on the annotation. If required is false (default), null is passed when the metadata value is not present. If required is true, the resolver will not match and prevent the method from being invoked when the metadata value is not present.

  • We can resolve the EventMessage in its entirety as well. If the first parameter is of type message, it effectively matches an event of any type, even if generic parameters suggest otherwise. Due to type erasure, Axon cannot detect what parameter the implementation expects. It is best to declare a parameter of the payload type in such a case, followed by a parameter of type message.

  • A parameter of type String annotated with @MessageIdentifier will resolve the identifier of the handled EventMessage.

  • Parameters annotated with @Timestamp and of type java.time.Instant (or java.time.temporal.Temporal) will resolve to the timestamp of the EventMessage. The resolved timestamp is the time at which the event was generated.

  • Parameters annotated with @SequenceNumber and of type java.lang.Long or long will resolve to the sequenceNumber of a DomainEventMessage. This parameter provides the order in which the event was generated (within the aggregate scope it originated from). It is important to note that DomainEventMessage can only originate from an Aggregate. Hence, events that have been published directly on the EventBus/EventGateway are not implementations of the DomainEventMessage. As such, they will not resolve a sequence number.

  • Parameters annotated with @SourceId and of type java.lang.String will resolve to the aggregateIdentifier of a DomainEventMessage. This parameter provides the identifier of the aggregate from which the event originates. It is important to note that DomainEventMessage can only originate from an Aggregate. Hence, events that have been published directly on the EventBus/EventGateway are not implementations of the DomainEventMessage. As such, they will not resolve a source id.

  • If the application runs in a Spring environment, any Spring Bean can be resolved. To that end, we should annotate the desired Spring bean with @Autowired. We can extend the annotation with @Qualifier if a specific version of the bean should be wired.

Supported Parameters for Query Handlers

By default, @QueryHandler annotated methods allow the following parameter types:

  • The first parameter is always the payload of the query message. It may also be of type Message or QueryMessage, if the @QueryHandler annotation explicitly defined the name of the query the handler can process. By default, a query name is the fully qualified class name of the query its payload.

  • Parameters of type MetaData will have the entire metadata of a QueryMessage injected.

  • Parameters annotated with @MetaDataValue will resolve the metadata value with the key as indicated on the annotation. If required is false (default), null is passed when the metadata value is not present. If required is true, the resolver will not match and prevent the method from being invoked when the metadata value is not present.

  • Parameters of type Message, or QueryMessage will get the complete message, with both the payload and the metadata. Resolving the entire Message is helpful if a method needs several metadata fields or other properties of the message.

  • A parameter of type String annotated with @MessageIdentifier will resolve the identifier of the handled CommandMessage.

  • If the application runs in a Spring environment, any Spring Bean can be resolved. To that end, we should annotate the desired Spring bean with @Autowired. We can extend the annotation with @Qualifier if a specific version of the bean should be wired.

Parameters of type UnitOfWork get the current injected. The UnitOfWork allows event handlers to register actions to be performed at specific stages of the unit of work or gain access to the resources registered with it.

Parameters of type TrackingToken will have the current related to the processed event injected. Note that this will only work for StreamingEventProcessor instances, as otherwise, there is no token attached to the events.

Parameters of type UnitOfWork get the current injected. The UnitOfWork allows query handlers to register actions to be performed at specific stages of the unit of work or gain access to the resources registered with it.

unit of work
unit of work
this
unit of work
Conflict Resolution
scheduling a deadline
this
token