Java Spring集成DSL中的消息类型安全

Java Spring集成DSL中的消息类型安全,java,spring-boot,spring-integration,Java,Spring Boot,Spring Integration,如果我以这种方式定义Jms集成流,有没有办法避免在处理程序中强制转换消息类型?或者我应该以另一种方式实现JMS集成 @EnableJms @EnableIntegration @Configuration public class JmsInboundFlow { private Logger logger = LoggerFactory.getLogger(JmsInboundFlow.class); @Autowired public ConnectionFactory jmsConnec

如果我以这种方式定义Jms集成流,有没有办法避免在处理程序中强制转换消息类型?或者我应该以另一种方式实现JMS集成

@EnableJms
@EnableIntegration
@Configuration
public class JmsInboundFlow {
private Logger logger = LoggerFactory.getLogger(JmsInboundFlow.class);

@Autowired
public ConnectionFactory jmsConnectionFactory;

@Autowired
private JmsMessageMyPojoHandlerService handlerService;

@Bean
public IntegrationFlow jmsMessageDrivenFlow() {
    return IntegrationFlows.from(messageDrivenChannelAdapter(jmsConnectionFactory).destination("queuName")
            .errorChannel(jmsMyPojoErrorChannel()))
            .transform(Transformers.fromJson(MyPojo.class))
            .handle(message -> handlerService.addEvent((Message<MyPojo>) message))
            .get();
}

@Bean
public MessageChannel jmsMyPojoErrorChannel() {
    return MessageChannels.direct("customErrorChannel")
            .get();
}

@Bean
public IntegrationFlow customErrorFlow() {
    return IntegrationFlows.from(jmsMyPojoErrorChannel())
            .handle(msg -> logger.error("Error processing JMS message " + msg.getPayload()))
            .get();
}
}
@EnableJms
@使能集成
@配置
公共类JmsInboundFlow{
私有记录器Logger=LoggerFactory.getLogger(JmsInboundFlow.class);
@自动连线
公共连接工厂JMS连接工厂;
@自动连线
私人JmsMessageMyPojoHandlerService handlerService;
@豆子
公共集成流jmsMessageDrivenFlow(){
返回IntegrationFlows.from(messageDrivenChannelAdapter(jmsConnectionFactory).destination(“queuName”)
.errorChannel(jmsMyPojoErrorChannel())
.transform(Transformers.fromJson(MyPojo.class))
.handle(消息->handlerService.addEvent((消息)消息))
.get();
}
@豆子
公共消息频道jmsMyPojoErrorChannel(){
返回MessageChannels.direct(“customErrorChannel”)
.get();
}
@豆子
公共集成流customErrorFlow(){
返回IntegrationFlows.from(jmsMyPojoErrorChannel())
.handle(msg->logger.error(“错误处理JMS消息”+msg.getPayload()))
.get();
}
}

您可以使用
.handle(服务、方法)
variant-框架将为您提供适当的强制转换。

fluent builder似乎不是类型安全的,但我不知道为什么