Axon服务器命令不包含路由密钥

时间:2018-11-15 04:19:59

标签: java axon

我正在尝试使用Axon服务器将应用程序迁移到Axon 4.0。 这是我的代码。

data class CreateTravelProductCommand(
    @TargetAggregateIdentifier val id: String,
    val productCreator: String
)

val id: String = ObjectId.get().toString()
val command = CreateTravelProductCommand(id=id, productCreator=request.creator)
commandGateway.sendAndWait(command)

但是我的命令出现此错误。

  

org.axonframework.commandhandling.distributed.CommandDispatchException:   命令[com.sunday.api.product.CreateTravelProductCommand]执行   不包含路由密钥。         在org.axonframework.commandhandling.distributed.AbstractRoutingStrategy.getRoutingKey(AbstractRoutingStrategy.java:57)   〜[axon-messaging-4.0.jar:4.0]         在org.axonframework.axonserver.connector.command.AxonServerCommandBus.dispatch(AxonServerCommandBus.java:114)   〜[axon-server-connector-4.0.jar:4.0]         在org.axonframework.commandhandling.gateway.AbstractCommandGateway.send(AbstractCommandGateway.java:75)   [axon-messaging-4.0.jar:4.0]         在org.axonframework.commandhandling.gateway.DefaultCommandGateway.send(DefaultCommandGateway.java:78)   [axon-messaging-4.0.jar:4.0]         在org.axonframework.commandhandling.gateway.DefaultCommandGateway.sendAndWait(DefaultCommandGateway.java:96)处   [axon-messaging-4.0.jar:4.0]         在com.sunday.underwriting.product.ProductHandler.sendCreateProductCommand(ProductHandler.kt:40)   [classes /:na]         在com.sunday.underwriting.product.ProductHandler.access $ sendCreateProductCommand(ProductHandler.kt:33)   [classes /:na]         在com.sunday.underwriting.product.ProductHandler $ createProduct $ product $ 1.invoke(ProductHandler.kt:97)   [classes /:na]         在com.sunday.underwriting.product.ProductHandler $ createProduct $ product $ 1.invoke(ProductHandler.kt:33)   [classes /:na]         在com.sunday.underwriting.product.ProductHandler $ sam $ java_util_function_Function $ 0.apply(ProductHandler.kt)   [classes /:na]         在Reactor.core.publisher.FluxMap $ MapSubscriber.onNext(FluxMap.java:100)   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在reactor.core.publisher.FluxOnErrorResume $ ResumeSubscriber.onNext(FluxOnErrorResume.java:73)   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在Reactor.core.publisher.Operators $ MonoSubscriber.complete(Operators.java:1476)   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在reactor.core.publisher.MonoSingle $ SingleSubscriber.onComplete(MonoSingle.java:171)   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在Reactor.core.publisher.FluxMap $ MapSubscriber.onComplete(FluxMap.java:136)   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在Reactor.core.publisher.FluxFlatMap $ FlatMapMain.checkTerminated(FluxFlatMap.java:794)处   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在reactor.core.publisher.FluxFlatMap $ FlatMapMain.drainLoop(FluxFlatMap.java:560)   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在reactor.core.publisher.FluxFlatMap $ FlatMapMain.drain(FluxFlatMap.java:540)   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在reactor.core.publisher.FluxFlatMap $ FlatMapMain.onComplete(FluxFlatMap.java:426)   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在reactor.core.publisher.DrainUtils.postCompleteDrain(DrainUtils.java:131)   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在reactor.core.publisher.DrainUtils.postComplete(DrainUtils.java:186)   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在Reactor.core.publisher.FluxMapSignal $ FluxMapSignalSubscriber.onComplete(FluxMapSignal.java:213)处   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在Reactor.core.publisher.FluxMap $ MapSubscriber.onComplete(FluxMap.java:136)   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在reactor.core.publisher.FluxPeek $ PeekSubscriber.onComplete(FluxPeek.java:252)   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在Reactor.core.publisher.FluxMap $ MapSubscriber.onComplete(FluxMap.java:136)   [reactor-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]         在react.netty.channel.FluxReceive.terminateReceiver(FluxReceive.java:378)   [reactor-netty-0.8.2.RELEASE.jar:0.8.2.RELEASE]         在react.netty.channel.FluxReceive.drainReceiver(FluxReceive.java:202)   [reactor-netty-0.8.2.RELEASE.jar:0.8.2.RELEASE]         在react.netty.channel.FluxReceive.onInboundComplete(FluxReceive.java:343)   [reactor-netty-0.8.2.RELEASE.jar:0.8.2.RELEASE]         在react.netty.channel.ChannelOperations.onInboundComplete(ChannelOperations.java:325)   [reactor-netty-0.8.2.RELEASE.jar:0.8.2.RELEASE]         在react.netty.http.server.HttpServerOperations.onInboundNext(HttpServerOperations.java:442)   [reactor-netty-0.8.2.RELEASE.jar:0.8.2.RELEASE]         在react.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:141)   [reactor-netty-0.8.2.RELEASE.jar:0.8.2.RELEASE]         在io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在react.netty.http.server.HttpTrafficHandler.channelRead(HttpTrafficHandler.java:188)   [reactor-netty-0.8.2.RELEASE.jar:0.8.2.RELEASE]         在io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.CombinedChannelDuplexHandler $ DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310)   [netty-codec-4.1.29.Final.jar:4.1.29.Final]         在io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284)   [netty-codec-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.DefaultChannelPipeline $ HeadContext.channelRead(DefaultChannelPipeline.java:1434)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.nio.AbstractNioByteChannel $ NioByteUnsafe.read(AbstractNioByteChannel.java:163)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:628)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:563)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:480)   [netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:442)[netty-transport-4.1.29.Final.jar:4.1.29.Final]         在io.netty.util.concurrent.SingleThreadEventExecutor $ 5.run(SingleThreadEventExecutor.java:884)   [netty-common-4.1.29.Final.jar:4.1.29.Final]         在java.lang.Thread.run(Thread.java:748)[na:1.8.0_172]

编辑:

我刚刚发现,如果您将类保留在同一项目中,就可以了。

问题是当您从另一个项目(曾经在轴突服务器之前工作过)导入类时

例如:

我的项目具有另一个名为api的项目的依赖项。

dependencies {
    compile project(':api')
}

如果在api项目中声明了该类,则轴突服务器库将引发错误,即找不到路由键。但是,如果该类在主项目中声明为自身,则它将按预期工作。我认为我应该将此问题提交到github。

3 个答案:

答案 0 :(得分:1)

真正的问题是2个项目之间的版本不匹配。我必须更正版本,但是intellij自动加载器无法正常工作,并且api项目的版本不正确。

我为自己的愚蠢而道歉

答案 1 :(得分:0)

这实际上与Kotlin的关系比与Axon的关系更大。 Axon希望它们使用Field或Getter方法。显然,这不是Kotlin放置它们的默认位置。

签出https://kotlinlang.org/docs/reference/annotations.html#annotation-use-site-targets

您可能需要用@get:TargetAggregateIdentifier注释属性

答案 2 :(得分:0)

从Axon 3.x迁移到4.0时,我遇到了同样的问题。 该解决方案与@TargetAggregateIdentifier有关-我在聚合处理的'CreateXXXCommand'中丢失了它。我很确定在Axon 3.x中添加@TargetAggregateIdentifier对于创建命令不是必需的(因为它不必定位现有的聚合)

在撰写本文时,迁移指南尚未完成https://docs.axoniq.io/reference-guide/3-migration/migration-guide