简体   繁体   English

为什么SFTP入站/出站通道适配器有单独的通道声明,为什么没有简单文件入站/出站通道适配器的通道声明?

[英]Why there is separate channel declaration for SFTP inbound/outbound channel adapter and why not for simple file inbound/outbound channel adapter?

I have developed a code going through Spring Integration File Support tutorial, in which I am polling files from specific location and processing them further. 我已经开发了通过Spring Integration File Support教程的代码,其中我从特定位置轮询文件并进一步处理它们。 For polling purpose I have used Spring Integration's Inbound and Outbound channel adapters so I have my bean.xml for the same as below: 为了进行轮询,我使用了Spring Integration的入站和出站通道适配器,因此我的bean.xml如下所示:

        <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:integration="http://www.springframework.org/schema/integration"
            xmlns:file="http://www.springframework.org/schema/integration/file"
            xsi:schemaLocation="http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans.xsd
                    http://www.springframework.org/schema/integration
                    http://www.springframework.org/schema/integration/spring-integration.xsd
                    http://www.springframework.org/schema/integration/file
                    http://www.springframework.org/schema/integration/file/spring-integration-file.xsd">
            <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
            <file:inbound-channel-adapter id="filesIn"
                directory="file:${java.io.tmpdir}/input">
                <integration:poller id="poller" fixed-rate="60000" />
            </file:inbound-channel-adapter>
            <integration:service-activator
                input-channel="filesIn" output-channel="filesOut" ref="handler" />
            <file:outbound-channel-adapter id="filesOut"
                directory="file:${java.io.tmpdir}/archive" delete-source-files="true">
            </file:outbound-channel-adapter>
            <bean id="handler" class="com.m.c.Handler" />
        </beans>

Now my main class is: 现在我的主要课程是:

    @SpringBootConfiguration
    @EnableScheduling
    public class App{
        private static final Log LOGGER = LogFactory.getLog(App.class);

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

        @Scheduled(fixedDelay = 60000)
        public static void display() throws InvalidFormatException, IOException{
            ApplicationContext context = new ClassPathXmlApplicationContext("/spring/integration/bean.xml", App.class);
            File inDir = (File) new DirectFieldAccessor(context.getBean(FileReadingMessageSource.class)).getPropertyValue("directory");
            LiteralExpression expression = (LiteralExpression) new DirectFieldAccessor(context.getBean(FileWritingMessageHandler.class)).getPropertyValue("destinationDirectoryExpression");
            File outDir = new File(expression.getValue());
            LOGGER.info("Input directory is: " + inDir.getAbsolutePath());
            LOGGER.info("Archive directory is: " + outDir.getAbsolutePath());
            LOGGER.info("===================================================");
        }
    }

and there is a Handler class for processing the files, this is working fine for me. 并且有一个用于处理文件的Handler类,这对我来说很好。

Now the question is I want to make the same mechanism for SFTP remote server and poll the file from that location and put the processed files on the same SFTP location in different folder. 现在的问题是,我想对SFTP远程服务器使用相同的机制,并从该位置轮询文件,然后将处理后的文件放在不同文件夹中的同一SFTP位置。

So I configured my bean.xml accordingly and wrote inbound and outbound channel adapters for SFTP. 因此,我相应地配置了bean.xml并为SFTP编写了入站和出站通道适配器。 When I came to the service-activator part I found that I need to configure separate channels for Inbound and Outbound channel adapters and give their id's in service-activator which I didn't see in simple file poller which is working fine. 当我进入服务激活器部分时,我发现我需要为入站和出站通道适配器配置单独的通道,并在服务激活器中提供它们的ID,而在简单的文件轮询器中却看不到它的正常运行。 So why separate channels are needed for inbound and outbound channel adapters? 那么,为什么入站和出站通道适配器需要单独的通道? And if they are required how do we implement the same for a Scheduled file polling service? 如果需要它们,我们如何为计划文件轮询服务实现相同的功能?

You don't show the configuration in question, so I am not sure exactly what you are asking, but channel on channel adapters is optional; 你不显示有问题的配置,所以我你是问不知道到底是什么,但channel上的通道适配器是可选的; if omitted, the channel name is the same as the id . 如果省略,则通道名称与id相同。 But there's always a channel. 但是总有一个渠道。 Whether or not you need to actually declare the channel depends on the consumer side. 是否需要实际声明频道取决于用户方。

If you explicitly use channel on an outbound adapter, you need to declare the channel. 如果您在出站适配器上显式使用channel ,则需要声明该通道。 It's not necessary on the inbound adapter because the service activator will automatically declare its input channel, if not present. 不需要在入站适配器上,因为服务激活器将自动声明其输入通道(如果不存在)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM