Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 与Executor的Spring Integration DSL自定义错误通道问题_Java_Spring Boot_Spring Integration_Spring Integration Dsl_Spring Integration File - Fatal编程技术网

Java 与Executor的Spring Integration DSL自定义错误通道问题

Java 与Executor的Spring Integration DSL自定义错误通道问题,java,spring-boot,spring-integration,spring-integration-dsl,spring-integration-file,Java,Spring Boot,Spring Integration,Spring Integration Dsl,Spring Integration File,您好,我有一个文件侦听器,它一次并行读取多个文件 package com.example.demo.flow; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Bean; import org.springframework.integration.dsl.*; import org.springframework.integration.dsl.channel.MessageCha

您好,我有一个文件侦听器,它一次并行读取多个文件

package com.example.demo.flow;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.dsl.*;
import org.springframework.integration.dsl.channel.MessageChannels;
import org.springframework.integration.file.dsl.Files;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.concurrent.Executors;

/**
 * Created by muhdk on 03/01/2020.
 */
@Component
@Slf4j
public class TestFlow {

    @Bean
    public StandardIntegrationFlow errorChannelHandler() {

        return IntegrationFlows.from("testChannel")
                .handle(o -> {

                    log.info("Handling error....{}", o);
                }).get();
    }

    @Bean
    public IntegrationFlow testFile() {


        IntegrationFlowBuilder testChannel = IntegrationFlows.from(Files.inboundAdapter(new File("d:/input-files/")),
                e -> e.poller(Pollers.fixedDelay(5000L).maxMessagesPerPoll(5)
                        .errorChannel("testChannel")))
                .channel(MessageChannels.executor(Executors.newFixedThreadPool(5)))
                .transform(o -> {

                    throw new RuntimeException("Failing on purpose");

                }).handle(o -> {
                });

        return testChannel.get();


    }


}
它不会转到我的自定义错误频道

但是如果我把线移走

            .channel(MessageChannels.executor(Executors.newFixedThreadPool(5)))
然后它进入错误通道


我如何使它工作,使它与executor一起进入我的自定义错误通道。

当使用executor服务处理多条消息时,它与正常的错误通道不工作,我不知道为什么

我做了这样的改变

@Bean
public IntegrationFlow testFile() {


    IntegrationFlowBuilder testChannel = IntegrationFlows.from(Files.inboundAdapter(new File("d:/input-files/")),
            e -> e.poller(Pollers.fixedDelay(5000L).maxMessagesPerPoll(10)
            ))
            .enrichHeaders(h -> h.header(MessageHeaders.ERROR_CHANNEL, "testChannel"))
            .channel(MessageChannels.executor(Executors.newFixedThreadPool(5)))

            .transform(o -> {

                throw new RuntimeException("Failing on purpose");

            }).handle(o -> {
            });

    return testChannel.get();


}
这里的队伍

        .enrichHeaders(h -> h.header(MessageHeaders.ERROR_CHANNEL, "testChannel"))

其余部分保持不变,并且有效。

您发现解决问题的方法是正确的。由于您将工作转移到完全不同的线程,因此无法通过启动轮询器中的
try..catch
捕获该线程中的异常。该轮询线程没有任何错误!因此,将错误通道添加到头中是一种方法。我们不能在框架中自己这样做,因为我们不能假设它是您一直想要做的。因此,您必须自己做出决定并应用解决方案。请参阅文档中的更多内容: