【发布时间】:2020-06-14 12:05:31
【问题描述】:
我使用IntegrationFlow 作为Sftp 入站DSL 配置,我使用CustomTriggerAdvice 来处理手动触发。请参阅下面的代码 sn-p 以供参考。
我还使用RotatingServerAdvice 来处理同一主机中的多个路径。
但是当我启动 Sftp Inbound 时,它会第一次从每个路径中获取文件,但第二次以后就无法正常工作了。 Sftp Inbound 启动但不从路径中获取文件。我无法找出问题所在。有什么我想念的吗?
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();
}
... ... ...
@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();
}
CustomTriggerAdvice
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;
}
}
使用 MessageChannel 启动 Sftp Inbound
@Qualifier("customControlChannel") MessageChannel controlChannel;
public void startSftpInbound(){
controlChannel.send(new GenericMessage<>("@" + beanID + ".start()"));
}
【问题讨论】:
-
你的
CustomTriggerAdvice用BEAN_ID停止你的SourcePollingChannelAdapter为你的SftpInboundChannelAdapterSpec,但我看不出你在哪里称呼它startSftpInbound()... -
我已经尝试了各种 DEBUG 并且我找不到任何东西,并且很确定之前没有获取文件并且文件没有存储在 @987654335 @.
-
它照常工作。它会在轮询每个路径后立即获取新文件。
-
是的。当我从
afterReceive()中删除controlChannel.send(new GenericMessage<>("@" + BEAN_ID + ".stop()"));时,它正在工作,它重新启动并获取新文件。我使用手动触发器来停止 Sftp Inbound。 -
希望你明白我的逻辑,以及在轮询每个目录至少一次后我想如何使用 stop Sftp Inbound。
标签: java spring spring-integration dsl spring-integration-sftp