了解默认队列通道/容量行为

时间:2019-05-22 15:01:35

标签: spring-integration

Spring集成优先级通道存在一个奇怪的问题(或者至少在我认为出错的地方)。我有以下流程:

IntegrationFlows
                .from(fileReadingMessageSource,
                        c -> c.poller(Pollers.fixedDelay(period)
                                             .taskExecutor(Executors.newFixedThreadPool(poolSize))
                                             .maxMessagesPerPoll(maxMessagesPerPoll)))
                .channel("alphabetically")
                .bridge(s -> s.poller(Pollers.fixedDelay(100)))
                .channel(ApplicationConfiguration.INBOUND_CHANNEL)
                .get();

以及容量为1'000的优先频道:

@Bean
    public PriorityChannel alphabetically(@Value("${inbound.sort.queue-capacity}") int capacity) {
        return new PriorityChannel(capacity, Comparator.comparing(left -> ((File) left.getPayload()).getName()));
    }

我正在使用此流程从输入目录中读取大约20'000个文件。一切正常,但是在大约2000个文件之后,该流停止工作,并且没有接收任何新文件。

我认为队列通道的默认行为是,当其达到容量时,它将仅等待容量释放并接受将要排队的下一个文件?但是我可能会弄错...如果不是这种情况,并且轮询程序会拾取一些文件并且在优先级通道中没有足够的空间,那么您的建议是如何解决它吗?

1 个答案:

答案 0 :(得分:0)

添加一些日志记录以查看发生了什么;这对我来说很好...

@SpringBootApplication
public class So56259801Application {

    public static void main(String[] args) {
        SpringApplication.run(So56259801Application.class, args);
    }

    private int i;

    @Bean
    public IntegrationFlow flow() {
        return IntegrationFlows.from(() -> "foo" + i++, e -> e.poller(Pollers.fixedDelay(5_000)
                    .taskExecutor(Executors.newFixedThreadPool(1))))
                .log()
                .channel(MessageChannels.queue(3))
                .bridge(b -> b.poller(Pollers.fixedDelay(10_000)))
                .log()
                .get();
    }

}

2019-05-28 13:43:59.719  INFO 75315 --- [pool-1-thread-1] o.s.integration.handler.LoggingHandler   : GenericMessage [payload=foo0, headers={id=d87cba1d-dc6b-fdf4-56ed-61f08048851b, timestamp=1559065439718}]
2019-05-28 13:43:59.719  INFO 75315 --- [ask-scheduler-2] o.s.integration.handler.LoggingHandler   : GenericMessage [payload=foo0, headers={id=d87cba1d-dc6b-fdf4-56ed-61f08048851b, timestamp=1559065439718}]
2019-05-28 13:43:59.724  INFO 75315 --- [           main] com.example.So56259801Application        : Started So56259801Application in 0.832 seconds (JVM running for 1.242)
2019-05-28 13:44:04.719  INFO 75315 --- [pool-1-thread-1] o.s.integration.handler.LoggingHandler   : GenericMessage [payload=foo1, headers={id=8b7676e6-9bac-cdf0-4f4c-38513267b666, timestamp=1559065444719}]
2019-05-28 13:44:09.721  INFO 75315 --- [pool-1-thread-1] o.s.integration.handler.LoggingHandler   : GenericMessage [payload=foo2, headers={id=3b5346f8-d007-dd33-bee3-28eed4cfbd00, timestamp=1559065449721}]
2019-05-28 13:44:10.727  INFO 75315 --- [ask-scheduler-3] o.s.integration.handler.LoggingHandler   : GenericMessage [payload=foo1, headers={id=8b7676e6-9bac-cdf0-4f4c-38513267b666, timestamp=1559065444719}]
2019-05-28 13:44:10.727  INFO 75315 --- [ask-scheduler-3] o.s.integration.handler.LoggingHandler   : GenericMessage [payload=foo2, headers={id=3b5346f8-d007-dd33-bee3-28eed4cfbd00, timestamp=1559065449721}]
2019-05-28 13:44:14.723  INFO 75315 --- [pool-1-thread-1] o.s.integration.handler.LoggingHandler   : GenericMessage [payload=foo3, headers={id=84df8665-1aa9-df90-2037-4dd1781b1bf3, timestamp=1559065454723}]
2019-05-28 13:44:19.727  INFO 75315 --- [pool-1-thread-1] o.s.integration.handler.LoggingHandler   : GenericMessage [payload=foo4, headers={id=4e81897b-a19c-4789-529a-46266762ccc6, timestamp=1559065459727}]
2019-05-28 13:44:21.733  INFO 75315 --- [ask-scheduler-2] o.s.integration.handler.LoggingHandler   : GenericMessage [payload=foo3, headers={id=84df8665-1aa9-df90-2037-4dd1781b1bf3, timestamp=1559065454723}]
2019-05-28 13:44:21.733  INFO 75315 --- [ask-scheduler-2] o.s.integration.handler.LoggingHandler   : GenericMessage [payload=foo4, headers={id=4e81897b-a19c-4789-529a-46266762ccc6, timestamp=1559065459727}]
2019-05-28 13:44:24.730  INFO 75315 --- [pool-1-thread-1] o.s.integration.handler.LoggingHandler   : GenericMessage [payload=foo5, headers={id=3fb96f4a-7d25-f94a-23d2-d4a121932554, timestamp=1559065464730}]
相关问题