我正在尝试将我的应用程序迁移到具有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项目中声明了该类,则axon服务器库将引发错误,即找不到路由密钥。但是,如果该类在主项目中声明为自已,则它将按预期工作。我认为我应该在github上提交此问题。
最佳答案
真正的问题是两个项目之间的版本不匹配。我必须更正版本,但是intellij autoloader无法正常工作,并且api项目的版本不正确。
我为自己的愚蠢而道歉
关于java - Axon服务器命令不包含路由 key ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53312390/