Skip to content

Commit cb6e84c

Browse files
norbertoritzmannpivovarit
authored andcommitted
New Article - ETL with Spring Cloud Data Flow (eugenp#5388)
* Including the ETL files to the repository * Rename READMET.md to README.MD Renamed to correct README. * Update README.MD Additional line brakes * Formatting * Removing unecessary autogenerated files
1 parent a199954 commit cb6e84c

14 files changed

Lines changed: 296 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Overview
2+
This is an example of a ETL stream pipeline, mixing a starter application with custom transform and sink.
3+
4+
# Applications
5+
JDBC Source - Application Starter distributed by default
6+
7+
customer-transform - Custom application to transform the data
8+
9+
customer-mongodb-sink - Custom application to sink the data
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.customer</groupId>
8+
<artifactId>customer-mongodb-sink</artifactId>
9+
<packaging>jar</packaging>
10+
11+
<name>customer-mongodb-sink</name>
12+
<description>Example ETL Load Project</description>
13+
14+
<parent>
15+
<artifactId>parent-boot-2</artifactId>
16+
<groupId>com.baeldung</groupId>
17+
<version>0.0.1-SNAPSHOT</version>
18+
<relativePath>../../../parent-boot-2</relativePath>
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
26+
</properties>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.springframework.cloud</groupId>
31+
<artifactId>spring-cloud-stream</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.cloud</groupId>
35+
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-data-mongodb</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-test</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.springframework.cloud</groupId>
48+
<artifactId>spring-cloud-stream-test-support</artifactId>
49+
<scope>test</scope>
50+
</dependency>
51+
</dependencies>
52+
53+
<dependencyManagement>
54+
<dependencies>
55+
<dependency>
56+
<groupId>org.springframework.cloud</groupId>
57+
<artifactId>spring-cloud-dependencies</artifactId>
58+
<version>${spring-cloud.version}</version>
59+
<type>pom</type>
60+
<scope>import</scope>
61+
</dependency>
62+
</dependencies>
63+
</dependencyManagement>
64+
65+
<build>
66+
<plugins>
67+
<plugin>
68+
<groupId>org.springframework.boot</groupId>
69+
<artifactId>spring-boot-maven-plugin</artifactId>
70+
</plugin>
71+
</plugins>
72+
</build>
73+
74+
75+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.customer.customermongodbsink;
2+
3+
import org.springframework.data.mongodb.core.mapping.Document;
4+
5+
@Document(collection = "customer")
6+
public class Customer {
7+
8+
private Long id;
9+
private String name;
10+
11+
public Long getId() {
12+
return id;
13+
}
14+
15+
public void setId(Long id) {
16+
this.id = id;
17+
}
18+
19+
public String getName() {
20+
return name;
21+
}
22+
23+
public void setName(String name) {
24+
this.name = name;
25+
}
26+
27+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.customer.customermongodbsink;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.cloud.stream.annotation.EnableBinding;
5+
import org.springframework.cloud.stream.annotation.StreamListener;
6+
import org.springframework.cloud.stream.messaging.Sink;
7+
8+
@EnableBinding(Sink.class)
9+
public class CustomerListener {
10+
11+
@Autowired
12+
private CustomerRepository repository;
13+
14+
@StreamListener(Sink.INPUT)
15+
public void save(Customer customer) {
16+
repository.save(customer);
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.customer.customermongodbsink;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class CustomerMongodbSinkApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(CustomerMongodbSinkApplication.class, args);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.customer.customermongodbsink;
2+
3+
import org.springframework.data.mongodb.repository.MongoRepository;
4+
import org.springframework.stereotype.Repository;
5+
6+
@Repository
7+
public interface CustomerRepository extends MongoRepository<Customer, Long> {
8+
9+
}

‎spring-cloud-data-flow/etl/customer-mongodb-sink/src/main/resources/application.properties‎

Whitespace-only changes.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.customer</groupId>
8+
<artifactId>customer-transform</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<name>customer-transform</name>
13+
<description>Example transform ETL step</description>
14+
15+
<parent>
16+
<artifactId>parent-boot-2</artifactId>
17+
<groupId>com.baeldung</groupId>
18+
<version>0.0.1-SNAPSHOT</version>
19+
<relativePath>../../../parent-boot-2</relativePath>
20+
</parent>
21+
22+
<properties>
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
25+
<java.version>1.8</java.version>
26+
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
27+
</properties>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.springframework.cloud</groupId>
32+
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-test</artifactId>
37+
<scope>test</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.cloud</groupId>
41+
<artifactId>spring-cloud-stream-test-support</artifactId>
42+
<scope>test</scope>
43+
</dependency>
44+
</dependencies>
45+
46+
<dependencyManagement>
47+
<dependencies>
48+
<dependency>
49+
<groupId>org.springframework.cloud</groupId>
50+
<artifactId>spring-cloud-dependencies</artifactId>
51+
<version>${spring-cloud.version}</version>
52+
<type>pom</type>
53+
<scope>import</scope>
54+
</dependency>
55+
</dependencies>
56+
</dependencyManagement>
57+
58+
<build>
59+
<plugins>
60+
<plugin>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-maven-plugin</artifactId>
63+
</plugin>
64+
</plugins>
65+
</build>
66+
67+
68+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.customer.customertransform;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
public class Customer {
6+
7+
private Long id;
8+
9+
private String name;
10+
11+
@JsonProperty("customer_name")
12+
public void setName(String name) {
13+
this.name = name;
14+
}
15+
16+
@JsonProperty("name")
17+
public String getName() {
18+
return name;
19+
}
20+
21+
public Long getId() {
22+
return id;
23+
}
24+
25+
public void setId(Long id) {
26+
this.id = id;
27+
}
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.customer.customertransform;
2+
3+
4+
import org.springframework.cloud.stream.annotation.EnableBinding;
5+
import org.springframework.cloud.stream.messaging.Processor;
6+
import org.springframework.integration.annotation.Transformer;
7+
8+
@EnableBinding(Processor.class)
9+
public class CustomerProcessorConfiguration {
10+
11+
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
12+
public Customer convertToPojo(Customer payload) {
13+
14+
return payload;
15+
}
16+
}

0 commit comments

Comments
 (0)