当前位置: 首页 > 知识库问答 >
问题:

没有向命令订阅任何处理程序。轴突3.3

翟奇
2023-03-14

我试图按教程创建基本的Axon/Spring应用程序,但面临奇怪的错误,如:noHandlerforCommandException:没有处理程序被订阅到命令。似乎Axon看不到@CommandHandler注释。

这里是我的文件:

@Aggregate
@NoArgsConstructor
public class Account {

    @AggregateIdentifier
    private UUID accountId;
    private Double balance;

    @CommandHandler
    public Account(CreateAccountCommand command) {
        apply(new AccountCreatedEvent(command.getAccountId(), command.getName()));
    }

    @EventSourcingHandler
    protected void on(AccountCreatedEvent event) {
        this.accountId = event.getAccountId();
        this.balance = 0.0;
    } 
}
@AllArgsConstructor
@Getter
public class AccountCreatedEvent {

    private UUID accountId;
    private String name;
}
@Getter
public class CreateAccountCommand {

    @TargetAggregateIdentifier
    private UUID accountId;
    private String name;

    public CreateAccountCommand(UUID accountId, String name) {
        this.accountId = accountId;
        this.name = name;
    }
}
@SpringBootApplication
public class App {

    @Configuration
    public static class TestConfiguration {
        @Bean
        public EventStorageEngine inMemoryEventStorageEngine() {
            return new InMemoryEventStorageEngine();
        }
    }

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}
@Component
public class AppLoader {

    @Autowired
    private CommandGateway cmdGateway;

    @PostConstruct
    public void init() {
        cmdGateway.send(new CreateAccountCommand(UUID.randomUUID(), "test"));
    }
}

我的建筑。Gradle

buildscript {
    ext {
        springBootVersion = '2.0.5.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'io.yourpoint.nettnews'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'org.axonframework', name: 'axon-test', version: '3.3.5'
    compile group: 'org.axonframework', name: 'axon-spring-boot-starter', version: '3.3.5'
    compile('org.springframework.boot:spring-boot-starter-webflux')
    compileOnly('org.projectlombok:lombok')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('io.projectreactor:reactor-test')
}

共有1个答案

咸高谊
2023-03-14

@postconstruct中执行commandgateway#send()调用对Axon来说很可能很早。

目前,所有命令、事件和查询处理程序通常在所有bean初始化后注册。将commandgateway#send()移到RESTendpoint后面应该给您足够长的时间框架,以确保所有处理程序都已注册。

因此,简而言之,获取NoHandlerForCommandException是一个时间问题。

希望这能帮到你@Benjamin!

 类似资料:
  • mysql会员订阅数据表的设计应该如何设计?产品有订阅商品和非订阅的,每次都只能购买一个。 订阅有1个月 3个月的 每次到期自动扣费。如果在一个月类购买了几个订阅商品 则扣费按照最新的一个 然后延长到期时间。其实是不是每次订阅都不需要生成新订单的 翻阅了其他资料都找不到很好的设计

  • 我在用轴突事件跟踪处理器。有时事件需要10秒才能处理。 这似乎导致消息再次被处理,并出现在日志“释放令牌X/0的声明失败。它由另一个节点拥有”中。 如果我增加段数,它不会记录此事件,但事件仍被处理两次,所以我认为这可能会引起误解。 (我想我搞错了) 我已经尝试调整fetchDelay、cleanupDelay和TokenClaimInterval。没有一个解决了这个问题。我是不是缺了什么东西? 编

  • 我可以在Axon中顺序处理的两个事件之间放置一个序列(或以一定的时间间隔执行)。这两个事件同时创建。下面是示例事件。 因为我的第二个事件取决于第一个事件的执行结果。我正在使用RabbitMq发布消息。

  • 主要内容:一、Sql流程,二、源码分析,四、总结一、Sql流程 MySql是数据库,这次就分析一下一条SQL语句的流程,流程可能不会全面展开分析,当后面遇到具体的模块时,再由各个模块深入学习。如果使用过MySql的客户端(任意一种都可以),基本的形式就是在客户端写一条SQL语句,然后点击运行,正常的情况下,就会返回这条SQL执行后的结果。 可能学习Sql源码的人不少,但学习编译器知识的人就少多了。在SQL语句的执行过程中,其实SQL语句就是一门

  • 我尝试使用Vertx HttpClient/WebClient来使用GraphQL订阅,但没有按预期工作。 与服务器端相关的代码(使用Vertx Web GraphQL编写)如下所示,添加注释后,触发onNext将注释发送到发布者。 在客户端中,我混合使用HttpClient/WebClient,大多数时候,我想使用WebClient,它更容易处理表单帖子。但它似乎没有连接。 所以websocke

  • 我为Eclipse编写了一个插件。我在工具栏菜单中有一个按钮。我想要按下它-一个向导页面对话框将被打开。我已经写了一个扩展wizard和实现IWizardPage的类,我还写了所有5个相关的页面,我只是没有找到任何方法在命令处理程序中打开它。 下面是我的代码片段: plugin.xml部分: 你有什么想法吗?