Проблема с каналом нестандартной ошибки Spring Integration DSL в Executor - PullRequest
0 голосов
/ 19 января 2020

Привет! У меня есть прослушиватель файлов, который читает файлы параллельно / более чем по одному за раз

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)))

Затем он переходит на канал ошибок.

Как я могу заставить его работать так, чтобы он go передавал мой пользовательский канал ошибок с executor.

1 Ответ

0 голосов
/ 21 января 2020

Похоже, что при использовании служб Executor с несколькими сообщениями он не работает с обычным errorChannel, который я понятия не имею, почему

Я сделал такое изменение

@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"))

Остальное остается прежним и все работает.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...