首页 > 解决方案 > 如何在 Spring 集成中将两个(对象和列表)发送到转换器

问题描述

入站流.Java

@Bean
public IntegrationFlow SampleFlow(ConnectionFactory jmsListenerConnectionFactory,
        MarshallingJmsMessageConverter sampleJmsMessageConverter,
        JmsMessageListenerContainerConfigurer jmsMessageListenerContainerConfigurer) {
    return IntegrationFlows
            .from(Jms
                    .messageDrivenChannelAdapter(
                            jmsMessageListenerContainerConfigurer.configure(Jms.container(jmsListenerConnectionFactory,
                                    jmsDestinationsProperties.getName().get("queueName"))).get())
                    .jmsMessageConverter(sampleJmsMessageConverter)
                    .errorChannel(errorChannelProperties.getChannel()))
                    .channel("inbound-channel").get();
}

集成流.Java

@Bean
public IntegrationFlow sampleransformationFlow(LinkagesDataService1 service1,
        LinkagesDataService2 service2, aProperties properties) {
    return IntegrationFlows.from("inbound-channel")
            .transform(Transformers.converter(
                    new MyConverterClass(service1, service2, properties)))
            .channel("outbound-channel").get();
}

入站流.java

@Bean
public IntegrationFlow psampleProducerFlow(ServiceBusClientFactory clientFactory) {
    return IntegrationFlows.from("outbound-channel").enrichHeaders(h -> h.headerExpression(
            ServiceBusHeaders.SESSION_ID,
            "payload.value1 + payload.value2"))
            .handle(ServiceBus.outboundChannelAdapter(clientFactory).entityId("SAMPLE")).get();
}

我的问题是:上面的代码正在执行正常流程,没有任何问题。但是在发布输入文件时,如果没有找到特定的字段,那么我们需要为Error POJO类设置errorCode、description等。我已经完成了那部分..现在,我需要知道如何从转换器发送 normalFlow 和 errorFlow ......另外,我需要按原样发送 normalflow,如果找不到字段,那么值也需要是转移到话题。(它实际上没有问题地这样做)。

如果未找到特定字段,则应发生正常流,并且 erroFlow 应捕获 erroCode、Desc 等并需要移动到错误主题。.

现在我有一个 normalFlow 对象,以及同一个转换类中的 errorFlow 列表。如何将这 2 个(对象和列表)返回给转换器。如何在积分中做条件发送 normalFlow,还需要检查列表是否为 =1 />1 。如果是,则将错误 json 移至 TOPIC 或 null。

请帮忙。

标签: javaspring-bootmicroservicesspring-integrationchannel

解决方案


推荐阅读