/** * Create an {@link IntegrationFlow} with a {@link ChunkProcessorChunkHandler} * configured as a service activator listening to the input channel and replying * on the output channel. * * @return the integration flow */ @SuppressWarnings({"unchecked", "rawtypes"}) public IntegrationFlow build() { Assert.notNull(this.itemWriter, "An ItemWriter must be provided"); Assert.notNull(this.inputChannel, "An InputChannel must be provided"); Assert.notNull(this.outputChannel, "An OutputChannel must be provided"); if(this.itemProcessor == null) { this.itemProcessor = new PassThroughItemProcessor(); } SimpleChunkProcessor<I, O> chunkProcessor = new SimpleChunkProcessor<>(this.itemProcessor, this.itemWriter); ChunkProcessorChunkHandler<I> chunkProcessorChunkHandler = new ChunkProcessorChunkHandler<>(); chunkProcessorChunkHandler.setChunkProcessor(chunkProcessor); return IntegrationFlows .from(this.inputChannel) .handle(chunkProcessorChunkHandler, SERVICE_ACTIVATOR_METHOD_NAME) .channel(this.outputChannel) .get(); }
@Bean public IntegrationFlow fileWritingFlow() { return IntegrationFlows.from("fileWritingInput") .enrichHeaders(h -> h.header(FileHeaders.FILENAME, "foo.write") .header("directory", new File(tmpDir.getRoot(), "fileWritingFlow"))) .handle(Files.outboundGateway(m -> m.getHeaders().get("directory")) .preserveTimestamp(true) .chmod(0777)) .channel(MessageChannels.queue("fileWritingResultChannel")) .get(); }
@Bean public IntegrationFlow fileSplitterFlow(BeanFactory beanFactory) { ExpressionFileListFilter<File> fileExpressionFileListFilter = new ExpressionFileListFilter<>(new FunctionExpression<File>(f -> "foo.tmp".equals(f.getName()))); fileExpressionFileListFilter.setBeanFactory(beanFactory); return IntegrationFlows .from(Files.inboundAdapter(tmpDir.getRoot()) .filter(new ChainFileListFilter<File>() .addFilter(new AcceptOnceFileListFilter<>()) .addFilter(fileExpressionFileListFilter)), e -> e.poller(p -> p.fixedDelay(100))) .split(Files.splitter() .markers() .charset(StandardCharsets.US_ASCII) .applySequence(true), e -> e.id("fileSplitter")) .channel(c -> c.queue("fileSplittingResultChannel")) .get(); }
@Override protected IntegrationFlowDefinition<?> buildFlow() { return from(this, "messageSource", e -> e.poller(p -> p.trigger(this::nextExecutionTime))) .split(this, null, e -> e.applySequence(false)) .transform(this) .aggregate(a -> a.processor(this, null)) .enrichHeaders(Collections.singletonMap("foo", "FOO")) .filter(this) .handle(this) .channel(MessageChannels.queue("myFlowAdapterOutput")) .log(); }
@Bean public IntegrationFlow fileSplitterAggregator() { return IntegrationFlows .from(Files.inboundAdapter(new File("/tmp/in")) .autoCreateDirectory(true) .patternFilter("*.txt"), e -> e.poller(Pollers.fixedDelay(5000))) .split(Files.splitter() .markers() .applySequence(true)) .filter(p -> !(p instanceof FileSplitter.FileMarker), e -> e.discardChannel("aggregatorChannel")) .<String, Name>transform(Name::new) .<Name>filter(p -> !p.getValue().startsWith("X")) .channel("aggregatorChannel") .aggregate(a -> a.processor(new FileMarkerAggregator())) .<List<Name>, Names>transform(Names::new) .transform(Transformers.marshaller(jaxbMarshaller(), new ResultToStringTransformer())) .handle(Files.outboundAdapter("'/tmp/out'") .fileNameGenerator(m -> m .getHeaders() .get(FileHeaders.FILENAME, String.class) .replace(".txt", ".xml")) .autoCreateDirectory(true)) .get(); }
@Bean public IntegrationFlow sseFlow() { return IntegrationFlows .from(WebFlux.inboundGateway("/sse") .requestMapping(m -> m.produces(MediaType.TEXT_EVENT_STREAM_VALUE)) .mappedResponseHeaders("*")) .enrichHeaders(Collections.singletonMap("aHeader", new String[] { "foo", "bar", "baz" })) .handle((p, h) -> Flux.fromArray(h.get("aHeader", String[].class))) .get(); }
@Bean public IntegrationFlow pop3MailFlow() { return IntegrationFlows .from(Mail.pop3InboundAdapter("localhost", pop3Server.getPort(), "user", "pw") .javaMailProperties(p -> p.put("mail.debug", "false")) .headerMapper(mailHeaderMapper()), e -> e.autoStartup(true).poller(p -> p.fixedDelay(1000))) .enrichHeaders(s -> s.headerExpressions(c -> c.put(MailHeaders.SUBJECT, "payload.subject") .put(MailHeaders.FROM, "payload.from[0].toString()"))) .channel(MessageChannels.queue("pop3Channel")) .get(); }
StandardIntegrationFlow standardIntegrationFlow = IntegrationFlows .from(this.inputChannel) .aggregate(aggregatorSpec -> aggregatorSpec.processor(partitionHandler)) .channel(replies) .get(); IntegrationFlowContext integrationFlowContext = this.beanFactory.getBean(IntegrationFlowContext.class); integrationFlowContext.registration(standardIntegrationFlow)
@Bean public IntegrationFlow flow2() { return IntegrationFlows.from(this.inputChannel) .filter(p -> p instanceof String, e -> e .id("filter") .discardFlow(df -> df .transform(String.class, "Discarded: "::concat) .channel(MessageChannels.queue("discardChannel")))) .channel("foo") .fixedSubscriberChannel() .<String, Integer>transform(Integer::parseInt) .transform(Foo::new) .transform(new PayloadSerializingTransformer(), c -> c.autoStartup(false).id("payloadSerializingTransformer")) .channel(MessageChannels.queue(new SimpleMessageStore(), "fooQueue")) .transform(Transformers.deserializer(Foo.class.getName())) .<Foo, Integer>transform(f -> f.value) .filter("true", e -> e.id("expressionFilter")) .channel(publishSubscribeChannel()) .transform((Integer p) -> p * 2, c -> c.advice(this.expressionAdvice())) .get(); }
@Bean public IntegrationFlow fileReadingFlow() { return IntegrationFlows .from(Files.inboundAdapter(tmpDir.getRoot()) .patternFilter("*.sitest") .useWatchService(true) .watchEvents(FileReadingMessageSource.WatchEventType.CREATE, FileReadingMessageSource.WatchEventType.MODIFY), e -> e.poller(Pollers.fixedDelay(100) .errorChannel("filePollingErrorChannel"))) .filter(File.class, p -> !p.getName().startsWith("a"), e -> e.throwExceptionOnRejection(true)) .transform(Files.toStringTransformer()) .aggregate(a -> a.correlationExpression("1") .releaseStrategy(g -> g.size() == 25)) .channel(MessageChannels.queue("fileReadingResultChannel")) .get(); }
@Bean public IntegrationFlow recipientListFlow() { return IntegrationFlows.from("recipientListInput") .<String, String>transform(p -> p.replaceFirst("Payload", "")) .routeToRecipients(r -> r .recipient("foo-channel", "'foo' == payload") .recipientMessageSelector("bar-channel", m -> m.getHeaders().containsKey("recipient") && (boolean) m.getHeaders().get("recipient")) .recipientFlow("'foo' == payload or 'bar' == payload or 'baz' == payload", f -> f.<String, String>transform(String::toUpperCase) .channel(MessageChannels.queue("recipientListSubFlow1Result"))) .recipientFlow((String p) -> p.startsWith("baz"), f -> f.transform("Hello "::concat) .channel(MessageChannels.queue("recipientListSubFlow2Result"))) .recipientFlow(new FunctionExpression<Message<?>>(m -> "bax".equals(m.getPayload())), f -> f.channel(MessageChannels.queue("recipientListSubFlow3Result"))) .defaultOutputToParentFlow()) .channel("defaultOutputChannel") .get(); }
private IntegrationFlowBuilder multiSourceListingFlowBuilder() { IntegrationFlowBuilder flow = IntegrationFlows.from(() -> this.listFilesRotator.getCurrentDirectory(), consumerSpec(this.listFilesRotator)) .handle(Sftp.outboundGateway(this.delegatingSessionFactory.getFactory(), AbstractRemoteFileOutboundGateway.Command.LS.getCommand(), "payload") .options(AbstractRemoteFileOutboundGateway.Option.NAME_ONLY.getOption())); return flow.handle(this.listFilesRotator, "clearKey") .split() .channel(sftpListInputChannel()); }
@Bean public Publisher<Message<Integer>> pollableReactiveFlow() { return IntegrationFlows .from("inputChannel") .split(s -> s.delimiters(",")) .<String, Integer>transform(Integer::parseInt) .channel(MessageChannels.queue()) .log() .toReactivePublisher(); }