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

组织。轴心框架。命令处理。分发。CommandDispatchException:该命令不包含路由密钥

袁泰
2023-03-14

我正在开发SpringBootAxonCQRS示例。在本例中,当敲击到

curl-H“内容类型:application/json”-d'{“company”:“apple”,“description”:“My Kep”}”http://localhost:8080

我已经启动了下面的服务器(axonserver-4.0.jar),我不知道如何修复这个错误。如果您需要任何其他详细信息,请告诉我?

-rw-r--r-- 1 user 1049089     6153 Oct 17 13:11 README.txt
-rw-r--r-- 1 user 1049089    16934 Oct 17 19:50 LICENSE.txt
drwxr-xr-x 1 user 1049089        0 Oct 22 22:26 kubernetes/
-rwxr-xr-x 1 user 1049089  3290320 Oct 22 22:26 axonserver-cli-4.0.jar*
-rwxr-xr-x 1 user 1049089 83303084 Oct 22 22:26 axonserver-4.0.jar*
drwxr-xr-x 1 user 1049089        0 Oct 22 22:26 ../
drwxr-xr-x 1 user 1049089        0 Oct 30 16:54 data/
-rw-r--r-- 1 user 1049089       13 Oct 30 16:54 AxonIQ.pid
drwxr-xr-x 1 user 1049089        0 Oct 30 16:54 ./

我得到以下错误:

org.axonframework.commandhandling.distributed.CommandDispatchException: The command [org.demo.DemoComplaintsApplication$FileComplaintCommand] does not contain a routing key.
    at org.axonframework.commandhandling.distributed.AbstractRoutingStrategy.getRoutingKey(AbstractRoutingStrategy.java:57) ~[axon-messaging-4.0.jar:4.0]
    at org.axonframework.axonserver.connector.command.AxonServerCommandBus.dispatch(AxonServerCommandBus.java:114) ~[axon-server-connector-4.0.jar:4.0]
    at org.axonframework.commandhandling.gateway.AbstractCommandGateway.send(AbstractCommandGateway.java:75) [axon-messaging-4.0.jar:4.0]
    at org.axonframework.commandhandling.gateway.DefaultCommandGateway.send(DefaultCommandGateway.java:78) [axon-messaging-4.0.jar:4.0]
    at org.axonframework.commandhandling.gateway.DefaultCommandGateway.send(DefaultCommandGateway.java:134) [axon-messaging-4.0.jar:4.0]
    at org.demo.DemoComplaintsApplication$ComplaintAPI.fileCompplaint(DemoComplaintsApplication.java:47) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_162]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_162]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_162]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_162]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) [spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) [spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) [spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:891) [spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) [spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) [spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) [spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) [spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) [spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877) [spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) [spring-webmvc-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.5.34.jar:8.5.34]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) [spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) [spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) [spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.10.RELEASE.jar:5.0.10.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_162]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_162]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.34.jar:8.5.34]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_162]

波姆。xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.6.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.axonframework</groupId>
            <artifactId>axon-spring-boot-starter</artifactId>
            <version>4.0</version>
        </dependency>
        <dependency>
            <groupId>org.axonframework</groupId>
            <artifactId>axon-core</artifactId>
            <version>3.4</version>
        </dependency>
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

主控制程序

@SpringBootApplication
public class DemoComplaintsApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoComplaintsApplication.class, args);
    }

    @RestController
    public static class ComplaintAPI {

        private final ComplaintQueryObjectRepository repostory;
        private final CommandGateway commandGateway;

        public ComplaintAPI(ComplaintQueryObjectRepository repostory, CommandGateway commandGateway) {
            this.repostory = repostory;
            this.commandGateway = commandGateway;
        }

        @PostMapping
        public CompletableFuture<String> fileCompplaint(@RequestBody Map<String, String> request) {
            String id = UUID.randomUUID().toString();
            return commandGateway
                    .send(new FileComplaintCommand(id, request.get("company"), request.get("description")));
        }

        @GetMapping
        public List<ComplaintQueryObject> findAll() {
            return repostory.findAll();
        }

        @GetMapping("/{id}")
        public ComplaintQueryObject find(@PathVariable String id) {
            //return repostory.findOne(id);
            return repostory.findById(id).get();
        }
    }

    @Aggregate
    public static class Complaint {
        @AggregateIdentifier
        private String complaintId;

        public Complaint() {
            super();
        }

        @CommandHandler
        public Complaint(FileComplaintCommand command) {
            apply(new ComplaintFileEvent(command.getId(), command.getCompany(), command.getDescription()));
        }

        @EventSourcingHandler
        public void on(ComplaintFileEvent event) {
            this.complaintId = event.getId();
        }
    }

    @Component
    public static class ComplaintQueryObjectUpdater {

        private final ComplaintQueryObjectRepository repository;

        public ComplaintQueryObjectUpdater(ComplaintQueryObjectRepository repository) {
            this.repository = repository;
        }

        @EventHandler
        public void on(ComplaintFileEvent event) {
            repository.save(new ComplaintQueryObject(event.getId(), event.getCompany(), event.getDescription()));
        }
    }

    public static class FileComplaintCommand {
        private String id;
        private String company;
        private String description;

        public FileComplaintCommand(String id, String company, String description) {
            super();
            this.id = id;
            this.company = company;
            this.description = description;
        }

        public String getId() {
            return id;
        }

        public String getCompany() {
            return company;
        }

        public String getDescription() {
            return description;
        }

    }

卷曲逗号

$curl-H"内容类型:应用程序/json"-d'{"公司":"苹果","描述":"我的Kep"}'localhost:8080%总计%接收%Xferd平均速度时间时间当前卸载上传总计花费左速度100 392 0 345 100 47 11129 1516 --:--:-- --:--:-- --:--:-- 12645{"时间戳":1540911397422,"状态":500,"错误":"内部服务器错误","异常":"java.util.concurrent.CompletionExc0019","消息":"AxonServer命令DispatchExc0019{消息=命令[org.demo.DemoComaintsApplication$FileComaint命令]不包含路由键。, errorCode='AXONIQ-4003', server='10296@841DTN2'}","path":"/"}

共有1个答案

宗沛
2023-03-14

错误命令[...]不包含路由键是由于在命令中缺少带注释的字段@TargetAggregate标识符造成的。在axonLocal命令总线中,这只在针对现有聚合的命令上是必要的。在分布式版本中,在创建聚合的命令上也有必要,因为Axon Server命令总线会查看它来做出路由决策。

因此,将@TargetAggregateIdentifier添加到FileComplaintCommand中的id字段中。

 类似资料:
  • 但我的命令出错了。 编辑: 我刚刚发现,如果你把类保留在同一个项目中,这是可以的。 我的项目依赖于另一个叫做API的项目。 如果在api项目中声明类,axon服务器库将抛出找不到路由密钥的错误。但是如果类是在主项目中声明的,它就会按照预期工作。我想我应该把这个问题提交到GitHub上。

  • 在本章中,我们来看一看一些经常使用的批处理命令。如下图中所示 - 编号 命令 描述 1 VER 此批处理命令显示正在使用的MS-DOS的版本。 2 ASSOC 这是将扩展名与文件类型(FTYPE)相关联的批处理命令,显示现有关联或删除关联。 3 CD 此批处理命令用于更改进入不同的目录,或显示当前目录。 4 CLS 这个批处理命令清除屏幕。 5 COPY 此批处理命令用于将文件从一个位置复制到另一

  • #,## # 和 ## 操作符是和#define宏使用的. 使用# 使在#后的首个参数返回为一个带引号的字符串. 例如, 命令 #define to_string( s ) # s 将会使编译器把以下命令 cout << to_string( Hello World! ) << endl; 理解为 cout << "Hello World!" << endl;

  • 预处理命令 #, ## manupilate字符串 #define 定义变量 #error 显示一个错误消息 #if, #ifdef, #ifndef, #else, #elif, #endif 条件操作符 #include 插入其它文件的内容 #line 设置行和文件信息 #pragma 执行特殊命令 #undef 取消定义变量 预定义变量 其它变量

  • 让我们举一个电子邮件传奇的例子:当一个用户注册时,我们创建一个发布UserRegisterEvent的用户聚合,一个传奇将被创建,这个传奇负责确保注册电子邮件被发送给用户(电子邮件可能包含验证密钥、欢迎消息等)。 我们是否应该使用: > 用try/catch->缩放吗? 使用deadline是因为我们只使用“send”,而不处理命令的最终错误,这可能是发送失败(其他服务关闭,等等) 其它的呢? 还

  • 本文向大家介绍批处理命令教学之tree命令,包括了批处理命令教学之tree命令的使用技巧和注意事项,需要的朋友参考一下 tree ,在英语中的基本含义是“树”,在cmd中,tree命令的功能是以树形格式罗列文件。 当你向别人展示你自己所做光盘的内容的时候,或者是罗列你硬盘上某个目录下的资料的时候,tree命令显得相当方便,并且能让你展示的内容层次分明,井井有条。啥也不说了,上图,顺便温习一下cd命