Commit c0682855 authored by Andy Wilkinson's avatar Andy Wilkinson

Streamline Integration Starter and add Java DSL to it

This commit streamlines the Integration Starter by removing the file
http, ip, and stream modules as they are not always used by a majority
of apps that use Spring Integration and can also pull in other, unwanted
dependencies.

Additionally, a dependency on spring-integration-java-dsl has been
added. This makes it easy for users to configure Spring Integration
using Java configuration (the recommended approach), rather than via
XML. The Integration sample has been updated to use the DSL. Further
improvements could be made once the sample is using Java 8.

Closes gh-5528
parent e4324a5c
...@@ -147,6 +147,7 @@ ...@@ -147,6 +147,7 @@
<spring-data-releasetrain.version>Hopper-SR1</spring-data-releasetrain.version> <spring-data-releasetrain.version>Hopper-SR1</spring-data-releasetrain.version>
<spring-hateoas.version>0.19.0.RELEASE</spring-hateoas.version> <spring-hateoas.version>0.19.0.RELEASE</spring-hateoas.version>
<spring-integration.version>4.3.0.M1</spring-integration.version> <spring-integration.version>4.3.0.M1</spring-integration.version>
<spring-integration-java-dsl.version>1.1.2.RELEASE</spring-integration-java-dsl.version>
<spring-loaded.version>1.2.5.RELEASE</spring-loaded.version> <spring-loaded.version>1.2.5.RELEASE</spring-loaded.version>
<spring-mobile.version>1.1.5.RELEASE</spring-mobile.version> <spring-mobile.version>1.1.5.RELEASE</spring-mobile.version>
<spring-plugin.version>1.2.0.RELEASE</spring-plugin.version> <spring-plugin.version>1.2.0.RELEASE</spring-plugin.version>
...@@ -2064,6 +2065,11 @@ ...@@ -2064,6 +2065,11 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-java-dsl</artifactId>
<version>${spring-integration-java-dsl.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.mobile</groupId> <groupId>org.springframework.mobile</groupId>
<artifactId>spring-mobile-device</artifactId> <artifactId>spring-mobile-device</artifactId>
......
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-file</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.integration</groupId> <groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-jmx</artifactId> <artifactId>spring-integration-jmx</artifactId>
......
/* /*
* Copyright 2012-2013 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,14 +16,16 @@ ...@@ -16,14 +16,16 @@
package sample.integration; package sample.integration;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;
import org.springframework.stereotype.Component;
@Component @Service
public class HelloWorldService { public class HelloWorldService {
@Autowired private final ServiceProperties configuration;
private ServiceProperties configuration;
public HelloWorldService(ServiceProperties configuration) {
this.configuration = configuration;
}
public String getHelloMessage(String name) { public String getHelloMessage(String name) {
return this.configuration.getGreeting() + " " + name; return this.configuration.getGreeting() + " " + name;
......
/* /*
* Copyright 2012-2013 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -19,7 +19,6 @@ package sample.integration; ...@@ -19,7 +19,6 @@ package sample.integration;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
...@@ -27,8 +26,11 @@ import org.springframework.util.StreamUtils; ...@@ -27,8 +26,11 @@ import org.springframework.util.StreamUtils;
@MessageEndpoint @MessageEndpoint
public class SampleEndpoint { public class SampleEndpoint {
@Autowired private final HelloWorldService helloWorldService;
private HelloWorldService helloWorldService;
public SampleEndpoint(HelloWorldService helloWorldService) {
this.helloWorldService = helloWorldService;
}
@ServiceActivator @ServiceActivator
public String hello(File input) throws Exception { public String hello(File input) throws Exception {
......
/* /*
* Copyright 2012-2013 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,18 +16,69 @@ ...@@ -16,18 +16,69 @@
package sample.integration; package sample.integration;
import java.io.File;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.Bean;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.dsl.SourcePollingChannelAdapterSpec;
import org.springframework.integration.dsl.core.Pollers;
import org.springframework.integration.dsl.support.Consumer;
import org.springframework.integration.file.FileReadingMessageSource;
import org.springframework.integration.file.FileWritingMessageHandler;
@SpringBootApplication @SpringBootApplication
@EnableConfigurationProperties(ServiceProperties.class) @EnableConfigurationProperties(ServiceProperties.class)
@ImportResource("integration-context.xml")
public class SampleIntegrationApplication { public class SampleIntegrationApplication {
@Bean
public FileReadingMessageSource fileReader() {
FileReadingMessageSource reader = new FileReadingMessageSource();
reader.setDirectory(new File("target/input"));
return reader;
}
@Bean
public DirectChannel inputChannel() {
return new DirectChannel();
}
@Bean
public DirectChannel outputChannel() {
return new DirectChannel();
}
@Bean
public FileWritingMessageHandler fileWriter() {
FileWritingMessageHandler writer = new FileWritingMessageHandler(
new File("target/output"));
writer.setExpectReply(false);
return writer;
}
@Bean
public IntegrationFlow integrationFlow(SampleEndpoint endpoint) {
return IntegrationFlows.from(fileReader(), new FixedRatePoller())
.channel(inputChannel()).handle(endpoint).channel(outputChannel())
.handle(fileWriter()).get();
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
SpringApplication.run(SampleIntegrationApplication.class, args); SpringApplication.run(SampleIntegrationApplication.class, args);
} }
private static class FixedRatePoller
implements Consumer<SourcePollingChannelAdapterSpec> {
@Override
public void accept(SourcePollingChannelAdapterSpec spec) {
spec.poller(Pollers.fixedRate(500));
}
}
} }
logging.file: /tmp/logs/app.log
logging.level.org.springframework.integration.file: DEBUG logging.level.org.springframework.integration.file: DEBUG
service.greeting: Hello service.greeting: Hello
debug: true
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-4.3.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<int-file:inbound-channel-adapter channel="input" directory="target/input" filename-pattern="*">
<int:poller fixed-rate="500"/>
</int-file:inbound-channel-adapter>
<int:service-activator input-channel="input" ref="sampleEndpoint" output-channel="output"/>
<int:channel id="output"/>
<int-file:outbound-channel-adapter channel="output" directory="target/output"/>
</beans>
...@@ -32,19 +32,7 @@ ...@@ -32,19 +32,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.integration</groupId> <groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-file</artifactId> <artifactId>spring-integration-java-dsl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-http</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-ip</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-stream</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment