org.springframework.integration.dsl.IntegrationFlow Java Examples
The following examples show how to use
org.springframework.integration.dsl.IntegrationFlow.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JdbcSourceConfiguration.java From spring-cloud-stream-app-starters with Apache License 2.0 | 6 votes |
@Bean public IntegrationFlow pollingFlow() { IntegrationFlowBuilder flowBuilder = IntegrationFlows.from(jdbcMessageSource(), new Consumer<SourcePollingChannelAdapterSpec>() { @Override public void accept(SourcePollingChannelAdapterSpec sourcePollingChannelAdapterSpec) { sourcePollingChannelAdapterSpec.poller(poller); } }); if (this.properties.isSplit()) { flowBuilder.split(); } flowBuilder.channel(this.source.output()); return flowBuilder.get(); }
Example #2
Source File: SftpSinkConfiguration.java From spring-cloud-stream-app-starters with Apache License 2.0 | 6 votes |
@Bean public IntegrationFlow ftpInboundFlow(SftpSinkProperties properties, SessionFactory<LsEntry> ftpSessionFactory) { SftpMessageHandlerSpec handlerSpec = Sftp.outboundAdapter(new SftpRemoteFileTemplate(ftpSessionFactory), properties.getMode()) .remoteDirectory(properties.getRemoteDir()) .remoteFileSeparator(properties.getRemoteFileSeparator()) .autoCreateDirectory(properties.isAutoCreateDir()) .temporaryFileSuffix(properties.getTmpFileSuffix()); if (properties.getFilenameExpression() != null) { handlerSpec.fileNameExpression(properties.getFilenameExpression().getExpressionString()); } return IntegrationFlows.from(Sink.INPUT) .handle(handlerSpec, new Consumer<GenericEndpointSpec<FileTransferringMessageHandler<LsEntry>>>() { @Override public void accept(GenericEndpointSpec<FileTransferringMessageHandler<LsEntry>> e) { e.autoStartup(false); } }) .get(); }
Example #3
Source File: FtpSinkConfiguration.java From spring-cloud-stream-app-starters with Apache License 2.0 | 6 votes |
@Bean public IntegrationFlow ftpInboundFlow(FtpSinkProperties properties, SessionFactory<FTPFile> ftpSessionFactory) { FtpMessageHandlerSpec handlerSpec = Ftp.outboundAdapter(new FtpRemoteFileTemplate(ftpSessionFactory), properties.getMode()) .remoteDirectory(properties.getRemoteDir()) .remoteFileSeparator(properties.getRemoteFileSeparator()) .autoCreateDirectory(properties.isAutoCreateDir()) .temporaryFileSuffix(properties.getTmpFileSuffix()); if (properties.getFilenameExpression() != null) { handlerSpec.fileNameExpression(properties.getFilenameExpression().getExpressionString()); } return IntegrationFlows.from(Sink.INPUT) .handle(handlerSpec, new Consumer<GenericEndpointSpec<FileTransferringMessageHandler<FTPFile>>>() { @Override public void accept(GenericEndpointSpec<FileTransferringMessageHandler<FTPFile>> e) { e.autoStartup(false); } }) .get(); }
Example #4
Source File: IntegrationConfiguration.java From building-microservices with Apache License 2.0 | 6 votes |
@Bean IntegrationFlow batchJobFlow(Job job, JdbcTemplate jdbcTemplate, JobLauncher launcher, MessageChannel files) { return IntegrationFlows.from(files) .transform((GenericTransformer<Object,JobLaunchRequest>) file -> { System.out.println(file.toString()); System.out.println(file.getClass()); return null ; }) .transform((GenericTransformer<File, JobLaunchRequest>) file -> { JobParameters jp = new JobParametersBuilder() .addString("file", file.getAbsolutePath()) .toJobParameters(); return new JobLaunchRequest(job, jp); }) .handle(new JobLaunchingGateway(launcher)) .handle(JobExecution.class, (payload, headers) -> { System.out.println("job execution status: " + payload.getExitStatus().toString()); List<Person> personList = jdbcTemplate.query("select * from PEOPLE", (resultSet, i) -> new Person(resultSet.getString("first"), resultSet.getString("last"), resultSet.getString("email"))); personList.forEach(System.out::println); return null; }) .get(); }
Example #5
Source File: StreamConsumer.java From messaging with Apache License 2.0 | 6 votes |
private IntegrationFlow incomingMessageFlow(SubscribableChannel incoming, String prefix) { Log log = LogFactory.getLog(getClass()); return IntegrationFlows .from(incoming) .transform(String.class, String::toUpperCase) .handle( String.class, (greeting, headers) -> { log.info("greeting received in IntegrationFlow (" + prefix + "): " + greeting); return null; }).get(); }
Example #6
Source File: DemoApplication.java From spring-and-kafka with Apache License 2.0 | 6 votes |
@Bean IntegrationFlow consumer() { log.info("starting consumer.."); KafkaHighLevelConsumerMessageSourceSpec messageSourceSpec = Kafka.inboundChannelAdapter( new ZookeeperConnect(this.kafkaConfig.getZookeeperAddress())) .consumerProperties(props -> props.put("auto.offset.reset", "smallest") .put("auto.commit.interval.ms", "100")) .addConsumer("myGroup", metadata -> metadata.consumerTimeout(100) .topicStreamMap(m -> m.put(this.kafkaConfig.getTopic(), 1)) .maxMessages(10) .valueDecoder(String::new)); Consumer<SourcePollingChannelAdapterSpec> endpointConfigurer = e -> e.poller(p -> p.fixedDelay(100)); return IntegrationFlows .from(messageSourceSpec, endpointConfigurer) .<Map<String, List<String>>>handle((payload, headers) -> { payload.entrySet().forEach(e -> log.info(e.getKey() + '=' + e.getValue())); return null; }) .get(); }
Example #7
Source File: DemoApplication.java From spring-and-kafka with Apache License 2.0 | 6 votes |
@Bean(name = OUTBOUND_ID) IntegrationFlow producer() { log.info("starting producer flow.."); return flowDefinition -> { Consumer<KafkaProducerMessageHandlerSpec.ProducerMetadataSpec> producerMetadataSpecConsumer = (KafkaProducerMessageHandlerSpec.ProducerMetadataSpec metadata) -> metadata.async(true) .batchNumMessages(10) .valueClassType(String.class) .<String>valueEncoder(String::getBytes); KafkaProducerMessageHandlerSpec messageHandlerSpec = Kafka.outboundChannelAdapter(props -> props.put("queue.buffering.max.ms", "15000")) .messageKey(m -> m.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER)) .addProducer(this.kafkaConfig.getTopic(), this.kafkaConfig.getBrokerAddress(), producerMetadataSpecConsumer); flowDefinition .handle(messageHandlerSpec); }; }
Example #8
Source File: IntegrationConfiguration.java From messaging with Apache License 2.0 | 6 votes |
@Bean IntegrationFlow etlFlow( @Value("${input-directory:${HOME}/Desktop/in}") File dir) { return IntegrationFlows // <1> .from(Files.inboundAdapter(dir).autoCreateDirectory(true), consumer -> consumer.poller(spec -> spec.fixedRate(1000))) // <2> .handle(File.class, (file, headers) -> { log.info("we noticed a new file, " + file); return file; }) // <3> .routeToRecipients( spec -> spec.recipient(csv(), msg -> hasExt(msg.getPayload(), ".csv")) .recipient(txt(), msg -> hasExt(msg.getPayload(), ".txt"))).get(); }
Example #9
Source File: WebSocketIntegration.java From building-microservices with Apache License 2.0 | 6 votes |
@Bean public IntegrationFlow webSocketFlow(EchoService echoService) { return (IntegrationFlowDefinition<?> integrationFlowDefinition) -> { Function<String, Object> splitter = (String messagePayload) -> { // convert the payload String echoValue = echoService.echo(messagePayload); // for each of the active WS sessions, // build a Message destined for that session containing the // input message return serverWebSocketContainer().getSessions().keySet().stream() .map(s -> MessageBuilder.withPayload(echoValue) .setHeader(SimpMessageHeaderAccessor.SESSION_ID_HEADER, s) .build()) .collect(Collectors.toList()); }; integrationFlowDefinition.split(String.class, splitter) .channel(c -> c.executor(Executors.newCachedThreadPool())) .handle(webSocketOutboundAdapter()); }; }
Example #10
Source File: FinishedFileFlowConfiguration.java From messaging with Apache License 2.0 | 6 votes |
@Bean IntegrationFlow finishedJobsFlow(BatchChannels channels, @Value("${completed-directory:${HOME}/Desktop/completed}") File finished, JdbcTemplate jdbcTemplate) { return IntegrationFlows .from(channels.completed()) .handle(JobExecution.class, (je, headers) -> { String ogFileName = String.class.cast(headers .get(FileHeaders.ORIGINAL_FILE)); File file = new File(ogFileName); mv(file, finished); List<Contact> contacts = jdbcTemplate.query( "select * from CONTACT", (rs, i) -> new Contact( rs.getBoolean("valid_email"), rs.getString("full_name"), rs.getString("email"), rs.getLong("id"))); contacts.forEach(log::info); return null; }).get(); }
Example #11
Source File: IntegrationDslConfig.java From spring-reactive-sample with GNU General Public License v3.0 | 6 votes |
@Bean public IntegrationFlow outboundReactive() { return f -> f .handle( WebFlux .<MultiValueMap<String, String>>outboundGateway( m -> UriComponentsBuilder .fromUriString("http://localhost:8080/posts") //.queryParams(m.getPayload()) .build() .toUri() ) .httpMethod(HttpMethod.GET) .expectedResponseType(String.class) ); }
Example #12
Source File: JavaDSLFileCopyConfig.java From tutorials with MIT License | 5 votes |
public IntegrationFlow fileMoverWithLambda() { return IntegrationFlows.from(sourceDirectory(), configurer -> configurer.poller(Pollers.fixedDelay(10000))) .filter(message -> ((File) message).getName() .endsWith(".jpg")) .handle(targetDirectory()) .get(); }
Example #13
Source File: PublishSubscibeChannelExample.java From tutorials with MIT License | 5 votes |
@Bean public IntegrationFlow classify() { return flow -> flow.split() .publishSubscribeChannel(subscription -> subscription.subscribe(subflow -> subflow.<Integer> filter(this::isMultipleOfThree) .channel("multipleofThreeChannel")) .subscribe(subflow -> subflow.<Integer> filter(this::isRemainderOne) .channel("remainderIsOneChannel")) .subscribe(subflow -> subflow.<Integer> filter(this::isRemainderTwo) .channel("remainderIsTwoChannel"))); }
Example #14
Source File: RouteToRecipientsExample.java From tutorials with MIT License | 5 votes |
@Bean public IntegrationFlow classify() { return flow -> flow.split() .routeToRecipients(route -> route .recipientFlow(subflow -> subflow .<Integer> filter(this::isMultipleOfThree) .channel("multipleofThreeChannel")) .<Integer> recipient("remainderIsOneChannel",this::isRemainderOne) .<Integer> recipient("remainderIsTwoChannel",this::isRemainderTwo)); }
Example #15
Source File: JavaDSLFileCopyConfig.java From tutorials with MIT License | 5 votes |
public IntegrationFlow fileMoverWithPriorityChannel() { return IntegrationFlows.from(sourceDirectory()) .filter(onlyJpgs()) .channel("alphabetically") .handle(targetDirectory()) .get(); }
Example #16
Source File: SpringIntegrationWebMvcApplication.java From springfox-demos with Apache License 2.0 | 5 votes |
@Bean public IntegrationFlow toUpperGetFlow() { return IntegrationFlows.from( Http.inboundGateway("/conversions/pathvariable/{upperLower}") .requestMapping(r -> r .methods(HttpMethod.GET) .params("toConvert")) .headerExpression("upperLower", "#pathVariables.upperLower") .payloadExpression("#requestParams['toConvert'][0]") .id("toUpperLowerGateway")) .<String>handle((p, h) -> "upper".equals(h.get("upperLower")) ? p.toUpperCase() : p.toLowerCase()) .get(); }
Example #17
Source File: JavaDSLFileCopyConfig.java From tutorials with MIT License | 5 votes |
@Bean public IntegrationFlow fileMover() { return IntegrationFlows.from(sourceDirectory(), configurer -> configurer.poller(Pollers.fixedDelay(10000))) .filter(onlyJpgs()) .handle(targetDirectory()) .get(); }
Example #18
Source File: SpringIntegrationWebMvcApplication.java From springfox-demos with Apache License 2.0 | 5 votes |
@Bean public IntegrationFlow toUpperFlow() { return IntegrationFlows.from( Http.inboundGateway("/conversions/upper") .requestMapping(r -> r.methods(HttpMethod.POST) .consumes("text/plain")) .requestPayloadType(String.class) .id("toUpperGateway")) .<String>handle((p, h) -> p.toUpperCase()) .get(); }
Example #19
Source File: SpringIntegrationWebMvcApplication.java From springfox-demos with Apache License 2.0 | 5 votes |
@Bean public IntegrationFlow toLowerFlow() { return IntegrationFlows.from( Http.inboundGateway("/conversions/lower") .requestMapping(r -> r.methods(HttpMethod.POST) .consumes("application/json")) .requestPayloadType(Foo.class) .id("toLowerGateway")) .<Foo>handle((p, h) -> new Foo(p.getBar() .toLowerCase())) .get(); }
Example #20
Source File: SpringIntegrationWebFluxApplication.java From springfox-demos with Apache License 2.0 | 5 votes |
@Bean public IntegrationFlow toUpperFlow() { return IntegrationFlows.from( WebFlux.inboundGateway("/conversions/upper") .requestMapping(r -> r.methods(HttpMethod.POST) .consumes("text/plain"))) .<String>handle((p, h) -> p.toUpperCase()) .get(); }
Example #21
Source File: MailSourceConfiguration.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
@Bean public IntegrationFlow mailInboundFlow() { return getFlowBuilder() .transform(Transformers.fromMail(this.properties.getCharset())) .channel(Source.OUTPUT) .get(); }
Example #22
Source File: FilterExample.java From tutorials with MIT License | 5 votes |
@Bean public IntegrationFlow classify() { return flow -> flow.split() .<Integer> filter(this::isMultipleOfThree, notMultiple -> notMultiple .discardFlow(oneflow -> oneflow .<Integer> filter(this::isRemainderOne, twoflow -> twoflow .discardChannel("remainderIsTwoChannel")) .channel("remainderIsOneChannel"))) .channel("multipleofThreeChannel"); }
Example #23
Source File: RouterExample.java From tutorials with MIT License | 5 votes |
@Bean public IntegrationFlow classify() { return flow -> flow.split() .<Integer, Integer> route(number -> number % 3, mapping -> mapping .channelMapping(0, "multipleofThreeChannel") .subFlowMapping(1, subflow -> subflow.channel("remainderIsOneChannel")) .subFlowMapping(2, subflow -> subflow .<Integer> handle((payload, headers) -> { // do extra work on the payload return payload; }))).channel("remainderIsTwoChannel"); }
Example #24
Source File: CommoditiesReservationConsumerConfiguration.java From event-based-shopping-system with MIT License | 5 votes |
@Bean IntegrationFlow consumer() { log.info("starting consumer.."); KafkaHighLevelConsumerMessageSourceSpec messageSourceSpec = Kafka .inboundChannelAdapter( new ZookeeperConnect(this.kafkaConfig .getZookeeperAddress())) .consumerProperties( props -> props.put("auto.offset.reset", "smallest") .put("auto.commit.interval.ms", "100")) .addConsumer( "myGroup", metadata -> metadata .consumerTimeout(100) .topicStreamMap( m -> m.put(this.kafkaConfig.getTopic(), 1)).maxMessages(1) .valueDecoder(String::new)); Consumer<SourcePollingChannelAdapterSpec> endpointConfigurer = e -> e.poller(p -> p.fixedDelay(100)); return IntegrationFlows .from(messageSourceSpec, endpointConfigurer) .<Map<String, ConcurrentHashMap<String, String>>> handle( (payload, headers) -> { payload.entrySet().forEach( e -> orderEntryService.createOrderEntryFromJson(e.getValue())); return null; }).get(); }
Example #25
Source File: AmqpIntegration.java From building-microservices with Apache License 2.0 | 5 votes |
@Bean public IntegrationFlow amqpReplyFlow(ConnectionFactory rabbitConnectionFactory, EchoService echoService) { return IntegrationFlows .from(Amqp.inboundGateway(rabbitConnectionFactory, this.echoQueueAndExchangeName)) .transform(String.class, echoService::echo).get(); }
Example #26
Source File: ConsumerApplication.java From building-microservices with Apache License 2.0 | 5 votes |
@Bean IntegrationFlow greetingsFlow(MessageChannels channels) { return IntegrationFlows.from(channels.input()) .handle(String.class, (payload, headers) -> { System.out.println(payload); return null; }) .get(); }
Example #27
Source File: IntegrationConfiguration.java From building-microservices with Apache License 2.0 | 5 votes |
@Bean IntegrationFlow incomingFiles(@Value("${HOME}/Desktop/in") File dir) { return IntegrationFlows.from( Files.inboundAdapter(dir) .preventDuplicates() .autoCreateDirectory(true), poller -> poller.poller(spec -> spec.fixedRate(1, TimeUnit.SECONDS))) .channel( this.files()) .get(); }
Example #28
Source File: MongodbSourceConfiguration.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
@Bean public IntegrationFlow startFlow() throws Exception { IntegrationFlowBuilder flow = IntegrationFlows.from(mongoSource()); if (config.isSplit()) { flow.split(); } flow.channel(output); return flow.get(); }
Example #29
Source File: FileSourceConfiguration.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
@Bean public IntegrationFlow fileSourceFlow() { FileInboundChannelAdapterSpec messageSourceSpec = Files.inboundAdapter(new File(this.properties.getDirectory())); if (StringUtils.hasText(this.properties.getFilenamePattern())) { messageSourceSpec.patternFilter(this.properties.getFilenamePattern()); } else if (this.properties.getFilenameRegex() != null) { messageSourceSpec.regexFilter(this.properties.getFilenameRegex().pattern()); } if (this.properties.isPreventDuplicates()) { messageSourceSpec.preventDuplicates(); } IntegrationFlowBuilder flowBuilder = IntegrationFlows .from(messageSourceSpec, new Consumer<SourcePollingChannelAdapterSpec>() { @Override public void accept(SourcePollingChannelAdapterSpec sourcePollingChannelAdapterSpec) { sourcePollingChannelAdapterSpec .poller(defaultPoller); } }); return FileUtils.enhanceFlowForReadingMode(flowBuilder, this.fileConsumerProperties) .channel(source.output()) .get(); }
Example #30
Source File: TacoOrderEmailIntegrationConfig.java From spring-in-action-5-samples with Apache License 2.0 | 5 votes |
@Bean public IntegrationFlow tacoOrderEmailFlow( EmailProperties emailProps, EmailToOrderTransformer emailToOrderTransformer, OrderSubmitMessageHandler orderSubmitHandler) { return IntegrationFlows .from(Mail.imapInboundAdapter(emailProps.getImapUrl()), e -> e.poller( Pollers.fixedDelay(emailProps.getPollRate()))) .transform(emailToOrderTransformer) .handle(orderSubmitHandler) .get(); }