Removing Kinesis samples from spring-cloud-stream-samples Ditmars

This commit is contained in:
Soby Chacko
2018-01-08 14:24:51 -05:00
parent 1204d0fcb4
commit c81c69587a
13 changed files with 0 additions and 648 deletions
-86
View File
@@ -1,86 +0,0 @@
Spring Cloud Stream Kinesis Sample
=============================
In this *Spring Cloud Stream* sample, a Controller exists which can receive POST requests containing Order objects. These Orders are added to a Kinesis Stream. The sample application consumes the Orders from the stream.
## Requirements
To run this sample, you will need to have installed:
* Java 8 or Above
This example requires and AWS account, it will create a Kinesis stream which will be chargeable. The AWS credentials will be obtained using the default credential provider chain.
## Code Tour
This sample is a Spring Boot application that uses Spring Cloud Stream to produce and consume data to a Kinesis Stream. The sample has the following components:
* KinesisApplication - The Spring Boot Main Application
* OrderController - The Controller exposing POST and GET endpoints
* OrderRepository - An in memory database for storing Order objects
* OrderProcessor - An interface defining the input `ordersIn` and output `ordersOut` channel bindings
* OrderSource - The class that produces messages for the stream
* OrderStreamConfiguration - Listens to the Kinesis stream using ` @StreamListener(OrderProcessor.INPUT)` logs receiving messages from the stream
## Building with Maven
Build the sample by executing:
kinesis-produce-consume>$ mvn clean package
## Running the Sample
This sample can be used to demonstrate passing data between applications over a Kinesis stream.
Start the Producer using:
`kinesis-produce-consume>$ java -jar target/spring-cloud-stream-sample-kinesis-0.0.1.BUILD-SNAPSHOT.jar --originator=KinesisProducer --server.port=64398`
Start the Consumer using:
`kinesis-produce-consume>$ java -jar target/spring-cloud-stream-sample-kinesis-0.0.1.BUILD-SNAPSHOT.jar --originator=KinesisConsumer --server.port=64399`
The originator is a key added to messages to tell the receiving application who sent the message. If the receiver sent the message nothing is done, if the receiver did not send the message then it is saved to an in memory database.
To use the sample POST a message to the Producer
`curl -X POST
http://localhost:64398/
-H 'authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
-H 'cache-control: no-cache'
-H 'content-type: application/json'
-d '{"name":"pen"}'`
Note: Match the authorization with the password in application.properties
Observe the logs and the AWS Kinesis Stream to see the produce and consume of that message.
* A log of placing a message on the stream
`2017-09-13 13:26:31.851 INFO 2807 --- [io-64398-exec-1] demo.stream.OrdersSource: Event sent: Event [id=null, subject=Order [id=c2d15e39-bbfa-4966-bd55-6a114045f18c, name=pencil], type=ORDER, originator=KinesisProducer]`
* A log of consuming a message from the stream
`2017-09-13 13:26:43.059 INFO 2807 --- [esis-consumer-1] uration$$EnhancerBySpringCGLIB$$15bce6e7: An order has been placed from this service Event [id=null, subject=Order [id=c2d15e39-bbfa-4966-bd55-6a114045f18c, name=pencil], type=ORDER, originator=KinesisProducer]`
Then run a GET request against the Consumer
`curl -X GET \
http://localhost:64399/orders \
-H 'authorization: Basic xxxxxxxxxxxxxxxxxxxxxx \
-H 'cache-control: no-cache' \
`
The returned Order should match the Order that was POSTed to the Producer.
`[
{
"id": "c2d15e39-bbfa-4966-bd55-6a114045f18c",
"name": "pencil"
}
]`
-88
View File
@@ -1,88 +0,0 @@
<?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>
<artifactId>spring-cloud-stream-sample-kinesis</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-cloud-stream-sample-kinesis</name>
<description>Demo project for spring-cloud-stream-kinesis-binder</description>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-samples</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
</parent>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>demo.KinesisApplication</start-class>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
<version>1.3.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-kinesis</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
@@ -1,34 +0,0 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
*
* @author Peter Oates
*
*/
@SpringBootApplication
public class KinesisApplication {
public static void main(String[] args) {
SpringApplication.run(KinesisApplication.class, args);
}
}
@@ -1,64 +0,0 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package demo.controller;
import org.springframework.beans.factory.annotation.*;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;
import demo.data.*;
import demo.repository.*;
import demo.stream.*;
/**
*
* @author Peter Oates
*
*/
@RestController
public class OrderController {
@Autowired
private OrderRepository orders;
@Autowired
private OrdersSource orderSource;
@Value("${originator}")
private String originator;
@RequestMapping(value = "/orders", method = RequestMethod.GET, produces = { "application/json" })
@ResponseStatus(HttpStatus.OK)
public Iterable<Order> getOrder() {
Iterable<Order> orderList = orders.findAll();
return orderList;
}
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Order> add(@RequestBody Order input) {
orders.save(input);
// place order on Kinesis Stream
orderSource.sendOrder(new Event(input, "ORDER", originator));
return new ResponseEntity<Order>(input, HttpStatus.OK);
}
}
@@ -1,68 +0,0 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package demo.data;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
*
* @author Peter Oates
*
*/
@Entity
@Table(name = "ORDER_TB")
public class Order {
@Id
@Column(name = "ID")
private UUID id;
@Column(name = "NAME")
private String name;
public Order() {
id = UUID.randomUUID();
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String item) {
this.name = item;
}
@Override
public String toString() {
return "Order [id=" + id + ", name=" + name + "]";
}
}
@@ -1,34 +0,0 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package demo.repository;
import java.util.UUID;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import demo.data.Order;
/**
*
* @author Peter Oates
*
*/
@Repository
public interface OrderRepository extends CrudRepository<Order, UUID> {
}
@@ -1,85 +0,0 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package demo.stream;
import java.util.UUID;
import demo.data.Order;
/**
*
* @author Peter Oates
*
*/
public class Event {
private UUID id;
private Order subject;
private String type;
private String originator;
public Event() {
}
public Event(Order subject, String type, String originator) {
this.subject = subject;
this.type = type;
this.originator = originator;
}
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public Order getSubject() {
return subject;
}
public void setSubject(Order subject) {
this.subject = subject;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getOriginator() {
return originator;
}
public void setOriginator(String originator) {
this.originator = originator;
}
@Override
public String toString() {
return "Event [id=" + id + ", subject=" + subject + ", type=" + type + ", originator=" + originator + "]";
}
}
@@ -1,39 +0,0 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package demo.stream;
import org.springframework.cloud.stream.annotation.Input;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.SubscribableChannel;
/**
*
* @author Peter Oates
*
*/
public interface OrderProcessor {
String INPUT = "ordersIn";
@Output
MessageChannel ordersOut();
@Input
SubscribableChannel ordersIn();
}
@@ -1,53 +0,0 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package demo.stream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import demo.repository.OrderRepository;
/**
*
* @author Peter Oates
*
*/
@EnableBinding(OrderProcessor.class)
public class OrderStreamConfiguration {
private final Log logger = LogFactory.getLog(getClass());
@Autowired
private OrderRepository orders;
@StreamListener(OrderProcessor.INPUT)
public void processOrder(Event event) {
//log the order received
if (!event.getOriginator().equals("KinesisProducer")) {
logger.info("An order has been received " + event.toString());
orders.save(event.getSubject());
}
else {
logger.info("An order has been placed from this service " + event.toString());
}
}
}
@@ -1,50 +0,0 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package demo.stream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;
/**
*
* @author Peter Oates
*
*/
@Component
public class OrdersSource {
private final Log logger = LogFactory.getLog(getClass());
private OrderProcessor orderOut;
@Autowired
public OrdersSource(OrderProcessor orderOut) {
this.orderOut = orderOut;
}
public void sendOrder(Event event) {
orderOut.ordersOut().send(new GenericMessage<>(event));
logger.info("Event sent: " + event.toString());
}
}
@@ -1,40 +0,0 @@
originator: KinesisProducer
server:
port: 64398
management:
port: 8082
context-path: /manage
security:
user:
name: admin
password: 2c76788d-e661-49fd-baba-4b41e7c1dd47
spring:
cloud:
stream:
bindings:
ordersOut:
destination: test_stream
content-type: application/json
producer:
partitionKeyExpression: "1"
ordersIn:
destination: test_stream
content-type: application/json
cloud:
aws:
region:
static: eu-west-1
logging:
level:
com:
amazonaws: INFO
org:
apache:
http: INFO
@@ -1,6 +0,0 @@
spring:
application:
name: KinesisProducerConsumer
-1
View File
@@ -33,7 +33,6 @@
<module>stream-listener</module>
<module>reactive-processor-kafka</module>
<module>test-embedded-kafka</module>
<module>kinesis-produce-consume</module>
<module>kstream</module>
<module>testing</module>
</modules>