将动态目录添加到 RotatingServerAdvice Spring 集成

Add Dynamic Directory to RotatingServerAdvice Spring Integration

我正在尝试使用 RotatingServerAdvice 从多个资源中轮询新文件。我有一个新要求,即对于每个新客户端,都会在 sftp 服务器中创建一个新目录,我也想将该目录添加到轮询中。所以我将使用 int-sftp:outbound-gateway 查询所有目录并检查是否创建了新目录,然后将新目录添加到关键目录。这样可能吗?谢谢。

@Bean
public RotatingServerAdvice advice() {
  List<RotationPolicy.KeyDirectory> keyDirectories = new ArrayList<>();
  keyDirectories.add(new RotationPolicy.KeyDirectory("one", "foo"));
  keyDirectories.add(new RotationPolicy.KeyDirectory("one", "bar"));
  keyDirectories.add(new RotationPolicy.KeyDirectory("two", "baz"));
  keyDirectories.add(new RotationPolicy.KeyDirectory("two", "qux"));
  keyDirectories.add(new RotationPolicy.KeyDirectory("three", "fiz"));
  keyDirectories.add(new RotationPolicy.KeyDirectory("three", "buz"));
  return new RotatingServerAdvice(delegatingSf(), keyDirectories);
}

默认StandardRotationPolicy是不可能的;您需要提供自定义 RotationPolicy.

/**
 * Construct an instance that rotates according to the supplied
 * {@link RotationPolicy}.
 * @param rotationPolicy the policy.
 */
public RotatingServerAdvice(RotationPolicy rotationPolicy) {
    Assert.notNull(rotationPolicy, "'rotationPolicy' cannot be null");
    this.rotationPolicy = rotationPolicy;
}

您或许可以从 StandardRotationPolicy 作为模型开始。