在弹簧积分流中集成可轮询通道

时间:2015-07-17 14:22:53

标签: spring-integration

如何在Integration流中集成Pollable通道。因为我的流程使用的是NullChannel而不是Pollable Channel。     有人可以在此提供任何指针。

This is my Integration flow.

    @Bean
    public IntegrationFlow sftpInboundFlow() {
        System.out.println("enter sftpInboundFlow....."
                + sftpSessionFactory.getSession());
        System.out.println("the channel is " + sftpInboundResultChannel);
        return IntegrationFlows
                .from(Sftp.inboundAdapter(this.sftpSessionFactory)
                        .preserveTimestamp(true).remoteDirectory(remDir)
                        .regexFilter(".*\\.txt$")
                        .localFilenameExpression("#this.toUpperCase()")
                        .localDirectory(new File(localDir))
                        .remoteFileSeparator("/"),
                        new Consumer<SourcePollingChannelAdapterSpec>() {
                            @Override
                            public void accept(SourcePollingChannelAdapterSpec e) {
                                e.id("sftpInboundAdapter")
                                        .autoStartup(true)
                                        .poller(Pollers.fixedRate(1000)
                                                .maxMessagesPerPoll(1));
                            }
                        })
                .channel(MessageChannels.queue("sftpInboundResultChannel"))
                .get();
    }


And I want to use this..

    @Autowired  
    private PollableChannel sftpInboundResultChannel; 
    in the .channel() method.

原木是...... [2015-07-22 18:48:05.497] - 2796 INFO [main] --- com.jcraft.jsch: SSH_MSG_NEWKEYS sent [2015-07-22 18:48:05.497] - 2796 INFO [main] --- com.jcraft.jsch: SSH_MSG_NEWKEYS received [2015-07-22 18:48:05.500] - 2796 INFO [main] --- com.jcraft.jsch: SSH_MSG_SERVICE_REQUEST sent [2015-07-22 18:48:05.501] - 2796 INFO [main] --- com.jcraft.jsch: SSH_MSG_SERVICE_ACCEPT received [2015-07-22 18:48:15.517] - 2796 INFO [main] --- com.jcraft.jsch: Authentications that can continue: gssapi-with-mic,publickey,keyboard-interactive,password [2015-07-22 18:48:15.517] - 2796 INFO [main] --- com.jcraft.jsch: Next authentication method: gssapi-with-mic [2015-07-22 18:48:15.522] - 2796 INFO [main] --- com.jcraft.jsch: Authentications that can continue: publickey,keyboard-interactive,password [2015-07-22 18:48:15.522] - 2796 INFO [main] --- com.jcraft.jsch: Next authentication method: publickey [2015-07-22 18:48:15.523] - 2796 INFO [main] --- com.jcraft.jsch: Authentications that can continue: password [2015-07-22 18:48:15.523] - 2796 INFO [main] --- com.jcraft.jsch: Next authentication method: password [2015-07-22 18:48:15.537] - 2796 INFO [main] --- com.jcraft.jsch: Authentication succeeded (password). enter sftpSessionFactory.....org.springframework.integration.sftp.session.SftpSession@1ffcd26 enter sftpInboundFlow.....org.springframework.integration.sftp.session.SftpSession@13a462c the channel is org.springframework.integration.channel.NullChannel@d532ee [2015-07-22 18:48:15.827] - 2796 INFO [main] --- org.springframework.context.support.DefaultLifecycleProcessor: Starting beans in phase -2147483648 [2015-07-22 18:48:15.828] - 2796 INFO [main] --- org.springframework.context.support.DefaultLifecycleProcessor: Starting beans in phase 0 [2015-07-22 18:48:15.828] - 2796 INFO [main] --- org.springframework.integration.endpoint.EventDrivenConsumer: Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel [2015-07-22 18:48:15.828] - 2796 INFO [main] --- org.springframework.integration.channel.PublishSubscribeChannel: Channel 'application.errorChannel' has 1 subscriber(s). [2015-07-22 18:48:15.829] - 2796 INFO [main] --- org.springframework.integration.endpoint.EventDrivenConsumer: started _org.springframework.integration.errorLogger [2015-07-22 18:48:15.829] - 2796 INFO [main] --- org.springframework.context.support.DefaultLifecycleProcessor: Starting beans in phase 1073741823 [2015-07-22 18:48:15.832] - 2796 INFO [main] --- org.springframework.integration.endpoint.SourcePollingChannelAdapter: started sftpInboundAdapter [2015-07-22 18:48:15.834] - 2796 INFO [main] --- src.MainSftpInBoundDsl: Started MainSftpInBoundDsl in 11.019 seconds (JVM running for 11.182) enter main..... enter main..... [2015-07-22 18:48:16.040] - 2796 INFO [task-scheduler-1] --- org.springframework.integration.file.FileReadingMessageSource: Created message: [GenericMessage [payload=D:\local_copy\AMARJEET.TXT, headers={timestamp=1437571096040, id=ddc20f6d-26ee-7eef-f59e-b5207dcdc8c7}]] [2015-07-22 18:48:16.832] - 2796 INFO [task-scheduler-1] --- org.springframework.integration.file.FileReadingMessageSource: Created message: [GenericMessage [payload=D:\local_copy\INFO.TXT, headers={timestamp=1437571096832, id=361b55d5-884e-9001-d513-ddc81926bf85}]] [2015-07-22 18:48:17.832] - 2796 INFO [task-scheduler-2] --- org.springframework.integration.file.FileReadingMessageSource: Created message: [GenericMessage [payload=D:\local_copy\KKKK.TXT, headers={timestamp=1437571097832, id=49deb17c-50e3-4315-dfa2-cc443a35bd1c}]] [2015-07-22 18:48:18.832] - 2796 INFO [task-scheduler-1] --- org.springframework.integration.file.FileReadingMessageSource: Created message: [GenericMessage [payload=D:\local_copy\LA.TXT, headers={timestamp=1437571098832, id=88def298-ab86-1d63-039e-c81c70ae6819}]] [2015-07-22 18:48:19.832] - 2796 INFO [task-scheduler-3] --- org.springframework.integration.file.FileReadingMessageSource: Created message: [GenericMessage [payload=D:\local_copy\POC.TXT, headers={timestamp=1437571099832, id=d78b36eb-10f5-ce83-ba4c-cd24a806480b}]] [2015-07-22 18:48:20.832] - 2796 INFO [task-scheduler-2] --- org.springframework.integration.file.FileReadingMessageSource: Created message: [GenericMessage [payload=D:\local_copy\PPPP.TXT, headers={timestamp=1437571100832, id=4e727ebb-b4de-be19-6a92-afb3be24576f}]] [2015-07-22 18:48:21.832] - 2796 INFO [task-scheduler-4] --- org.springframework.integration.file.FileReadingMessageSource: Created message: [GenericMessage [payload=D:\local_copy\REFERENCE.TXT, headers={timestamp=1437571101832, id=3d611371-431c-6b1e-0e17-377f5607de96}]] [2015-07-22 18:48:22.831] - 2796 INFO [task-scheduler-1] --- org.springframework.integration.file.FileReadingMessageSource: Created message: [GenericMessage [payload=D:\local_copy\RRRRR.TXT, headers={timestamp=1437571102831, id=707e566c-ccfa-6c32-16d6-1f27ec73abaf}]] [2015-07-22 18:48:23.832] - 2796 INFO [task-scheduler-5] --- org.springframework.integration.file.FileReadingMessageSource: Created message: [GenericMessage [payload=D:\local_copy\SFTP.TXT, headers={timestamp=1437571103832, id=b3c979ff-fcd2-e1ff-8b37-6b8f2803637a}]] [2015-07-22 18:48:24.832] - 2796 INFO [task-scheduler-3] --- org.springframework.integration.file.FileReadingMessageSource: Created message: [GenericMessage [payload=D:\local_copy\TEST.TXT, headers={timestamp=1437571104832, id=98d43e62-8e5f-69bc-7617-4706761eaf86}]] [2015-07-22 18:48:25.832] - 2796 INFO [task-scheduler-3] --- org.springframework.integration.file.FileReadingMessageSource: Created message: [GenericMessage [payload=D:\local_copy\XSS.TXT, headers={timestamp=1437571105832, id=77b28259-0287-0ef5-825f-5345d6c21c21}]] [2015-07-22 18:48:26.832] - 2796 INFO [task-scheduler-3] --- org.springframework.integration.file.FileReadingMessageSource: Created message: [GenericMessage [payload=D:\local_copy\ZZZZ.TXT, headers={timestamp=1437571106832, id=b5644a62-8c8c-86d2-e016-75fff01c70b4}]]

1 个答案:

答案 0 :(得分:2)

直接在流程中使用自动装配字段......

.channel(this.sftpInboundResultChannel)

修改

看起来MessageChannels.queue("sftpInboundResultChannel")没有将频道注册为bean,因此Spring将NullChannel自动装入该字段(因为它是上下文中唯一的PollableChannel)。

我们需要看一看;在此期间,添加

@Bean
public PollableChannel sftpInboundResultChannel() {
    return new QueueChannel();
}