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 Project: spring-reactive-sample Author: hantsy File: IntegrationDslConfig.java License: 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 #2
Source Project: messaging Author: cloud-native-java File: StreamConsumer.java License: 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 #3
Source Project: messaging Author: cloud-native-java File: FinishedFileFlowConfiguration.java License: 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 #4
Source Project: messaging Author: cloud-native-java File: IntegrationConfiguration.java License: 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 #5
Source Project: spring-cloud-stream-app-starters Author: spring-cloud File: FtpSinkConfiguration.java License: 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 #6
Source Project: spring-cloud-stream-app-starters Author: spring-cloud File: SftpSinkConfiguration.java License: 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 #7
Source Project: spring-cloud-stream-app-starters Author: spring-cloud File: JdbcSourceConfiguration.java License: 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 #8
Source Project: building-microservices Author: livelessons-spring File: IntegrationConfiguration.java License: 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 #9
Source Project: building-microservices Author: livelessons-spring File: WebSocketIntegration.java License: 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 Project: spring-and-kafka Author: joshlong File: DemoApplication.java License: 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 #11
Source Project: spring-and-kafka Author: joshlong File: DemoApplication.java License: 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 #12
Source Project: spring-in-action-5-samples Author: habuma File: TacoOrderEmailIntegrationConfig.java License: 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(); }
Example #13
Source Project: spring-in-action-5-samples Author: habuma File: TacoOrderEmailIntegrationConfig.java License: 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(); }
Example #14
Source Project: spring-in-action-5-samples Author: habuma File: TacoOrderEmailIntegrationConfig.java License: 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(); }
Example #15
Source Project: spring-in-action-5-samples Author: habuma File: FileWriterIntegrationConfig.java License: Apache License 2.0 | 5 votes |
@Profile("javadsl") @Bean public IntegrationFlow fileWriterFlow() { return IntegrationFlows .from(MessageChannels.direct("textInChannel")) .<String, String>transform(t -> t.toUpperCase()) .handle(Files .outboundAdapter(new File("/tmp/sia5/files")) .fileExistsMode(FileExistsMode.APPEND) .appendNewLine(true)) .get(); }
Example #16
Source Project: Software-Architecture-with-Spring-5.0 Author: PacktPublishing File: CallCenterAppApplication.java License: MIT License | 5 votes |
@Bean IntegrationFlow integrationFlow(EventNotificationChannel eventNotificationChannel) { return IntegrationFlows.from(eventNotificationChannel.subscriptionOnMoneyTransferredChannel()). handle(String.class, new GenericHandler<String>() { @Override public Object handle(String payload, Map<String, Object> headers) { log.info("Message retrieved:"); log.info(payload); // TODO: // Use the client id to find the transaction and determine if // we have to offer investment opportunities to the client return null; } }).get(); }
Example #17
Source Project: Software-Architecture-with-Spring-5.0 Author: PacktPublishing File: NotificationsApplication.java License: MIT License | 5 votes |
@Bean IntegrationFlow integrationFlow(EventNotificationChannel eventNotificationChannel) { return IntegrationFlows.from(eventNotificationChannel.subscriptionOnMoneyTransferredChannel()). handle(String.class, new GenericHandler<String>() { @Override public Object handle(String payload, Map<String, Object> headers) { log.info("Message retrieved:"); log.info(payload); // TODO: // Use the client id to find the transaction and determine the // preferred notification channels return null; } }).get(); }
Example #18
Source Project: Software-Architecture-with-Spring-5.0 Author: PacktPublishing File: ExternalBanksApplication.java License: MIT License | 5 votes |
@Bean IntegrationFlow integrationFlow(EventNotificationChannel eventNotificationChannel) { return IntegrationFlows.from(eventNotificationChannel.subscriptionOnMoneyTransferredChannel()). handle(String.class, new GenericHandler<String>() { @Override public Object handle(String payload, Map<String, Object> headers) { log.info("Message retrieved:"); log.info(payload); // TODO: // Use the client id to find the transaction and determine if a notification // should be sent to external banks return null; } }).get(); }
Example #19
Source Project: Software-Architecture-with-Spring-5.0 Author: PacktPublishing File: CallCenterAppApplication.java License: MIT License | 5 votes |
@Bean IntegrationFlow integrationFlow(EventNotificationChannel eventNotificationChannel) { return IntegrationFlows.from(eventNotificationChannel.subscriptionOnMoneyTransferredChannel()). handle(TransferMoneyDetails.class, new GenericHandler<TransferMoneyDetails>() { @Override public Object handle(TransferMoneyDetails payload, Map<String, Object> map) { log.info("Verifying if we have to offer investment opportunities to customer with id: " + payload.getCustomerId()); log.info("Transaction details: " + payload); return null; } }).get(); }
Example #20
Source Project: Software-Architecture-with-Spring-5.0 Author: PacktPublishing File: NotificationsApplication.java License: MIT License | 5 votes |
@Bean IntegrationFlow integrationFlow(EventNotificationChannel eventNotificationChannel) { return IntegrationFlows.from(eventNotificationChannel.subscriptionOnMoneyTransferredChannel()). handle(TransferMoneyDetails.class, new GenericHandler<TransferMoneyDetails>() { @Override public Object handle(TransferMoneyDetails payload, Map<String, Object> map) { log.info("Notifying by preferred channels to customer with id: " + payload.getCustomerId()); log.info("Transaction details: " + payload); return null; } }).get(); }
Example #21
Source Project: Software-Architecture-with-Spring-5.0 Author: PacktPublishing File: ExternalBanksApplication.java License: MIT License | 5 votes |
@Bean IntegrationFlow integrationFlow(EventNotificationChannel eventNotificationChannel) { return IntegrationFlows.from(eventNotificationChannel.subscriptionOnMoneyTransferredChannel()). handle(TransferMoneyDetails.class, new GenericHandler<TransferMoneyDetails>() { @Override public Object handle(TransferMoneyDetails payload, Map<String, Object> map) { log.info("Should we notify to external banks: " + payload.isExternalBank()); if (payload.isExternalBank()) { log.info("Notifying to external bank about transaction: " + payload); } return null; } }).get(); }
Example #22
Source Project: activiti6-boot2 Author: dingziyang File: Application.java License: Apache License 2.0 | 5 votes |
@Bean IntegrationFlow inboundProcess(ActivitiInboundGateway inboundGateway) { return IntegrationFlows .from(inboundGateway) .handle(new GenericHandler<DelegateExecution>() { @Override public Object handle(DelegateExecution execution, Map<String, Object> headers) { return MessageBuilder.withPayload(execution) .setHeader("projectId", "3243549") .copyHeaders(headers).build(); } }) .get(); }
Example #23
Source Project: activiti6-boot2 Author: dingziyang File: IntegrationAutoConfigurationTest.java License: Apache License 2.0 | 5 votes |
@Bean public IntegrationFlow inboundProcess(ActivitiInboundGateway inboundGateway) { return IntegrationFlows .from(inboundGateway) .handle(new GenericHandler<DelegateExecution>() { @Override public Object handle(DelegateExecution execution, Map<String, Object> headers) { return MessageBuilder.withPayload(execution) .setHeader("projectId", projectId) .setHeader("orderId", "246") .copyHeaders(headers).build(); } }) .get(); }
Example #24
Source Project: spring-reactive-sample Author: hantsy File: IntegrationDslConfig.java License: GNU General Public License v3.0 | 5 votes |
@Bean public IntegrationFlow inboundChannelAdapterFlow() { return IntegrationFlows .from( WebFlux .inboundGateway("/all") .requestMapping(m -> m.methods(HttpMethod.GET)) // .requestPayloadType(ResolvableType.forClassWithGenerics(Flux.class, String.class)) //.statusCodeFunction(m -> HttpStatus.OK) ) .channel(c -> c.flux("outboundReactive.input")) .get(); }
Example #25
Source Project: spring-5-examples Author: daggerok File: ServerSideEventsConfig.java License: MIT License | 5 votes |
@Bean public IntegrationFlow sseFlow() { return IntegrationFlows.from(Http.inboundReactiveGateway("/sse") .requestMapping(m -> m.produces(MediaType.TEXT_EVENT_STREAM_VALUE))) .handle((p, h) -> Flux.just("foo", "bar", "baz")) .get(); }
Example #26
Source Project: micrometer Author: micrometer-metrics File: SpringIntegrationApplication.java License: Apache License 2.0 | 5 votes |
@Bean public IntegrationFlow convert() { return f -> f .transform(payload -> "<FahrenheitToCelsius xmlns=\"https://www.w3schools.com/xml/\">" + "<Fahrenheit>" + payload + "</Fahrenheit>" + "</FahrenheitToCelsius>", e -> e.id("toXml")) .enrichHeaders(h -> h .header(WebServiceHeaders.SOAP_ACTION, "https://www.w3schools.com/xml/FahrenheitToCelsius")) .handle(new SimpleWebServiceOutboundGateway( "https://www.w3schools.com/xml/tempconvert.asmx"), e -> e.id("w3schools")) .transform(new XPathTransformer("/*[local-name()=\"FahrenheitToCelsiusResponse\"]" + "/*[local-name()=\"FahrenheitToCelsiusResult\"]"), e -> e.id("toResponse")); }
Example #27
Source Project: messaging Author: cloud-native-java File: InvalidFileFlowConfiguration.java License: Apache License 2.0 | 5 votes |
@Bean IntegrationFlow invalidFileFlow(BatchChannels channels, @Value("${error-directory:${HOME}/Desktop/errors}") File errors) { return IntegrationFlows .from(channels.invalid()) .handle(JobExecution.class, (je, headers) -> { String ogFileName = String.class.cast(headers .get(FileHeaders.ORIGINAL_FILE)); File file = new File(ogFileName); mv(file, errors); return null; }).get(); }
Example #28
Source Project: messaging Author: cloud-native-java File: EtlFlowConfiguration.java License: Apache License 2.0 | 5 votes |
@Bean IntegrationFlow etlFlow( @Value("${input-directory:${HOME}/Desktop/in}") File directory, BatchChannels c, JobLauncher launcher, Job job) { return IntegrationFlows .from(Files.inboundAdapter(directory).autoCreateDirectory(true), cs -> cs.poller(p -> p.fixedRate(1000))) .handle( File.class, (file, headers) -> { String absolutePath = file.getAbsolutePath(); // <2> JobParameters params = new JobParametersBuilder().addString("file", absolutePath).toJobParameters(); return MessageBuilder.withPayload(new JobLaunchRequest(job, params)) .setHeader(ORIGINAL_FILE, absolutePath) .copyHeadersIfAbsent(headers).build(); }) // <3> .handle(new JobLaunchingGateway(launcher)) // <4> .routeToRecipients( spec -> spec.recipient(c.invalid(), this::notFinished).recipient( c.completed(), this::finished)).get(); }
Example #29
Source Project: messaging Author: cloud-native-java File: IntegrationConfiguration.java License: Apache License 2.0 | 5 votes |
@Bean IntegrationFlow txtFlow() { return IntegrationFlows.from(txt()).handle(File.class, (f, h) -> { log.info("file is .txt!"); return null; }).get(); }
Example #30
Source Project: messaging Author: cloud-native-java File: IntegrationConfiguration.java License: Apache License 2.0 | 5 votes |
@Bean IntegrationFlow csvFlow() { return IntegrationFlows.from(csv()).handle(File.class, (f, h) -> { log.info("file is .csv!"); return null; }).get(); }