Example usage for org.springframework.integration.dsl Pollers fixedDelay

List of usage examples for org.springframework.integration.dsl Pollers fixedDelay

Introduction

In this page you can find the example usage for org.springframework.integration.dsl Pollers fixedDelay.

Prototype

public static PollerSpec fixedDelay(long period) 

Source Link

Usage

From source file:org.springframework.integration.ftp.dsl.FtpTests.java

@Test
public void testFtpInboundFlow() {
    QueueChannel out = new QueueChannel();
    IntegrationFlow flow = IntegrationFlows.from(
            Ftp.inboundAdapter(sessionFactory()).preserveTimestamp(true).remoteDirectory("ftpSource")
                    .regexFilter(".*\\.txt$").localFilename(f -> f.toUpperCase() + ".a")
                    .localDirectory(getTargetLocalDirectory()),
            e -> e.id("ftpInboundAdapter").poller(Pollers.fixedDelay(100))).channel(out).get();
    IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
    Message<?> message = out.receive(10_000);
    assertNotNull(message);/*from   w  w w  . j av a2  s .c  o  m*/
    Object payload = message.getPayload();
    assertThat(payload, instanceOf(File.class));
    File file = (File) payload;
    assertThat(file.getName(), isOneOf(" FTPSOURCE1.TXT.a", "FTPSOURCE2.TXT.a"));
    assertThat(file.getAbsolutePath(), containsString("localTarget"));

    message = out.receive(10_000);
    assertNotNull(message);
    file = (File) message.getPayload();
    assertThat(file.getName(), isOneOf(" FTPSOURCE1.TXT.a", "FTPSOURCE2.TXT.a"));
    assertThat(file.getAbsolutePath(), containsString("localTarget"));

    assertNull(out.receive(10));

    File remoteFile = new File(this.sourceRemoteDirectory, " " + prefix() + "Source1.txt");
    remoteFile.setLastModified(System.currentTimeMillis() - 1000 * 60 * 60 * 24);

    message = out.receive(10_000);
    assertNotNull(message);
    payload = message.getPayload();
    assertThat(payload, instanceOf(File.class));
    file = (File) payload;
    assertEquals(" FTPSOURCE1.TXT.a", file.getName());

    registration.destroy();
}

From source file:org.springframework.integration.ftp.dsl.FtpTests.java

@Test
public void testFtpInboundStreamFlow() throws Exception {
    QueueChannel out = new QueueChannel();
    StandardIntegrationFlow flow = IntegrationFlows.from(
            Ftp.inboundStreamingAdapter(new FtpRemoteFileTemplate(sessionFactory()))
                    .remoteDirectory("ftpSource").regexFilter(".*\\.txt$"),
            e -> e.id("ftpInboundAdapter").poller(Pollers.fixedDelay(100))).channel(out).get();
    IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
    Message<?> message = out.receive(10_000);
    assertNotNull(message);/* w  w  w.  j  a  va  2  s.c om*/
    assertThat(message.getPayload(), instanceOf(InputStream.class));
    assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE), isOneOf(" ftpSource1.txt", "ftpSource2.txt"));
    new IntegrationMessageHeaderAccessor(message).getCloseableResource().close();

    message = out.receive(10_000);
    assertNotNull(message);
    assertThat(message.getPayload(), instanceOf(InputStream.class));
    assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE), isOneOf(" ftpSource1.txt", "ftpSource2.txt"));
    new IntegrationMessageHeaderAccessor(message).getCloseableResource().close();

    registration.destroy();
}

From source file:org.springframework.integration.samples.filesplit.Application.java

/**
 * Poll for files, add an error channel, split into lines route the start/end markers
 * to {@link #markers()} and the lines to {@link #lines}.
 *
 * @return the flow.//ww w.  j a  v a2  s . c  o m
 */
@Bean
public IntegrationFlow fromFile() {
    return IntegrationFlows
            .from(Files.inboundAdapter(new File("/tmp/in")).preventDuplicates(false).patternFilter("*.txt"),
                    e -> e.poller(Pollers.fixedDelay(5000).errorChannel("tfrErrors.input"))
                            .id("fileInboundChannelAdapter"))
            .handle(Files.splitter(true, true))
            .<Object, Class<?>>route(Object::getClass,
                    m -> m.channelMapping(FileSplitter.FileMarker.class, "markers.input")
                            .channelMapping(String.class, "lines.input"))
            .get();
}

From source file:org.springframework.integration.samples.mqtt.Application.java

@Bean
public IntegrationFlow mqttOutFlow() {
    return IntegrationFlows
            .from(CharacterStreamReadingMessageSource.stdin(), e -> e.poller(Pollers.fixedDelay(1000)))
            .transform(p -> p + " sent to MQTT").handle(mqttOutbound()).get();
}