org.springframework.integration.dsl.support.Consumer Java Examples
The following examples show how to use
org.springframework.integration.dsl.support.Consumer.
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: 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 #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: 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 #4
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 #5
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 #6
Source File: FtpSourceConfiguration.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
@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())); } 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(); }
Example #7
Source File: SftpSourceConfiguration.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
@Bean public IntegrationFlow sftpInboundFlow(SessionFactory<LsEntry> sftpSessionFactory, SftpSourceProperties properties, FileConsumerProperties fileConsumerProperties) { SftpInboundChannelAdapterSpec messageSourceBuilder = Sftp.inboundAdapter(sftpSessionFactory) .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 SftpSimplePatternFileListFilter(properties.getFilenamePattern())); } else if (properties.getFilenameRegex() != null) { messageSourceBuilder .filter(new SftpRegexPatternFileListFilter(properties.getFilenameRegex())); } IntegrationFlowBuilder flowBuilder = IntegrationFlows.from(messageSourceBuilder , new Consumer<SourcePollingChannelAdapterSpec>() { @Override public void accept(SourcePollingChannelAdapterSpec sourcePollingChannelAdapterSpec) { sourcePollingChannelAdapterSpec .poller(SftpSourceConfiguration.this.defaultPoller); } }); return FileUtils.enhanceFlowForReadingMode(flowBuilder, fileConsumerProperties) .channel(this.source.output()) .get(); }
Example #8
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 #9
Source File: OrderEntryProducerConfiguration.java From event-based-shopping-system with MIT License | 5 votes |
@Bean(name = OUTBOUND_ID) public IntegrationFlow producer() { log.info("starting producer flow.."); return flowDefinition -> { Consumer<KafkaProducerMessageHandlerSpec.ProducerMetadataSpec> producerMetadataSpecConsumer = ( KafkaProducerMessageHandlerSpec.ProducerMetadataSpec metadata) -> metadata .async(true).batchNumMessages(5) .valueClassType(String.class); Consumer<PropertiesBuilder> producerProperties = props -> props .put("queue.buffering.max.ms", "15000"); Function<Message<Object>, ?> messageKey = m -> m.getHeaders().get( IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER); KafkaProducerMessageHandlerSpec outboundChannelAdapter = Kafka .outboundChannelAdapter(producerProperties); String topic = this.kafkaConfig.getTopic(); String brokerAddress = this.kafkaConfig.getBrokerAddress(); KafkaProducerMessageHandlerSpec messageHandlerSpec = outboundChannelAdapter .messageKey(messageKey).addProducer(topic, brokerAddress, producerMetadataSpecConsumer); flowDefinition.handle(messageHandlerSpec); }; }
Example #10
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 #11
Source File: MailSourceConfiguration.java From spring-cloud-stream-app-starters with Apache License 2.0 | 4 votes |
/** * Method to build Integration Flow for Mail. Suppress Warnings for * MailInboundChannelAdapterSpec. * @return Integration Flow object for Mail Source */ @SuppressWarnings({ "rawtypes", "unchecked" }) private IntegrationFlowBuilder getFlowBuilder() { IntegrationFlowBuilder flowBuilder; URLName urlName = this.properties.getUrl(); if (this.properties.isIdleImap()) { flowBuilder = getIdleImapFlow(urlName); } else { MailInboundChannelAdapterSpec adapterSpec; switch (urlName.getProtocol().toUpperCase()) { case "IMAP": case "IMAPS": adapterSpec = getImapFlowBuilder(urlName); break; case "POP3": case "POP3S": adapterSpec = getPop3FlowBuilder(urlName); break; default: throw new IllegalArgumentException( "Unsupported mail protocol: " + urlName.getProtocol()); } flowBuilder = IntegrationFlows.from( adapterSpec.javaMailProperties(getJavaMailProperties(urlName)) .selectorExpression(this.properties.getExpression()) .shouldDeleteMessages(this.properties.isDelete()), new Consumer<SourcePollingChannelAdapterSpec>() { @Override public void accept( SourcePollingChannelAdapterSpec sourcePollingChannelAdapterSpec) { sourcePollingChannelAdapterSpec.poller(MailSourceConfiguration.this.defaultPoller); } }); } return flowBuilder; }