List of usage examples for org.springframework.integration.dsl IntegrationFlows from
private static IntegrationFlowBuilder from(MessagingGatewaySupport inboundGateway, @Nullable IntegrationFlowBuilder integrationFlowBuilderArg)
From source file:com.netflix.spring.sample.membership.Membership.java
@Bean public IntegrationFlow myFlow() { return IntegrationFlows.from(this.integerMessageSource(), c -> c.poller(Pollers.fixedRate(100))) .channel(this.inputChannel()).filter((Integer p) -> p > 0).transform(Object::toString) .channel(MessageChannels.queue("sampleQueue")) // .handle(System.out::println) .get();//www . j a va 2 s . c o m }
From source file:org.springframework.cloud.stream.app.ftp.source.FtpSourceConfiguration.java
@Bean public IntegrationFlow ftpInboundFlow(SessionFactory<FTPFile> ftpSessionFactory, FtpSourceProperties properties, FileConsumerProperties fileConsumerProperties) { FtpInboundChannelAdapterSpec messageSourceBuilder = Ftp.inboundAdapter(ftpSessionFactory) .preserveTimestamp(properties.isPreserveTimestamp()).remoteDirectory(properties.getRemoteDir()) .remoteFileSeparator(properties.getRemoteFileSeparator()).localDirectory(properties.getLocalDir()) .autoCreateLocalDirectory(properties.isAutoCreateLocalDir()) .temporaryFileSuffix(properties.getTmpFileSuffix()) .deleteRemoteFiles(properties.isDeleteRemoteFiles()); if (StringUtils.hasText(properties.getFilenamePattern())) { messageSourceBuilder.filter(new FtpSimplePatternFileListFilter(properties.getFilenamePattern())); } else if (properties.getFilenameRegex() != null) { messageSourceBuilder.filter(new FtpRegexPatternFileListFilter(properties.getFilenameRegex())); }// w w w .j a v a2 s .co m IntegrationFlowBuilder flowBuilder = IntegrationFlows.from(messageSourceBuilder, new Consumer<SourcePollingChannelAdapterSpec>() { @Override public void accept(SourcePollingChannelAdapterSpec sourcePollingChannelAdapterSpec) { sourcePollingChannelAdapterSpec.poller(FtpSourceConfiguration.this.defaultPoller); } }); return FileUtils.enhanceFlowForReadingMode(flowBuilder, fileConsumerProperties) .channel(this.source.output()).get(); }
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 www . j a v a2 s .c om*/ 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);//from w w w.ja v a 2s .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./* w ww. 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(); }