org.springframework.integration.dsl.IntegrationFlowBuilder Java Examples

The following examples show how to use org.springframework.integration.dsl.IntegrationFlowBuilder. 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 vote down vote up
@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: FileUtils.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
/**
 * Enhance an {@link IntegrationFlowBuilder} to add flow snippets, depending on
 * {@link FileConsumerProperties}.
 * @param flowBuilder the flow builder.
 * @param fileConsumerProperties the properties.
 * @return the updated flow builder.
 */
public static IntegrationFlowBuilder enhanceFlowForReadingMode(IntegrationFlowBuilder flowBuilder,
		FileConsumerProperties fileConsumerProperties) {
	switch (fileConsumerProperties.getMode()) {
	case contents:
		flowBuilder.enrichHeaders(Collections.<String, Object>singletonMap(MessageHeaders.CONTENT_TYPE,
				"application/octet-stream"))
				.transform(Transformers.fileToByteArray());
		break;
	case lines:
		Boolean withMarkers = fileConsumerProperties.getWithMarkers();
		if (withMarkers == null) {
			withMarkers = false;
		}
		flowBuilder.enrichHeaders(Collections.<String, Object>singletonMap(MessageHeaders.CONTENT_TYPE,
				"text/plain"))
				.split(new FileSplitter(true, withMarkers, fileConsumerProperties.getMarkersJson()));
	case ref:
		break;
	default:
		throw new IllegalArgumentException(fileConsumerProperties.getMode().name() +
				" is not a supported file reading mode.");
	}
	return flowBuilder;
}
 
Example #3
Source File: FtpSourceConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@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 #4
Source File: SftpSourceConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@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 #5
Source File: MailSourceConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
/**
 * Method to build Integration flow for IMAP Idle configuration.
 * @param urlName Mail source URL.
 * @return Integration Flow object IMAP IDLE.
 */
private IntegrationFlowBuilder getIdleImapFlow(URLName urlName) {
	return IntegrationFlows.from(Mail.imapIdleAdapter(urlName.toString())
			.shouldDeleteMessages(this.properties.isDelete())
			.javaMailProperties(getJavaMailProperties(urlName))
			.selectorExpression(this.properties.getExpression())
			.shouldMarkMessagesAsRead(this.properties.isMarkAsRead()));
}
 
Example #6
Source File: FileSourceConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@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 #7
Source File: MongodbSourceConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Bean
public IntegrationFlow startFlow() throws Exception {
    IntegrationFlowBuilder flow =  IntegrationFlows.from(mongoSource());
    if (config.isSplit()) {
        flow.split();
    }
    flow.channel(output);
    return flow.get();
}
 
Example #8
Source File: FunctionConfiguration.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
private IntegrationFlowBuilder integrationFlowFromProvidedSupplier(Supplier<?> supplier,
		Publisher<Object> beginPublishingTrigger, PollableBean pollable, GenericApplicationContext context,
		TaskScheduler taskScheduler, Type functionType) {

	IntegrationFlowBuilder integrationFlowBuilder;

	boolean splittable = pollable != null
			&& (boolean) AnnotationUtils.getAnnotationAttributes(pollable).get("splittable");

	if (pollable == null && FunctionTypeUtils.isReactive(FunctionTypeUtils.getInputType(functionType, 0))) {
		Publisher publisher = (Publisher) supplier.get();
		publisher = publisher instanceof Mono
				? ((Mono) publisher).delaySubscription(beginPublishingTrigger).map(this::wrapToMessageIfNecessary)
				: ((Flux) publisher).delaySubscription(beginPublishingTrigger).map(this::wrapToMessageIfNecessary);

		integrationFlowBuilder = IntegrationFlows.from(publisher);

		// see https://github.com/spring-cloud/spring-cloud-stream/issues/1863 for details about the following code
		taskScheduler.schedule(() -> { }, Instant.now()); // will keep AC alive
	}
	else { // implies pollable
		integrationFlowBuilder = IntegrationFlows.from(supplier);
		if (splittable) {
			integrationFlowBuilder = integrationFlowBuilder.split();
		}
	}

	return integrationFlowBuilder;
}
 
Example #9
Source File: MailSourceConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}