Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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 如何解决“RotatingServerAdvice”多次未提取文件的问题?_Java_Spring_Spring Integration_Dsl_Spring Integration Sftp - Fatal编程技术网

Java 如何解决“RotatingServerAdvice”多次未提取文件的问题?

Java 如何解决“RotatingServerAdvice”多次未提取文件的问题?,java,spring,spring-integration,dsl,spring-integration-sftp,Java,Spring,Spring Integration,Dsl,Spring Integration Sftp,我使用IntegrationFlow作为Sftp入站DSL配置使用CustomTriggerAdvice处理手动触发。请参阅下面的代码片段以供参考 我还使用RotatingServerAdvice处理同一主机中的多个路径 但是,当我启动sftpinbound时,它第一次从每个路径获取文件,但第二次和以后都不起作用。Sftp入站启动,但不从路径获取文件。我想不出这个问题。有什么我遗漏的吗 SftpConfiguration public IntegrationFlow fileFlow() {

我使用
IntegrationFlow
作为Sftp入站DSL配置使用
CustomTriggerAdvice
处理手动触发。请参阅下面的代码片段以供参考

我还使用
RotatingServerAdvice
处理同一主机中的多个路径

但是,当我启动sftpinbound时,它第一次从每个路径获取文件,但第二次和以后都不起作用。Sftp入站启动,但不从路径获取文件。我想不出这个问题。有什么我遗漏的吗

SftpConfiguration

public IntegrationFlow fileFlow() {
    SftpInboundChannelAdapterSpec spec = Sftp
            .inboundAdapter(dSF())
            .preserveTimestamp(true)
            .remoteDirectory(".")
            .autoCreateLocalDirectory(true)
            .deleteRemoteFiles(false)
            .localDirectory(new File(getDestinationLocation()));

    return IntegrationFlows
            .from(spec, e -> e.id(BEAN_ID)
                    .autoStartup(false)
                    .poller(Pollers
                            .fixedDelay(5000)
                            .advice(
                                    customRotatingServerAdvice(dSF()),
                                    customTriggerAdvice()
                            )
                    )
            )
            .channel(sftpReceiverChannel())
            .handle(sftpInboundMessageHandler())
            .get();
}

private MessageChannel sftpReceiverChannel() {
    return MessageChannels.direct().get();
}
public class CustomTriggerAdvice extends AbstractMessageSourceAdvice {
    private final MessageChannel controlChannel;
    private final String BEAN_ID;

    public CustomTriggerAdvice(MessageChannel controlChannel, String beanID) {
        this.controlChannel = controlChannel;
        this.BEAN_ID = beanID;
    }

    @Override
    public boolean beforeReceive(MessageSource<?> source) {
        return true;
    }

    @Override
    public Message<?> afterReceive(Message<?> result, MessageSource<?> source) {
        if (result == null) {
            controlChannel.send(new GenericMessage<>("@" + BEAN_ID + ".stop()"));
        } 
        return result;
    }
}

@Bean
public RotatingServerAdvice customRotatingServerAdvice(
      DelegatingSessionFactory<LsEntry> dSF
) {
    List<String> pathList = getSourcePathList();
    for (String path : pathList) {
        keyDirectories.add(new RotationPolicy.KeyDirectory(KEY, path));
    }

    return new RotatingServerAdvice(
            dSF,
            keyDirectories
    );
}

@Bean
public CustomTriggerAdvice customTriggerAdvice() {
    return new CustomTriggerAdvice(customControlChannel(),BEAN_ID);
}


@Bean
public IntegrationFlow customControlBus() {
    return IntegrationFlows.from(customControlChannel())
            .controlBus()
            .get();
}


@Bean
public MessageChannel customControlChannel() {
    return MessageChannels.direct().get();
}
使用MessageChannel启动Sftp入站

@Qualifier("customControlChannel") MessageChannel controlChannel;


public void startSftpInbound(){
       controlChannel.send(new GenericMessage<>("@" + beanID + ".start()"));
}
@限定符(“customControlChannel”)消息通道控制通道;
public void startSftpInbound(){
发送(新的GenericMessage(“@”+beanID+”.start()”);
}
我需要系统启动的需求和获取文件完成一个周期。如果之后没有停止,它将继续轮询,不会停止,我的系统将陷入无限循环。当RotatingServerAdvice至少从一台服务器完成所有服务器的轮询时,是否有任何方法可以实现这一点?它会抛出任何事件或类似的东西吗

您可能误解了afterReceive(@Nullable Message result,MessageSource source)契约的逻辑。当其中一台服务器未返回任何要轮询的内容时,无法根据您的要求停止通道适配器。这样,您就没有机会让其他服务器在下一个轮询周期进行轮询


我认为您的想法是只在所有服务器上迭代一次,然后停止。可能与它们的结果无关。看起来最好的停止方式是使用
RotatingServerAdvice
fair=true
每次移动到下一台服务器。当您看到
RotationPolicy.getCurrent()
与列表中的最后一个相等时,可以从自定义的
afterReceive()
执行停止,而不依赖于结果。因此,通过这种方式,您可以迭代所有这些参数,并停止在下一个极化周期中移动第一个参数。

您的
CustomTriggerAdvice
使用
BEAN\u ID
停止
SourcePollingChannelAdapter
SftpInboundChannelAdapterSpec
,但我看不出您将其称为
StartSpinBound()
…我尝试了各种调试,但找不到任何东西,并且非常确定以前没有获取该文件,并且该文件没有存储在
元数据存储中。
。它正常工作。它会在轮询每个路径后的一瞬间获取新文件。是的。当我删除
controlChannel.send(新的GenericMessage(“@”+BEAN\u ID+”.stop()”)时,它就开始工作了
afterReceive()
重新启动并获取新文件。我使用手动触发器停止Sftp入站。希望您了解我的逻辑,以及在至少轮询每个目录一次后如何使用stop Sftp入站。是否有类似于
RotationPolicy.getCurrent()
的内容?或者在何处找到此
RotationPolicy.getCurrent()
RotatingServerAdvice
具有
RotationPolicy
属性。您需要覆盖带有
afterReceive()
的自定义
RotatingServerAdvice
,以执行逻辑,确保您处于停止通道适配器的状态。