Spring integration Spring集成dsl:按有效负载类型的路由

Spring integration Spring集成dsl:按有效负载类型的路由,spring-integration,Spring Integration,鉴于: return from(listenerContainer(connectionFactory, queue)) .handle(Foo.class, new HandlerForFoo()).get(); } 如果通道接收到类型为Bar.class的有效负载,如何使其调用HandlerForBar?我的意思是这样的: return from(listenerContainer(connectionFactory, queue))

鉴于:

   return from(listenerContainer(connectionFactory, queue))
             .handle(Foo.class, new HandlerForFoo()).get();
}
如果通道接收到类型为Bar.class的有效负载,如何使其调用HandlerForBar?我的意思是这样的:

      return from(listenerContainer(connectionFactory, queue))
             .handle(Bar.class, new HandlerForBar());
             .handle(Foo.class, new HandlerForFoo()).get();
}
.<Object, Class<?>>route(Object::getClass, m -> m
        .subFlowMapping(Bar.class, sf -> sf.handle(new HandlerForBar())
        .subFlowMapping(Foo.class, sf -> sf.handle(new HandlerForFoo())

这样不行。流定义假定第二个
.handle()
在第一个之后

对于您的
负载类型
目的,有一种特殊的企业集成模式-

Spring集成提供了关于这个问题的特定实现-

通过Spring Integration Java DSL,我们可以通过以下方式满足您的需求:

      return from(listenerContainer(connectionFactory, queue))
             .handle(Bar.class, new HandlerForBar());
             .handle(Foo.class, new HandlerForFoo()).get();
}
.<Object, Class<?>>route(Object::getClass, m -> m
        .subFlowMapping(Bar.class, sf -> sf.handle(new HandlerForBar())
        .subFlowMapping(Foo.class, sf -> sf.handle(new HandlerForFoo())

。上述代码不应使用
.getName()
,或使用
而不是
修复。非常感谢。