diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000..42bdaef55
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,24 @@
+/application.yml
+/application.properties
+asciidoctor.css
+*~
+.#*
+*#
+target/
+build/
+bin/
+_site/
+.classpath
+.project
+.settings
+.springBeans
+.DS_Store
+*.sw*
+*.iml
+*.ipr
+*.iws
+.idea/*
+.factorypath
+dump.rdb
+.apt_generated
+artifacts
diff --git a/.mvn/jvm.config b/.mvn/jvm.config
new file mode 100644
index 000000000..0e7dabeff
--- /dev/null
+++ b/.mvn/jvm.config
@@ -0,0 +1 @@
+-Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom
\ No newline at end of file
diff --git a/.mvn/maven.config b/.mvn/maven.config
new file mode 100644
index 000000000..3b8cf46e1
--- /dev/null
+++ b/.mvn/maven.config
@@ -0,0 +1 @@
+-DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local -P spring
diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar
new file mode 100644
index 000000000..5fd4d5023
Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ
diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties
new file mode 100644
index 000000000..eb9194764
--- /dev/null
+++ b/.mvn/wrapper/maven-wrapper.properties
@@ -0,0 +1 @@
+distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.3/apache-maven-3.3.3-bin.zip
\ No newline at end of file
diff --git a/.settings.xml b/.settings.xml
new file mode 100644
index 000000000..8b234ce74
--- /dev/null
+++ b/.settings.xml
@@ -0,0 +1,66 @@
+
+
+
+
+ repo.spring.io
+ ${env.CI_DEPLOY_USERNAME}
+ ${env.CI_DEPLOY_PASSWORD}
+
+
+
+
+
+ spring
+ true
+
+
+ spring-snapshots
+ Spring Snapshots
+ http://repo.spring.io/libs-snapshot-local
+
+ true
+
+
+
+ spring-milestones
+ Spring Milestones
+ http://repo.spring.io/libs-milestone-local
+
+ false
+
+
+
+ spring-releases
+ Spring Releases
+ http://repo.spring.io/release
+
+ false
+
+
+
+
+
+ spring-snapshots
+ Spring Snapshots
+ http://repo.spring.io/libs-snapshot-local
+
+ true
+
+
+
+ spring-milestones
+ Spring Milestones
+ http://repo.spring.io/libs-milestone-local
+
+ false
+
+
+
+
+
+
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 000000000..8dada3eda
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "{}"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright {yyyy} {name of copyright owner}
+
+ 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.
diff --git a/README.adoc b/README.adoc
index bc38a291f..05aec3f55 100644
--- a/README.adoc
+++ b/README.adoc
@@ -1 +1,3 @@
# spring-cloud-stream-binder-kafka
+
+Spring Cloud Stream Binder implementation for Kafka
diff --git a/mvnw b/mvnw
new file mode 100755
index 000000000..e3511489f
--- /dev/null
+++ b/mvnw
@@ -0,0 +1,234 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+# ----------------------------------------------------------------------------
+
+# ----------------------------------------------------------------------------
+# Maven2 Start Up Batch script
+#
+# Required ENV vars:
+# ------------------
+# JAVA_HOME - location of a JDK home dir
+#
+# Optional ENV vars
+# -----------------
+# M2_HOME - location of maven2's installed home dir
+# MAVEN_OPTS - parameters passed to the Java VM when running Maven
+# e.g. to debug Maven itself, use
+# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+# ----------------------------------------------------------------------------
+
+if [ -z "$MAVEN_SKIP_RC" ] ; then
+
+ if [ -f /etc/mavenrc ] ; then
+ . /etc/mavenrc
+ fi
+
+ if [ -f "$HOME/.mavenrc" ] ; then
+ . "$HOME/.mavenrc"
+ fi
+
+fi
+
+# OS specific support. $var _must_ be set to either true or false.
+cygwin=false;
+darwin=false;
+mingw=false
+case "`uname`" in
+ CYGWIN*) cygwin=true ;;
+ MINGW*) mingw=true;;
+ Darwin*) darwin=true
+ #
+ # Look for the Apple JDKs first to preserve the existing behaviour, and then look
+ # for the new JDKs provided by Oracle.
+ #
+ if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
+ #
+ # Apple JDKs
+ #
+ export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
+ fi
+
+ if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
+ #
+ # Apple JDKs
+ #
+ export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
+ fi
+
+ if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
+ #
+ # Oracle JDKs
+ #
+ export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
+ fi
+
+ if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
+ #
+ # Apple JDKs
+ #
+ export JAVA_HOME=`/usr/libexec/java_home`
+ fi
+ ;;
+esac
+
+if [ -z "$JAVA_HOME" ] ; then
+ if [ -r /etc/gentoo-release ] ; then
+ JAVA_HOME=`java-config --jre-home`
+ fi
+fi
+
+if [ -z "$M2_HOME" ] ; then
+ ## resolve links - $0 may be a link to maven's home
+ PRG="$0"
+
+ # need this for relative symlinks
+ while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG="`dirname "$PRG"`/$link"
+ fi
+ done
+
+ saveddir=`pwd`
+
+ M2_HOME=`dirname "$PRG"`/..
+
+ # make it fully qualified
+ M2_HOME=`cd "$M2_HOME" && pwd`
+
+ cd "$saveddir"
+ # echo Using m2 at $M2_HOME
+fi
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME=`cygpath --unix "$M2_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+ [ -n "$CLASSPATH" ] &&
+ CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
+fi
+
+# For Migwn, ensure paths are in UNIX format before anything is touched
+if $mingw ; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME="`(cd "$M2_HOME"; pwd)`"
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
+ # TODO classpath?
+fi
+
+if [ -z "$JAVA_HOME" ]; then
+ javaExecutable="`which javac`"
+ if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
+ # readlink(1) is not available as standard on Solaris 10.
+ readLink=`which readlink`
+ if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
+ if $darwin ; then
+ javaHome="`dirname \"$javaExecutable\"`"
+ javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
+ else
+ javaExecutable="`readlink -f \"$javaExecutable\"`"
+ fi
+ javaHome="`dirname \"$javaExecutable\"`"
+ javaHome=`expr "$javaHome" : '\(.*\)/bin'`
+ JAVA_HOME="$javaHome"
+ export JAVA_HOME
+ fi
+ fi
+fi
+
+if [ -z "$JAVACMD" ] ; then
+ if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ else
+ JAVACMD="`which java`"
+ fi
+fi
+
+if [ ! -x "$JAVACMD" ] ; then
+ echo "Error: JAVA_HOME is not defined correctly." >&2
+ echo " We cannot execute $JAVACMD" >&2
+ exit 1
+fi
+
+if [ -z "$JAVA_HOME" ] ; then
+ echo "Warning: JAVA_HOME environment variable is not set."
+fi
+
+CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME=`cygpath --path --windows "$M2_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+ [ -n "$CLASSPATH" ] &&
+ CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+fi
+
+# traverses directory structure from process work directory to filesystem root
+# first directory with .mvn subdirectory is considered project base directory
+find_maven_basedir() {
+ local basedir=$(pwd)
+ local wdir=$(pwd)
+ while [ "$wdir" != '/' ] ; do
+ if [ -d "$wdir"/.mvn ] ; then
+ basedir=$wdir
+ break
+ fi
+ wdir=$(cd "$wdir/.."; pwd)
+ done
+ echo "${basedir}"
+}
+
+# concatenates all lines of a file
+concat_lines() {
+ if [ -f "$1" ]; then
+ echo "$(tr -s '\n' ' ' < "$1")"
+ fi
+}
+
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+
+# Provide a "standardized" way to retrieve the CLI args that will
+# work with both Windows and non-Windows executions.
+MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
+export MAVEN_CMD_LINE_ARGS
+
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+exec "$JAVACMD" \
+ $MAVEN_OPTS \
+ -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
+ "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
+ ${WRAPPER_LAUNCHER} "$@"
+
diff --git a/mvnw.cmd b/mvnw.cmd
new file mode 100644
index 000000000..e3511489f
--- /dev/null
+++ b/mvnw.cmd
@@ -0,0 +1,234 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+# ----------------------------------------------------------------------------
+
+# ----------------------------------------------------------------------------
+# Maven2 Start Up Batch script
+#
+# Required ENV vars:
+# ------------------
+# JAVA_HOME - location of a JDK home dir
+#
+# Optional ENV vars
+# -----------------
+# M2_HOME - location of maven2's installed home dir
+# MAVEN_OPTS - parameters passed to the Java VM when running Maven
+# e.g. to debug Maven itself, use
+# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+# ----------------------------------------------------------------------------
+
+if [ -z "$MAVEN_SKIP_RC" ] ; then
+
+ if [ -f /etc/mavenrc ] ; then
+ . /etc/mavenrc
+ fi
+
+ if [ -f "$HOME/.mavenrc" ] ; then
+ . "$HOME/.mavenrc"
+ fi
+
+fi
+
+# OS specific support. $var _must_ be set to either true or false.
+cygwin=false;
+darwin=false;
+mingw=false
+case "`uname`" in
+ CYGWIN*) cygwin=true ;;
+ MINGW*) mingw=true;;
+ Darwin*) darwin=true
+ #
+ # Look for the Apple JDKs first to preserve the existing behaviour, and then look
+ # for the new JDKs provided by Oracle.
+ #
+ if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
+ #
+ # Apple JDKs
+ #
+ export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
+ fi
+
+ if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
+ #
+ # Apple JDKs
+ #
+ export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
+ fi
+
+ if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
+ #
+ # Oracle JDKs
+ #
+ export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
+ fi
+
+ if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
+ #
+ # Apple JDKs
+ #
+ export JAVA_HOME=`/usr/libexec/java_home`
+ fi
+ ;;
+esac
+
+if [ -z "$JAVA_HOME" ] ; then
+ if [ -r /etc/gentoo-release ] ; then
+ JAVA_HOME=`java-config --jre-home`
+ fi
+fi
+
+if [ -z "$M2_HOME" ] ; then
+ ## resolve links - $0 may be a link to maven's home
+ PRG="$0"
+
+ # need this for relative symlinks
+ while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG="`dirname "$PRG"`/$link"
+ fi
+ done
+
+ saveddir=`pwd`
+
+ M2_HOME=`dirname "$PRG"`/..
+
+ # make it fully qualified
+ M2_HOME=`cd "$M2_HOME" && pwd`
+
+ cd "$saveddir"
+ # echo Using m2 at $M2_HOME
+fi
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME=`cygpath --unix "$M2_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+ [ -n "$CLASSPATH" ] &&
+ CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
+fi
+
+# For Migwn, ensure paths are in UNIX format before anything is touched
+if $mingw ; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME="`(cd "$M2_HOME"; pwd)`"
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
+ # TODO classpath?
+fi
+
+if [ -z "$JAVA_HOME" ]; then
+ javaExecutable="`which javac`"
+ if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
+ # readlink(1) is not available as standard on Solaris 10.
+ readLink=`which readlink`
+ if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
+ if $darwin ; then
+ javaHome="`dirname \"$javaExecutable\"`"
+ javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
+ else
+ javaExecutable="`readlink -f \"$javaExecutable\"`"
+ fi
+ javaHome="`dirname \"$javaExecutable\"`"
+ javaHome=`expr "$javaHome" : '\(.*\)/bin'`
+ JAVA_HOME="$javaHome"
+ export JAVA_HOME
+ fi
+ fi
+fi
+
+if [ -z "$JAVACMD" ] ; then
+ if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ else
+ JAVACMD="`which java`"
+ fi
+fi
+
+if [ ! -x "$JAVACMD" ] ; then
+ echo "Error: JAVA_HOME is not defined correctly." >&2
+ echo " We cannot execute $JAVACMD" >&2
+ exit 1
+fi
+
+if [ -z "$JAVA_HOME" ] ; then
+ echo "Warning: JAVA_HOME environment variable is not set."
+fi
+
+CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME=`cygpath --path --windows "$M2_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+ [ -n "$CLASSPATH" ] &&
+ CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+fi
+
+# traverses directory structure from process work directory to filesystem root
+# first directory with .mvn subdirectory is considered project base directory
+find_maven_basedir() {
+ local basedir=$(pwd)
+ local wdir=$(pwd)
+ while [ "$wdir" != '/' ] ; do
+ if [ -d "$wdir"/.mvn ] ; then
+ basedir=$wdir
+ break
+ fi
+ wdir=$(cd "$wdir/.."; pwd)
+ done
+ echo "${basedir}"
+}
+
+# concatenates all lines of a file
+concat_lines() {
+ if [ -f "$1" ]; then
+ echo "$(tr -s '\n' ' ' < "$1")"
+ fi
+}
+
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+
+# Provide a "standardized" way to retrieve the CLI args that will
+# work with both Windows and non-Windows executions.
+MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
+export MAVEN_CMD_LINE_ARGS
+
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+exec "$JAVACMD" \
+ $MAVEN_OPTS \
+ -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
+ "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
+ ${WRAPPER_LAUNCHER} "$@"
+
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 000000000..7af25d3ce
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,94 @@
+
+
+ 4.0.0
+ spring-cloud-stream-binder-kafka-parent
+ 1.1.0.BUILD-SNAPSHOT
+ pom
+
+ org.springframework.cloud
+ spring-cloud-build
+ 1.1.1.RELEASE
+
+
+
+ 1.4.0.BUILD-SNAPSHOT
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-stream-dependencies
+ 1.1.0.BUILD-SNAPSHOT
+ pom
+ import
+
+
+
+
+ spring-cloud-stream-binder-kafka
+ spring-cloud-starter-stream-kafka
+
+
+
+ spring
+
+
+ spring-snapshots
+ Spring Snapshots
+ http://repo.spring.io/libs-snapshot-local
+
+ true
+
+
+ false
+
+
+
+ spring-milestones
+ Spring Milestones
+ http://repo.spring.io/libs-milestone-local
+
+ false
+
+
+
+ spring-releases
+ Spring Releases
+ http://repo.spring.io/release
+
+ false
+
+
+
+
+
+ spring-snapshots
+ Spring Snapshots
+ http://repo.spring.io/libs-snapshot-local
+
+ true
+
+
+ false
+
+
+
+ spring-milestones
+ Spring Milestones
+ http://repo.spring.io/libs-milestone-local
+
+ false
+
+
+
+ spring-releases
+ Spring Releases
+ http://repo.spring.io/libs-release-local
+
+ false
+
+
+
+
+
+
diff --git a/spring-cloud-starter-stream-kafka/pom.xml b/spring-cloud-starter-stream-kafka/pom.xml
new file mode 100644
index 000000000..caaf900ba
--- /dev/null
+++ b/spring-cloud-starter-stream-kafka/pom.xml
@@ -0,0 +1,25 @@
+
+
+ 4.0.0
+
+ org.springframework.cloud
+ spring-cloud-stream-binder-kafka-parent
+ 1.1.0.BUILD-SNAPSHOT
+
+ spring-cloud-starter-stream-kafka
+ Spring Cloud Starter Stream Kafka
+ http://projects.spring.io/spring-cloud
+
+ Pivotal Software, Inc.
+ http://www.spring.io
+
+
+ ${basedir}/../..
+
+
+
+ org.springframework.cloud
+ spring-cloud-stream-binder-kafka
+
+
+
diff --git a/spring-cloud-starter-stream-kafka/src/main/resources/META-INF/spring.provides b/spring-cloud-starter-stream-kafka/src/main/resources/META-INF/spring.provides
new file mode 100644
index 000000000..0aa482658
--- /dev/null
+++ b/spring-cloud-starter-stream-kafka/src/main/resources/META-INF/spring.provides
@@ -0,0 +1 @@
+provides: spring-cloud-stream-binder-kafka
\ No newline at end of file
diff --git a/spring-cloud-stream-binder-kafka/pom.xml b/spring-cloud-stream-binder-kafka/pom.xml
new file mode 100644
index 000000000..3426dc64e
--- /dev/null
+++ b/spring-cloud-stream-binder-kafka/pom.xml
@@ -0,0 +1,143 @@
+
+
+ 4.0.0
+
+ spring-cloud-stream-binder-kafka
+ jar
+ spring-cloud-stream-binder-kafka
+ Kafka binder implementation
+
+
+ org.springframework.cloud
+ spring-cloud-stream-binder-kafka-parent
+ 1.1.0.BUILD-SNAPSHOT
+
+
+
+ 0.8.2.2
+ 2.6.0
+ 1.3.1.BUILD-SNAPSHOT
+ 1.0.0
+
+
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+ org.springframework.cloud
+ spring-cloud-stream
+
+
+ org.springframework.cloud
+ spring-cloud-stream-codec
+
+
+ org.springframework.boot
+ spring-boot-autoconfigure
+ true
+
+
+ org.springframework.cloud
+ spring-cloud-stream-binder-test
+ test
+
+
+ org.springframework.cloud
+ spring-cloud-stream-test-support-internal
+ test
+
+
+ org.springframework.integration
+ spring-integration-kafka
+ ${spring-integration-kafka.version}
+
+
+ org.apache.avro
+ avro-compiler
+
+
+
+
+ org.apache.kafka
+ kafka_2.10
+
+
+ org.apache.kafka
+ kafka-clients
+
+
+ io.reactivex
+ rxjava
+
+
+ io.reactivex
+ rxjava-math
+ ${rxjava-math.version}
+
+
+ org.apache.curator
+ curator-recipes
+ test
+
+
+ org.apache.kafka
+ kafka_2.10
+ test
+ test
+
+
+ org.apache.curator
+ curator-test
+ test
+
+
+
+
+
+
+ org.apache.kafka
+ kafka_2.10
+ ${kafka.version}
+
+
+ org.slf4j
+ slf4j-log4j12
+
+
+ log4j
+ log4j
+
+
+
+
+ org.apache.kafka
+ kafka_2.10
+ test
+ ${kafka.version}
+
+
+ org.apache.kafka
+ kafka-clients
+ ${kafka.version}
+
+
+ org.apache.curator
+ curator-framework
+ ${curator.version}
+
+
+ org.apache.curator
+ curator-recipes
+ ${curator.version}
+
+
+ org.apache.curator
+ curator-test
+ ${curator.version}
+
+
+
+
diff --git a/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaBinderHealthIndicator.java b/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaBinderHealthIndicator.java
new file mode 100644
index 000000000..c523f0854
--- /dev/null
+++ b/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaBinderHealthIndicator.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2016 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 org.springframework.cloud.stream.binder.kafka;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import kafka.cluster.Broker;
+import kafka.utils.ZKStringSerializer$;
+import kafka.utils.ZkUtils$;
+import org.I0Itec.zkclient.ZkClient;
+import scala.collection.JavaConversions;
+import scala.collection.Seq;
+
+import org.springframework.boot.actuate.health.Health;
+import org.springframework.boot.actuate.health.HealthIndicator;
+import org.springframework.cloud.stream.binder.kafka.config.KafkaBinderConfigurationProperties;
+import org.springframework.integration.kafka.core.BrokerAddress;
+import org.springframework.integration.kafka.core.Partition;
+
+/**
+ * Health indicator for Kafka.
+ *
+ * @author Ilayaperumal Gopinathan
+ */
+public class KafkaBinderHealthIndicator implements HealthIndicator {
+
+ private final KafkaMessageChannelBinder binder;
+
+ private final KafkaBinderConfigurationProperties configurationProperties;
+
+ public KafkaBinderHealthIndicator(KafkaMessageChannelBinder binder,
+ KafkaBinderConfigurationProperties configurationProperties) {
+ this.binder = binder;
+ this.configurationProperties = configurationProperties;
+ }
+
+ @Override
+ public Health health() {
+ ZkClient zkClient = null;
+ try {
+ zkClient = new ZkClient(configurationProperties.getZkConnectionString(),
+ configurationProperties.getZkSessionTimeout(),
+ configurationProperties.getZkConnectionTimeout(), ZKStringSerializer$.MODULE$);
+ Set brokersInClusterSet = new HashSet<>();
+ Seq allBrokersInCluster = ZkUtils$.MODULE$.getAllBrokersInCluster(zkClient);
+ Collection brokersInCluster = JavaConversions.asJavaCollection(allBrokersInCluster);
+ for (Broker broker : brokersInCluster) {
+ brokersInClusterSet.add(broker.connectionString());
+ }
+ Set downMessages = new HashSet<>();
+ for (Map.Entry> entry : binder.getTopicsInUse().entrySet()) {
+ for (Partition partition : entry.getValue()) {
+ BrokerAddress address = binder.getConnectionFactory().getLeader(partition);
+ if (!brokersInClusterSet.contains(address.toString())) {
+ downMessages.add(address.toString());
+ }
+ }
+ }
+ if (downMessages.isEmpty()) {
+ return Health.up().build();
+ }
+ return Health.down().withDetail("Following brokers are down: ", downMessages.toString()).build();
+ }
+ catch (Exception e) {
+ return Health.down(e).build();
+ }
+ finally {
+ if (zkClient != null) {
+ try {
+ zkClient.close();
+ }
+ catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+ }
+}
diff --git a/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaBindingProperties.java b/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaBindingProperties.java
new file mode 100644
index 000000000..6bd233d63
--- /dev/null
+++ b/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaBindingProperties.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2016 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 org.springframework.cloud.stream.binder.kafka;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class KafkaBindingProperties {
+
+ private KafkaConsumerProperties consumer = new KafkaConsumerProperties();
+
+ private KafkaProducerProperties producer = new KafkaProducerProperties();
+
+ public KafkaConsumerProperties getConsumer() {
+ return consumer;
+ }
+
+ public void setConsumer(KafkaConsumerProperties consumer) {
+ this.consumer = consumer;
+ }
+
+ public KafkaProducerProperties getProducer() {
+ return producer;
+ }
+
+ public void setProducer(KafkaProducerProperties producer) {
+ this.producer = producer;
+ }
+}
diff --git a/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaConsumerProperties.java b/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaConsumerProperties.java
new file mode 100644
index 000000000..c52a38221
--- /dev/null
+++ b/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaConsumerProperties.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2016 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 org.springframework.cloud.stream.binder.kafka;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class KafkaConsumerProperties {
+
+ private boolean autoCommitOffset = true;
+
+ private Boolean autoCommitOnError;
+
+ private boolean resetOffsets;
+
+ private KafkaMessageChannelBinder.StartOffset startOffset;
+
+ private boolean enableDlq;
+
+ private int recoveryInterval = 5000;
+
+ public boolean isAutoCommitOffset() {
+ return autoCommitOffset;
+ }
+
+ public void setAutoCommitOffset(boolean autoCommitOffset) {
+ this.autoCommitOffset = autoCommitOffset;
+ }
+
+ public boolean isResetOffsets() {
+ return resetOffsets;
+ }
+
+ public void setResetOffsets(boolean resetOffsets) {
+ this.resetOffsets = resetOffsets;
+ }
+
+ public KafkaMessageChannelBinder.StartOffset getStartOffset() {
+ return startOffset;
+ }
+
+ public void setStartOffset(KafkaMessageChannelBinder.StartOffset startOffset) {
+ this.startOffset = startOffset;
+ }
+
+ public boolean isEnableDlq() {
+ return enableDlq;
+ }
+
+ public void setEnableDlq(boolean enableDlq) {
+ this.enableDlq = enableDlq;
+ }
+
+ public Boolean getAutoCommitOnError() {
+ return autoCommitOnError;
+ }
+
+ public void setAutoCommitOnError(Boolean autoCommitOnError) {
+ this.autoCommitOnError = autoCommitOnError;
+ }
+
+ public int getRecoveryInterval() {
+ return recoveryInterval;
+ }
+
+ public void setRecoveryInterval(int recoveryInterval) {
+ this.recoveryInterval = recoveryInterval;
+ }
+}
diff --git a/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaExtendedBindingProperties.java b/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaExtendedBindingProperties.java
new file mode 100644
index 000000000..637d14a35
--- /dev/null
+++ b/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaExtendedBindingProperties.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2016 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 org.springframework.cloud.stream.binder.kafka;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.cloud.stream.binder.ExtendedBindingProperties;
+
+/**
+ * @author Marius Bogoevici
+ */
+@ConfigurationProperties("spring.cloud.stream.kafka")
+public class KafkaExtendedBindingProperties implements ExtendedBindingProperties {
+
+ private Map bindings = new HashMap<>();
+
+ public Map getBindings() {
+ return bindings;
+ }
+
+ public void setBindings(Map bindings) {
+ this.bindings = bindings;
+ }
+
+ @Override
+ public KafkaConsumerProperties getExtendedConsumerProperties(String channelName) {
+ if (bindings.containsKey(channelName) && bindings.get(channelName).getConsumer() != null) {
+ return bindings.get(channelName).getConsumer();
+ }
+ else {
+ return new KafkaConsumerProperties();
+ }
+ }
+
+ @Override
+ public KafkaProducerProperties getExtendedProducerProperties(String channelName) {
+ if (bindings.containsKey(channelName) && bindings.get(channelName).getProducer() != null) {
+ return bindings.get(channelName).getProducer();
+ }
+ else {
+ return new KafkaProducerProperties();
+ }
+ }
+}
diff --git a/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaMessageChannelBinder.java b/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaMessageChannelBinder.java
new file mode 100644
index 000000000..359fd4d5c
--- /dev/null
+++ b/spring-cloud-stream-binder-kafka/src/main/java/org/springframework/cloud/stream/binder/kafka/KafkaMessageChannelBinder.java
@@ -0,0 +1,800 @@
+/*
+ * Copyright 2014-2016 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 org.springframework.cloud.stream.binder.kafka;
+
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Properties;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import kafka.admin.AdminUtils;
+import kafka.api.OffsetRequest;
+import kafka.api.TopicMetadata;
+import kafka.common.ErrorMapping;
+import kafka.serializer.Decoder;
+import kafka.serializer.DefaultDecoder;
+import kafka.utils.ZKStringSerializer$;
+import kafka.utils.ZkUtils;
+import org.I0Itec.zkclient.ZkClient;
+import org.apache.kafka.clients.producer.Callback;
+import org.apache.kafka.clients.producer.Producer;
+import org.apache.kafka.clients.producer.ProducerConfig;
+import org.apache.kafka.clients.producer.ProducerRecord;
+import org.apache.kafka.clients.producer.RecordMetadata;
+import org.apache.kafka.common.serialization.ByteArraySerializer;
+import org.apache.kafka.common.utils.Utils;
+import scala.collection.Seq;
+
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.cloud.stream.binder.AbstractBinder;
+import org.springframework.cloud.stream.binder.Binder;
+import org.springframework.cloud.stream.binder.BinderException;
+import org.springframework.cloud.stream.binder.BinderHeaders;
+import org.springframework.cloud.stream.binder.Binding;
+import org.springframework.cloud.stream.binder.DefaultBinding;
+import org.springframework.cloud.stream.binder.ExtendedConsumerProperties;
+import org.springframework.cloud.stream.binder.ExtendedProducerProperties;
+import org.springframework.cloud.stream.binder.ExtendedPropertiesBinder;
+import org.springframework.cloud.stream.binder.HeaderMode;
+import org.springframework.cloud.stream.binder.MessageValues;
+import org.springframework.cloud.stream.binder.PartitionHandler;
+import org.springframework.cloud.stream.binder.kafka.config.KafkaBinderConfigurationProperties;
+import org.springframework.http.MediaType;
+import org.springframework.integration.channel.FixedSubscriberChannel;
+import org.springframework.integration.endpoint.EventDrivenConsumer;
+import org.springframework.integration.handler.AbstractMessageHandler;
+import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
+import org.springframework.integration.kafka.core.ConnectionFactory;
+import org.springframework.integration.kafka.core.DefaultConnectionFactory;
+import org.springframework.integration.kafka.core.KafkaMessage;
+import org.springframework.integration.kafka.core.Partition;
+import org.springframework.integration.kafka.core.ZookeeperConfiguration;
+import org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter;
+import org.springframework.integration.kafka.listener.AcknowledgingMessageListener;
+import org.springframework.integration.kafka.listener.Acknowledgment;
+import org.springframework.integration.kafka.listener.ErrorHandler;
+import org.springframework.integration.kafka.listener.KafkaMessageListenerContainer;
+import org.springframework.integration.kafka.listener.KafkaNativeOffsetManager;
+import org.springframework.integration.kafka.listener.MessageListener;
+import org.springframework.integration.kafka.listener.OffsetManager;
+import org.springframework.integration.kafka.support.KafkaHeaders;
+import org.springframework.integration.kafka.support.ProducerConfiguration;
+import org.springframework.integration.kafka.support.ProducerFactoryBean;
+import org.springframework.integration.kafka.support.ProducerListener;
+import org.springframework.integration.kafka.support.ProducerMetadata;
+import org.springframework.integration.kafka.support.ZookeeperConnect;
+import org.springframework.messaging.Message;
+import org.springframework.messaging.MessageChannel;
+import org.springframework.messaging.MessageHandler;
+import org.springframework.messaging.MessageHeaders;
+import org.springframework.messaging.SubscribableChannel;
+import org.springframework.messaging.support.MessageBuilder;
+import org.springframework.retry.RetryCallback;
+import org.springframework.retry.RetryContext;
+import org.springframework.retry.RetryOperations;
+import org.springframework.retry.backoff.ExponentialBackOffPolicy;
+import org.springframework.retry.policy.SimpleRetryPolicy;
+import org.springframework.retry.support.RetryTemplate;
+import org.springframework.scheduling.concurrent.CustomizableThreadFactory;
+import org.springframework.util.Assert;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.ObjectUtils;
+import org.springframework.util.StringUtils;
+
+/**
+ * A {@link Binder} that uses Kafka as the underlying middleware.
+ *
+ * @author Eric Bottard
+ * @author Marius Bogoevici
+ * @author Ilayaperumal Gopinathan
+ * @author David Turanski
+ * @author Gary Russell
+ * @author Mark Fisher
+ * @author Soby Chacko
+ */
+public class KafkaMessageChannelBinder extends
+ AbstractBinder, ExtendedProducerProperties>
+ implements ExtendedPropertiesBinder,
+ DisposableBean {
+
+ public static final ByteArraySerializer BYTE_ARRAY_SERIALIZER = new ByteArraySerializer();
+
+ public static final ThreadFactory DAEMON_THREAD_FACTORY;
+
+ static {
+ CustomizableThreadFactory threadFactory = new CustomizableThreadFactory("kafka-binder-");
+ threadFactory.setDaemon(true);
+ DAEMON_THREAD_FACTORY = threadFactory;
+ }
+
+ private final KafkaBinderConfigurationProperties configurationProperties;
+
+ private final String[] headersToMap;
+
+ private RetryOperations metadataRetryOperations;
+
+ private final Map> topicsInUse = new HashMap<>();
+
+ // -------- Default values for properties -------
+
+ private ConnectionFactory connectionFactory;
+
+ private ProducerListener producerListener;
+
+ private volatile Producer dlqProducer;
+
+ private KafkaExtendedBindingProperties extendedBindingProperties = new KafkaExtendedBindingProperties();
+
+ public KafkaMessageChannelBinder(KafkaBinderConfigurationProperties configurationProperties) {
+ this.configurationProperties = configurationProperties;
+ String[] configuredHeaders = configurationProperties.getHeaders();
+ if (ObjectUtils.isEmpty(configuredHeaders)) {
+ this.headersToMap = BinderHeaders.STANDARD_HEADERS;
+ }
+ else {
+ String[] combinedHeadersToMap = Arrays.copyOfRange(BinderHeaders.STANDARD_HEADERS, 0,
+ BinderHeaders.STANDARD_HEADERS.length + configuredHeaders.length);
+ System.arraycopy(configuredHeaders, 0, combinedHeadersToMap, BinderHeaders.STANDARD_HEADERS.length,
+ configuredHeaders.length);
+ this.headersToMap = combinedHeadersToMap;
+ }
+ }
+
+ String getZkAddress() {
+ return this.configurationProperties.getZkConnectionString();
+ }
+
+ public ConnectionFactory getConnectionFactory() {
+ return connectionFactory;
+ }
+
+ public void setProducerListener(ProducerListener producerListener) {
+ this.producerListener = producerListener;
+ }
+
+ /**
+ * Retry configuration for operations such as validating topic creation
+ * @param metadataRetryOperations the retry configuration
+ */
+ public void setMetadataRetryOperations(RetryOperations metadataRetryOperations) {
+ this.metadataRetryOperations = metadataRetryOperations;
+ }
+
+ public void setExtendedBindingProperties(KafkaExtendedBindingProperties extendedBindingProperties) {
+ this.extendedBindingProperties = extendedBindingProperties;
+ }
+
+ @Override
+ public void onInit() throws Exception {
+ ZookeeperConfiguration configuration = new ZookeeperConfiguration(
+ new ZookeeperConnect(configurationProperties.getZkConnectionString()));
+ configuration.setBufferSize(configurationProperties.getSocketBufferSize());
+ configuration.setMaxWait(configurationProperties.getMaxWait());
+ DefaultConnectionFactory defaultConnectionFactory = new DefaultConnectionFactory(configuration);
+ defaultConnectionFactory.afterPropertiesSet();
+ this.connectionFactory = defaultConnectionFactory;
+ if (metadataRetryOperations == null) {
+ RetryTemplate retryTemplate = new RetryTemplate();
+
+ SimpleRetryPolicy simpleRetryPolicy = new SimpleRetryPolicy();
+ simpleRetryPolicy.setMaxAttempts(10);
+ retryTemplate.setRetryPolicy(simpleRetryPolicy);
+
+ ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
+ backOffPolicy.setInitialInterval(100);
+ backOffPolicy.setMultiplier(2);
+ backOffPolicy.setMaxInterval(1000);
+ retryTemplate.setBackOffPolicy(backOffPolicy);
+ metadataRetryOperations = retryTemplate;
+ }
+ }
+
+ @Override
+ public void destroy() throws Exception {
+ if (dlqProducer != null) {
+ dlqProducer.close();
+ dlqProducer = null;
+ }
+ }
+
+ /**
+ * Allowed chars are ASCII alphanumerics, '.', '_' and '-'.
+ */
+ public static void validateTopicName(String topicName) {
+ try {
+ byte[] utf8 = topicName.getBytes("UTF-8");
+ for (byte b : utf8) {
+ if (!((b >= 'a') && (b <= 'z') || (b >= 'A') && (b <= 'Z') || (b >= '0') && (b <= '9') || (b == '.')
+ || (b == '-') || (b == '_'))) {
+ throw new IllegalArgumentException(
+ "Topic name can only have ASCII alphanumerics, '.', '_' and '-'");
+ }
+ }
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new AssertionError(e); // Can't happen
+ }
+ }
+
+ @Override
+ public KafkaConsumerProperties getExtendedConsumerProperties(String channelName) {
+ return extendedBindingProperties.getExtendedConsumerProperties(channelName);
+ }
+
+ @Override
+ public KafkaProducerProperties getExtendedProducerProperties(String channelName) {
+ return extendedBindingProperties.getExtendedProducerProperties(channelName);
+ }
+
+ Map> getTopicsInUse() {
+ return this.topicsInUse;
+ }
+
+ @Override
+ protected Binding doBindConsumer(String name, String group, MessageChannel inputChannel,
+ ExtendedConsumerProperties properties) {
+ // If the caller provides a consumer group, use it; otherwise an anonymous
+ // consumer group
+ // is generated each time, such that each anonymous binding will receive all
+ // messages.
+ // Consumers reset offsets at the latest time by default, which allows them to
+ // receive only
+ // messages sent after they've been bound. That behavior can be changed with the
+ // "resetOffsets" and "startOffset" properties.
+ boolean anonymous = !StringUtils.hasText(group);
+ Assert.isTrue(!anonymous || !properties.getExtension().isEnableDlq(),
+ "DLQ support is not available for anonymous subscriptions");
+ String consumerGroup = anonymous ? "anonymous." + UUID.randomUUID().toString() : group;
+ // The reference point, if not set explicitly is the latest time for anonymous
+ // subscriptions and the
+ // earliest time for group subscriptions. This allows the latter to receive
+ // messages published before the group
+ // has been created.
+ long referencePoint = properties.getExtension().getStartOffset() != null
+ ? properties.getExtension().getStartOffset().getReferencePoint()
+ : (anonymous ? OffsetRequest.LatestTime() : OffsetRequest.EarliestTime());
+ return createKafkaConsumer(name, inputChannel, properties, consumerGroup, referencePoint);
+ }
+
+ @Override
+ public Binding doBindProducer(String name, MessageChannel moduleOutputChannel,
+ ExtendedProducerProperties properties) {
+
+ Assert.isInstanceOf(SubscribableChannel.class, moduleOutputChannel);
+ if (logger.isInfoEnabled()) {
+ logger.info("Using kafka topic for outbound: " + name);
+ }
+
+ validateTopicName(name);
+
+ Collection partitions = ensureTopicCreated(name, properties.getPartitionCount());
+
+ if (properties.getPartitionCount() < partitions.size()) {
+ if (logger.isInfoEnabled()) {
+ logger.info("The `partitionCount` of the producer for topic " + name + " is "
+ + properties.getPartitionCount() + ", smaller than the actual partition count of "
+ + partitions.size() + " of the topic. The larger number will be used instead.");
+ }
+ }
+
+ topicsInUse.put(name, partitions);
+
+ ProducerMetadata producerMetadata = new ProducerMetadata<>(name, byte[].class, byte[].class,
+ BYTE_ARRAY_SERIALIZER, BYTE_ARRAY_SERIALIZER);
+ producerMetadata.setSync(properties.getExtension().isSync());
+ producerMetadata.setCompressionType(properties.getExtension().getCompressionType());
+ producerMetadata.setBatchBytes(properties.getExtension().getBufferSize());
+ Properties additionalProps = new Properties();
+ additionalProps.put(ProducerConfig.ACKS_CONFIG, String.valueOf(configurationProperties.getRequiredAcks()));
+ additionalProps.put(ProducerConfig.LINGER_MS_CONFIG,
+ String.valueOf(properties.getExtension().getBatchTimeout()));
+ ProducerFactoryBean producerFB = new ProducerFactoryBean<>(producerMetadata,
+ configurationProperties.getKafkaConnectionString(), additionalProps);
+
+ try {
+ final ProducerConfiguration producerConfiguration = new ProducerConfiguration<>(
+ producerMetadata, producerFB.getObject());
+ producerConfiguration.setProducerListener(producerListener);
+
+ MessageHandler handler = new SendingHandler(name, properties, partitions.size(), producerConfiguration);
+ EventDrivenConsumer consumer = new EventDrivenConsumer((SubscribableChannel) moduleOutputChannel, handler) {
+
+ @Override
+ protected void doStop() {
+ super.doStop();
+ producerConfiguration.stop();
+ }
+ };
+ consumer.setBeanFactory(this.getBeanFactory());
+ consumer.setBeanName("outbound." + name);
+ consumer.afterPropertiesSet();
+ DefaultBinding producerBinding = new DefaultBinding<>(name, null, moduleOutputChannel,
+ consumer);
+ consumer.start();
+ return producerBinding;
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Creates a Kafka topic if needed, or try to increase its partition count to the
+ * desired number.
+ */
+ private Collection ensureTopicCreated(final String topicName, final int partitionCount) {
+
+ final ZkClient zkClient = new ZkClient(configurationProperties.getZkConnectionString(),
+ configurationProperties.getZkSessionTimeout(), configurationProperties.getZkConnectionTimeout(),
+ ZKStringSerializer$.MODULE$);
+ try {
+ final Properties topicConfig = new Properties();
+ TopicMetadata topicMetadata = AdminUtils.fetchTopicMetadataFromZk(topicName, zkClient);
+ if (topicMetadata.errorCode() == ErrorMapping.NoError()) {
+ // only consider minPartitionCount for resizing if autoAddPartitions is
+ // true
+ int effectivePartitionCount = configurationProperties.isAutoAddPartitions()
+ ? Math.max(configurationProperties.getMinPartitionCount(), partitionCount) : partitionCount;
+ if (topicMetadata.partitionsMetadata().size() < effectivePartitionCount) {
+ if (configurationProperties.isAutoAddPartitions()) {
+ AdminUtils.addPartitions(zkClient, topicName, effectivePartitionCount, null, false,
+ new Properties());
+ }
+ else {
+ int topicSize = topicMetadata.partitionsMetadata().size();
+ throw new BinderException("The number of expected partitions was: " + partitionCount + ", but "
+ + topicSize + (topicSize > 1 ? " have " : " has ") + "been found instead."
+ + "Consider either increasing the partition count of the topic or enabling `autoAddPartitions`");
+ }
+ }
+ }
+ else if (topicMetadata.errorCode() == ErrorMapping.UnknownTopicOrPartitionCode()) {
+ if (configurationProperties.isAutoCreateTopics()) {
+ Seq