Skip to content

Instantly share code, notes, and snippets.

@alex3305
Created January 13, 2015 15:00
Show Gist options
  • Save alex3305/39119b34950e2994e831 to your computer and use it in GitHub Desktop.
Save alex3305/39119b34950e2994e831 to your computer and use it in GitHub Desktop.
Spring Integration Java DSL test
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.util.Assert;
@SpringBootApplication
public class Application implements CommandLineRunner {
private static Logger logger = Logger.getLogger(Application.class);
@Autowired
private IntegrationConfiguration configuration;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void run(String... strings) throws Exception {
Assert.notNull(configuration);
DirectChannel inputChannel = configuration.inputChannel();
QueueChannel outputChannel = configuration.outputChannel();
inputChannel.send(new GenericMessage<>("Hello world!"));
logger.warn("==> Demo: " + outputChannel.receive().getPayload());
}
}
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
@Configuration
@EnableIntegration
public class IntegrationConfiguration {
@Bean
public DirectChannel inputChannel() {
return new DirectChannel();
}
@Bean
public QueueChannel outputChannel() {
return new QueueChannel();
}
@Bean
public IntegrationFlow helloWorldFlow() {
return IntegrationFlows.from("inputChannel")
.transform(String.class, String::toUpperCase)
.channel("outputChannel")
.get();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>nl.alex3305</groupId>
<artifactId>spring-batch-integration-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Spring Batch Integration test</name>
<description>Test for DSL configuration with Spring Batch, Integration and Batch Integration</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>Application</start-class>
<java.version>1.7</java.version>
<spring.integration.version>4.1.1.RELEASE</spring.integration.version>
<spring.integration.java.dsl>1.0.1.RELEASE</spring.integration.java.dsl>
<msv.version>2013.6.1</msv.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-java-dsl</artifactId>
<version>${spring.integration.java.dsl}</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-sftp</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-test</artifactId>
<version>${spring.integration.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment