Skip to content

Commit

Permalink
Adding spring cloud stream producer example
Browse files Browse the repository at this point in the history
  • Loading branch information
ctoestreich committed Jul 26, 2016
1 parent 8923f4a commit b7fa4be
Show file tree
Hide file tree
Showing 49 changed files with 2,001 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docker/build-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# Create Dockerfile for consumer and producer
sed "s|{RELEASE_VERSION}|$RELEASE_VERSION|g;" $SCRIPT_DIR/consumer/Dockerfile.template > $SCRIPT_DIR/consumer/Dockerfile
sed "s|{RELEASE_VERSION}|$RELEASE_VERSION|g;" $SCRIPT_DIR/producer/Dockerfile.template > $SCRIPT_DIR/producer/Dockerfile
sed "s|{RELEASE_VERSION}|$RELEASE_VERSION|g;" $SCRIPT_DIR/stream/Dockerfile.template > $SCRIPT_DIR/stream/Dockerfile

cd ..

./gradlew :gr8-rest-producer:clean :gr8-rest-producer:assemble
cp -rf gr8-rest-producer/build/libs/gr8-rest-producer-0.1.jar docker/producer
./gradlew :gr8-rest-consumer:clean :gr8-rest-consumer:assemble
cp -rf gr8-rest-consumer/build/libs/gr8-rest-consumer-0.1.jar docker/consumer
./gradlew :gr8-rest-stream-producer:clean :gr8-rest-stream-producer:assemble
cp -rf gr8-rest-stream-producer/build/libs/gr8-rest-stream-producer-0.1.jar docker/stream

cd docker

Expand Down
12 changes: 12 additions & 0 deletions docker/stream/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM java:openjdk-8u91-jdk

EXPOSE 8080

ADD bin/wait-for-it.sh /wait-for-it.sh

# FIXME: fix /app volume issue with jdk base image.
RUN mkdir -p /stream

ADD gr8-rest-stream-producer-0.1.jar /stream/stream.jar

CMD /bin/sh -c "/wait-for-it.sh redis:6379 --strict && /wait-for-it.sh kafka:9092 --strict && java -jar /stream/stream.jar --spring.profiles.active=docker"
160 changes: 160 additions & 0 deletions docker/stream/bin/wait-for-it.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available
# Note: From https://github.com/vishnubob/wait-for-it/blob/20c60949dedb74a34b06cb954ddd0d71a3c1c769/wait-for-it.sh

cmdname=$(basename $0)

echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }

usage()
{
cat << USAGE >&2
Usage:
$cmdname host:port [-s] [-t timeout] [-- command args]
-h HOST | --host=HOST Host or IP under test
-p PORT | --port=PORT TCP port under test
Alternatively, you specify the host and port as host:port
-s | --strict Only execute subcommand if the test succeeds
-q | --quiet Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
}

wait_for()
{
if [[ $TIMEOUT -gt 0 ]]; then
echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT"
else
echoerr "$cmdname: waiting for $HOST:$PORT without a timeout"
fi
start_ts=$(date +%s)
while :
do
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
result=$?
if [[ $result -eq 0 ]]; then
end_ts=$(date +%s)
echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"
break
fi
sleep 1
done
return $result
}

wait_for_wrapper()
{
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
if [[ $QUIET -eq 1 ]]; then
timeout $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
else
timeout $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
fi
PID=$!
trap "kill -INT -$PID" INT
wait $PID
RESULT=$?
if [[ $RESULT -ne 0 ]]; then
echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT"
fi
return $RESULT
}

# process arguments
while [[ $# -gt 0 ]]
do
case "$1" in
*:* )
hostport=(${1//:/ })
HOST=${hostport[0]}
PORT=${hostport[1]}
shift 1
;;
--child)
CHILD=1
shift 1
;;
-q | --quiet)
QUIET=1
shift 1
;;
-s | --strict)
STRICT=1
shift 1
;;
-h)
HOST="$2"
if [[ $HOST == "" ]]; then break; fi
shift 2
;;
--host=*)
HOST="${1#*=}"
shift 1
;;
-p)
PORT="$2"
if [[ $PORT == "" ]]; then break; fi
shift 2
;;
--port=*)
PORT="${1#*=}"
shift 1
;;
-t)
TIMEOUT="$2"
if [[ $TIMEOUT == "" ]]; then break; fi
shift 2
;;
--timeout=*)
TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
CLI="$@"
break
;;
--help)
usage
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
done

if [[ "$HOST" == "" || "$PORT" == "" ]]; then
echoerr "Error: you need to provide a host and port to test."
usage
fi

TIMEOUT=${TIMEOUT:-15}
STRICT=${STRICT:-0}
CHILD=${CHILD:-0}
QUIET=${QUIET:-0}

if [[ $CHILD -gt 0 ]]; then
RESULT=$(wait_for)
exit $RESULT
else
if [[ $TIMEOUT -gt 0 ]]; then
wait_for_wrapper
RESULT=$?
else
RESULT=$(wait_for)
fi
fi

if [[ $CLI != "" ]]; then
if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then
echoerr "$cmdname: strict mode, refusing to execute subprocess"
exit $RESULT
fi
exec $CLI
else
exit $RESULT
fi
90 changes: 90 additions & 0 deletions gr8-rest-stream-producer/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate4:5.0.2"
classpath "org.grails.plugins:views-gradle:1.0.8"
}
}

version "0.1"
group "gr8.rest.stream.producer"

apply plugin: "idea"
apply plugin: "eclipse"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.plugins.views-json"
apply plugin: "org.grails.grails-gsp"
apply plugin: 'java'

ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}

repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
maven { url 'https://repo.spring.io/libs-snapshot' }
}

dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}

//configurations {
// compile.exclude group: 'log4j', module: 'log4j'
// compile.exclude group: 'org.slf4j', module: 'slf4j-log4j12'
//}

dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.springframework.boot:spring-boot-starter-amqp"
compile 'org.springframework.cloud:spring-cloud-sleuth-core:1.0.3.RELEASE'
compile 'org.springframework.cloud:spring-cloud-sleuth-zipkin:1.0.3.RELEASE'
compile group: 'org.springframework.cloud', name: 'spring-cloud-stream', version: '1.0.2.RELEASE'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-stream-kafka', version: '1.0.2.RELEASE'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-stream-rabbit', version: '1.0.2.RELEASE'
compile "org.grails:grails-plugin-url-mappings"
compile "org.grails:grails-plugin-rest"
compile "org.grails:grails-plugin-codecs"
compile "org.grails:grails-plugin-interceptors"
compile "org.grails:grails-plugin-services"
compile "org.grails:grails-plugin-datasource"
compile "org.grails:grails-plugin-databinding"
compile "org.grails:grails-plugin-async"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-logging"
// compile "org.grails.plugins:cache"
compile "org.grails.plugins:hibernate4"
compile "org.hibernate:hibernate-ehcache"
compile "org.grails.plugins:views-json"
// compile 'org.apache.kafka:kafka_2.10:0.9.0.1'
compile 'org.apache.zookeeper:zookeeper:3.4.8'

console "org.grails:grails-console"
profile "org.grails.profiles:rest-api:${grailsVersion}"
runtime "com.h2database:h2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testCompile "org.grails:grails-datastore-rest-client"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}

task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
2 changes: 2 additions & 0 deletions gr8-rest-stream-producer/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
grailsVersion=3.1.7
gradleWrapperVersion=2.9
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Mon Jul 25 10:23:01 CDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip
Loading

0 comments on commit b7fa4be

Please sign in to comment.