├── .github
└── ISSUE_TEMPLATE
│ └── bug_report.md
├── .gitignore
├── .jdk8
├── .mvn
├── jvm.config
├── maven.config
└── wrapper
│ ├── MavenWrapperDownloader.java
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── .settings.xml
├── LICENSE
├── README.adoc
├── docs
├── .jdk8
├── pom.xml
└── src
│ └── main
│ ├── asciidoc
│ ├── .gitignore
│ ├── Guardfile
│ ├── README.adoc
│ ├── _configprops.adoc
│ ├── appendix.adoc
│ ├── building.adoc
│ ├── contributing.adoc
│ ├── dlq.adoc
│ ├── ghpages.sh
│ ├── images
│ │ ├── kafka-binder.png
│ │ ├── kafka-streams-initializr.png
│ │ └── spring-initializr-kafka-streams.png
│ ├── index-docinfo.xml
│ ├── kafka-streams.adoc
│ ├── overview.adoc
│ ├── partitions.adoc
│ ├── spring-cloud-stream-binder-kafka-aggregate.adoc
│ ├── spring-cloud-stream-binder-kafka.adoc
│ └── tips.adoc
│ └── ruby
│ └── generate_readme.sh
├── mvnw
├── mvnw.cmd
├── pom.xml
├── spring-cloud-starter-stream-kafka
├── .jdk8
└── pom.xml
├── spring-cloud-stream-binder-kafka-core
├── .jdk8
├── .settings
│ └── org.eclipse.jdt.ui.prefs
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── org
│ │ └── springframework
│ │ └── cloud
│ │ └── stream
│ │ └── binder
│ │ └── kafka
│ │ ├── properties
│ │ ├── JaasLoginModuleConfiguration.java
│ │ ├── KafkaBinderConfigurationProperties.java
│ │ ├── KafkaBindingProperties.java
│ │ ├── KafkaConsumerProperties.java
│ │ ├── KafkaExtendedBindingProperties.java
│ │ ├── KafkaProducerProperties.java
│ │ └── KafkaTopicProperties.java
│ │ ├── provisioning
│ │ ├── AdminClientConfigCustomizer.java
│ │ └── KafkaTopicProvisioner.java
│ │ └── utils
│ │ ├── DlqDestinationResolver.java
│ │ ├── DlqPartitionFunction.java
│ │ └── KafkaTopicUtils.java
│ └── test
│ ├── java
│ └── org
│ │ └── springframework
│ │ └── cloud
│ │ └── stream
│ │ └── binder
│ │ └── kafka
│ │ ├── properties
│ │ └── KafkaBinderConfigurationPropertiesTest.java
│ │ └── provisioning
│ │ └── KafkaTopicProvisionerTests.java
│ └── resources
│ ├── test.truststore.ks
│ ├── testclient.keystore
│ └── testclient.truststore
├── spring-cloud-stream-binder-kafka-streams
├── .jdk8
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── org
│ │ │ └── springframework
│ │ │ └── cloud
│ │ │ └── stream
│ │ │ └── binder
│ │ │ └── kafka
│ │ │ └── streams
│ │ │ ├── AbstractKafkaStreamsBinderProcessor.java
│ │ │ ├── DeserializationExceptionHandler.java
│ │ │ ├── EncodingDecodingBindAdviceHandler.java
│ │ │ ├── ExtendedBindingHandlerMappingsProviderAutoConfiguration.java
│ │ │ ├── GlobalKTableBinder.java
│ │ │ ├── GlobalKTableBinderConfiguration.java
│ │ │ ├── GlobalKTableBoundElementFactory.java
│ │ │ ├── InteractiveQueryService.java
│ │ │ ├── KStreamBinder.java
│ │ │ ├── KStreamBinderConfiguration.java
│ │ │ ├── KStreamBoundElementFactory.java
│ │ │ ├── KTableBinder.java
│ │ │ ├── KTableBinderConfiguration.java
│ │ │ ├── KTableBoundElementFactory.java
│ │ │ ├── KafkaStreamsBinderHealthIndicator.java
│ │ │ ├── KafkaStreamsBinderHealthIndicatorConfiguration.java
│ │ │ ├── KafkaStreamsBinderMetrics.java
│ │ │ ├── KafkaStreamsBinderSupportAutoConfiguration.java
│ │ │ ├── KafkaStreamsBinderUtils.java
│ │ │ ├── KafkaStreamsBindingInformationCatalogue.java
│ │ │ ├── KafkaStreamsFunctionProcessor.java
│ │ │ ├── KafkaStreamsJaasConfiguration.java
│ │ │ ├── KafkaStreamsMessageConversionDelegate.java
│ │ │ ├── KafkaStreamsRegistry.java
│ │ │ ├── KeyValueSerdeResolver.java
│ │ │ ├── MultiBinderPropertiesConfiguration.java
│ │ │ ├── SendToDlqAndContinue.java
│ │ │ ├── SkipAndContinueExceptionHandler.java
│ │ │ ├── StreamsBuilderFactoryManager.java
│ │ │ ├── endpoint
│ │ │ ├── KafkaStreamsTopologyEndpoint.java
│ │ │ └── KafkaStreamsTopologyEndpointAutoConfiguration.java
│ │ │ ├── function
│ │ │ ├── FunctionDetectorCondition.java
│ │ │ ├── KafkaStreamsBindableProxyFactory.java
│ │ │ ├── KafkaStreamsFunctionAutoConfiguration.java
│ │ │ ├── KafkaStreamsFunctionBeanPostProcessor.java
│ │ │ └── KafkaStreamsFunctionProcessorInvoker.java
│ │ │ ├── properties
│ │ │ ├── KafkaStreamsBinderConfigurationProperties.java
│ │ │ ├── KafkaStreamsBindingProperties.java
│ │ │ ├── KafkaStreamsConsumerProperties.java
│ │ │ ├── KafkaStreamsExtendedBindingProperties.java
│ │ │ └── KafkaStreamsProducerProperties.java
│ │ │ └── serde
│ │ │ └── CollectionSerde.java
│ └── resources
│ │ └── META-INF
│ │ ├── spring.binders
│ │ └── spring.factories
│ └── test
│ ├── java
│ └── org
│ │ └── springframework
│ │ └── cloud
│ │ └── stream
│ │ └── binder
│ │ └── kafka
│ │ └── streams
│ │ ├── ExtendedBindingHandlerMappingsProviderAutoConfigurationTests.java
│ │ ├── KafkaStreamsEventTypeRoutingTests.java
│ │ ├── KafkaStreamsFunctionCompositionTests.java
│ │ ├── KafkaStreamsInteractiveQueryIntegrationTests.java
│ │ ├── MultipleFunctionsInSameAppTests.java
│ │ ├── bootstrap
│ │ ├── KafkaStreamsBinderBootstrapTest.java
│ │ └── KafkaStreamsBinderJaasInitTests.java
│ │ ├── function
│ │ ├── KafkaStreamsBinderWordCountBranchesFunctionTests.java
│ │ ├── KafkaStreamsBinderWordCountFunctionTests.java
│ │ ├── KafkaStreamsComponentBeansTests.java
│ │ ├── KafkaStreamsFunctionStateStoreTests.java
│ │ ├── KafkaStreamsRetryTests.java
│ │ ├── SerdesProvidedAsBeansTests.java
│ │ ├── StreamToGlobalKTableFunctionTests.java
│ │ └── StreamToTableJoinFunctionTests.java
│ │ ├── integration
│ │ ├── DlqDestinationResolverTests.java
│ │ ├── KafkaStreamsBinderDestinationIsPatternTests.java
│ │ ├── KafkaStreamsBinderHealthIndicatorTests.java
│ │ ├── KafkaStreamsBinderMultipleInputTopicsTest.java
│ │ ├── KafkaStreamsBinderPojoInputAndPrimitiveTypeOutputTests.java
│ │ ├── KafkaStreamsBinderTombstoneTests.java
│ │ ├── KafkaStreamsStateStoreIntegrationTests.java
│ │ └── KafkastreamsBinderPojoInputStringOutputIntegrationTests.java
│ │ └── serde
│ │ └── CollectionSerdeTest.java
│ └── resources
│ └── logback.xml
├── spring-cloud-stream-binder-kafka
├── .jdk8
├── .settings
│ └── org.eclipse.jdt.ui.prefs
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── org
│ │ │ └── springframework
│ │ │ └── cloud
│ │ │ └── stream
│ │ │ └── binder
│ │ │ └── kafka
│ │ │ ├── BinderHeaderMapper.java
│ │ │ ├── KafkaBinderEnvironmentPostProcessor.java
│ │ │ ├── KafkaBinderHealth.java
│ │ │ ├── KafkaBinderHealthIndicator.java
│ │ │ ├── KafkaBinderMetrics.java
│ │ │ ├── KafkaBindingRebalanceListener.java
│ │ │ ├── KafkaExpressionEvaluatingInterceptor.java
│ │ │ ├── KafkaMessageChannelBinder.java
│ │ │ ├── KafkaNullConverter.java
│ │ │ ├── ListenerContainerWithDlqAndRetryCustomizer.java
│ │ │ └── config
│ │ │ ├── ClientFactoryCustomizer.java
│ │ │ ├── ConsumerConfigCustomizer.java
│ │ │ ├── ExtendedBindingHandlerMappingsProviderConfiguration.java
│ │ │ ├── KafkaBinderConfiguration.java
│ │ │ ├── KafkaBinderHealthIndicatorConfiguration.java
│ │ │ └── ProducerConfigCustomizer.java
│ └── resources
│ │ └── META-INF
│ │ ├── spring.binders
│ │ └── spring.factories
│ └── test
│ ├── java
│ └── org
│ │ └── springframework
│ │ └── cloud
│ │ └── stream
│ │ └── binder
│ │ └── kafka
│ │ ├── AbstractKafkaTestBinder.java
│ │ ├── AdminConfigTests.java
│ │ ├── AutoCreateTopicDisabledTests.java
│ │ ├── KafkaBinderAutoConfigurationPropertiesTest.java
│ │ ├── KafkaBinderConfigurationPropertiesTest.java
│ │ ├── KafkaBinderConfigurationTest.java
│ │ ├── KafkaBinderHealthIndicatorTest.java
│ │ ├── KafkaBinderJaasInitializerListenerTest.java
│ │ ├── KafkaBinderMetricsTest.java
│ │ ├── KafkaBinderTests.java
│ │ ├── KafkaBinderUnitTests.java
│ │ ├── KafkaTestBinder.java
│ │ ├── KafkaTransactionTests.java
│ │ ├── RawKafkaPartitionTestSupport.java
│ │ ├── TestKafkaProperties.java
│ │ ├── bootstrap
│ │ ├── KafkaBinderBootstrapTest.java
│ │ ├── KafkaBinderCustomHealthCheckTests.java
│ │ └── KafkaBinderMeterRegistryTest.java
│ │ ├── integration
│ │ ├── KafkaBinderActuatorTests.java
│ │ ├── KafkaBinderExtendedPropertiesTest.java
│ │ ├── KafkaConfigCustomizationTests.java
│ │ ├── KafkaNullConverterTest.java
│ │ ├── KafkaRetryDlqBinderOrContainerTests.java
│ │ ├── ProducerOnlyTransactionTests.java
│ │ └── topic
│ │ │ └── configs
│ │ │ ├── BaseKafkaBinderTopicPropertiesUpdateTest.java
│ │ │ ├── DisabledKafkaBinderTopicPropertiesUpdateTest.java
│ │ │ └── KafkaBinderTopicPropertiesUpdateTest.java
│ │ └── integration2
│ │ └── ConsumerProducerTransactionTests.java
│ └── resources
│ ├── binder-config-autoconfig.properties
│ ├── binder-config.properties
│ ├── jaas-sample-kafka-only.conf
│ ├── jaas-sample-with-zk.conf
│ └── logback.xml
└── update-version.sh
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: Please create new issues in https://github.com/spring-cloud/spring-cloud-stream/issues
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | Please create all new issues in https://github.com/spring-cloud/spring-cloud-stream/issues. The Kafka binder repository has been relocated to the core Spring Cloud Stream repo.
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /application.yml
2 | /application.properties
3 | asciidoctor.css
4 | *~
5 | .#*
6 | *#
7 | target/
8 | build/
9 | bin/
10 | _site/
11 | .classpath
12 | .project
13 | .settings
14 | .springBeans
15 | .DS_Store
16 | *.sw*
17 | *.iml
18 | *.ipr
19 | *.iws
20 | .idea/*
21 | */.idea
22 | .factorypath
23 | dump.rdb
24 | .apt_generated
25 | artifacts
26 | .sts4-cache
27 |
--------------------------------------------------------------------------------
/.jdk8:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-cloud-stream-binder-kafka/31ea10683422d38d8185c6b236b8954200562b77/.jdk8
--------------------------------------------------------------------------------
/.mvn/jvm.config:
--------------------------------------------------------------------------------
1 | -Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom
--------------------------------------------------------------------------------
/.mvn/maven.config:
--------------------------------------------------------------------------------
1 | -DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local -P spring
2 |
--------------------------------------------------------------------------------
/.mvn/wrapper/MavenWrapperDownloader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007-present the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | import java.net.*;
17 | import java.io.*;
18 | import java.nio.channels.*;
19 | import java.util.Properties;
20 |
21 | public class MavenWrapperDownloader {
22 |
23 | private static final String WRAPPER_VERSION = "0.5.6";
24 | /**
25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26 | */
27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29 |
30 | /**
31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32 | * use instead of the default one.
33 | */
34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35 | ".mvn/wrapper/maven-wrapper.properties";
36 |
37 | /**
38 | * Path where the maven-wrapper.jar will be saved to.
39 | */
40 | private static final String MAVEN_WRAPPER_JAR_PATH =
41 | ".mvn/wrapper/maven-wrapper.jar";
42 |
43 | /**
44 | * Name of the property which should be used to override the default download url for the wrapper.
45 | */
46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47 |
48 | public static void main(String args[]) {
49 | System.out.println("- Downloader started");
50 | File baseDirectory = new File(args[0]);
51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52 |
53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom
54 | // wrapperUrl parameter.
55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56 | String url = DEFAULT_DOWNLOAD_URL;
57 | if(mavenWrapperPropertyFile.exists()) {
58 | FileInputStream mavenWrapperPropertyFileInputStream = null;
59 | try {
60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61 | Properties mavenWrapperProperties = new Properties();
62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64 | } catch (IOException e) {
65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66 | } finally {
67 | try {
68 | if(mavenWrapperPropertyFileInputStream != null) {
69 | mavenWrapperPropertyFileInputStream.close();
70 | }
71 | } catch (IOException e) {
72 | // Ignore ...
73 | }
74 | }
75 | }
76 | System.out.println("- Downloading from: " + url);
77 |
78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79 | if(!outputFile.getParentFile().exists()) {
80 | if(!outputFile.getParentFile().mkdirs()) {
81 | System.out.println(
82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83 | }
84 | }
85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86 | try {
87 | downloadFileFromURL(url, outputFile);
88 | System.out.println("Done");
89 | System.exit(0);
90 | } catch (Throwable e) {
91 | System.out.println("- Error downloading");
92 | e.printStackTrace();
93 | System.exit(1);
94 | }
95 | }
96 |
97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99 | String username = System.getenv("MVNW_USERNAME");
100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101 | Authenticator.setDefault(new Authenticator() {
102 | @Override
103 | protected PasswordAuthentication getPasswordAuthentication() {
104 | return new PasswordAuthentication(username, password);
105 | }
106 | });
107 | }
108 | URL website = new URL(urlString);
109 | ReadableByteChannel rbc;
110 | rbc = Channels.newChannel(website.openStream());
111 | FileOutputStream fos = new FileOutputStream(destination);
112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113 | fos.close();
114 | rbc.close();
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-cloud-stream-binder-kafka/31ea10683422d38d8185c6b236b8954200562b77/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
3 |
--------------------------------------------------------------------------------
/.settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | repo.spring.io
6 | ${env.CI_DEPLOY_USERNAME}
7 | ${env.CI_DEPLOY_PASSWORD}
8 |
9 |
10 |
11 |
12 |
18 | spring
19 | true
20 |
21 |
22 | spring-snapshots
23 | Spring Snapshots
24 | https://repo.spring.io/libs-snapshot-local
25 |
26 | true
27 |
28 |
29 |
30 | spring-milestones
31 | Spring Milestones
32 | https://repo.spring.io/libs-milestone-local
33 |
34 | false
35 |
36 |
37 |
38 | spring-releases
39 | Spring Releases
40 | https://repo.spring.io/release
41 |
42 | false
43 |
44 |
45 |
46 |
47 |
48 | spring-snapshots
49 | Spring Snapshots
50 | https://repo.spring.io/libs-snapshot-local
51 |
52 | true
53 |
54 |
55 |
56 | spring-milestones
57 | Spring Milestones
58 | https://repo.spring.io/libs-milestone-local
59 |
60 | false
61 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/docs/.jdk8:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-cloud-stream-binder-kafka/31ea10683422d38d8185c6b236b8954200562b77/docs/.jdk8
--------------------------------------------------------------------------------
/docs/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | spring-cloud-stream-binder-kafka-docs
7 |
8 | org.springframework.cloud
9 | spring-cloud-stream-binder-kafka-parent
10 | 4.0.0-SNAPSHOT
11 |
12 | jar
13 | spring-cloud-stream-binder-kafka-docs
14 | Spring Cloud Stream Kafka Binder Docs
15 |
16 | spring-cloud-stream-binder-kafka
17 | ${basedir}/..
18 | 3.4
19 | .*stream.*
20 | deploy
21 |
22 |
23 |
24 | ${project.groupId}
25 | spring-cloud-starter-stream-kafka
26 | ${project.version}
27 |
28 |
29 |
30 | src/main/asciidoc
31 |
32 |
33 |
34 | docs
35 |
36 |
37 |
38 | pl.project13.maven
39 | git-commit-id-plugin
40 |
41 |
42 | maven-dependency-plugin
43 |
44 |
45 | maven-resources-plugin
46 |
47 |
48 | org.codehaus.mojo
49 | exec-maven-plugin
50 |
51 |
52 | org.asciidoctor
53 | asciidoctor-maven-plugin
54 |
55 |
56 | maven-antrun-plugin
57 |
58 |
59 | maven-deploy-plugin
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/.gitignore:
--------------------------------------------------------------------------------
1 | *.html
2 | *.css
3 |
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/Guardfile:
--------------------------------------------------------------------------------
1 | require 'asciidoctor'
2 | require 'erb'
3 |
4 | guard 'shell' do
5 | watch(/.*\.adoc$/) {|m|
6 | Asciidoctor.render_file('index.adoc', \
7 | :in_place => true, \
8 | :safe => Asciidoctor::SafeMode::UNSAFE, \
9 | :attributes=> { \
10 | 'source-highlighter' => 'prettify', \
11 | 'icons' => 'font', \
12 | 'linkcss'=> 'true', \
13 | 'copycss' => 'true', \
14 | 'doctype' => 'book'})
15 | }
16 | end
17 |
18 | guard 'livereload' do
19 | watch(%r{^.+\.(css|js|html)$})
20 | end
21 |
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/README.adoc:
--------------------------------------------------------------------------------
1 | :jdkversion: 1.8
2 | :github-tag: master
3 | :github-repo: spring-cloud/spring-cloud-stream-binder-kafka
4 |
5 | :github-raw: https://raw.githubusercontent.com/{github-repo}/{github-tag}
6 | :github-code: https://github.com/{github-repo}/tree/{github-tag}
7 |
8 | image::https://circleci.com/gh/spring-cloud/spring-cloud-stream-binder-kafka.svg?style=svg["CircleCI", link="https://circleci.com/gh/spring-cloud/spring-cloud-stream-binder-kafka"]
9 | image::https://codecov.io/gh/spring-cloud/spring-cloud-stream-binder-kafka/branch/{github-tag}/graph/badge.svg["codecov", link="https://codecov.io/gh/spring-cloud/spring-cloud-stream-binder-kafka"]
10 | image::https://badges.gitter.im/spring-cloud/spring-cloud-stream-binder-kafka.svg[Gitter, link="https://gitter.im/spring-cloud/spring-cloud-stream-binder-kafka?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"]
11 |
12 | // ======================================================================================
13 |
14 | == Apache Kafka Binder
15 |
16 | === Usage
17 |
18 | To use Apache Kafka binder, you need to add `spring-cloud-stream-binder-kafka` as a dependency to your Spring Cloud Stream application, as shown in the following example for Maven:
19 |
20 | [source,xml]
21 | ----
22 |
23 | org.springframework.cloud
24 | spring-cloud-stream-binder-kafka
25 |
26 | ----
27 |
28 | Alternatively, you can also use the Spring Cloud Stream Kafka Starter, as shown in the following example for Maven:
29 |
30 | [source,xml]
31 | ----
32 |
33 | org.springframework.cloud
34 | spring-cloud-starter-stream-kafka
35 |
36 | ----
37 |
38 | == Apache Kafka Streams Binder
39 |
40 | === Usage
41 |
42 | To use Apache Kafka Streams binder, you need to add `spring-cloud-stream-binder-kafka-streams` as a dependency to your Spring Cloud Stream application, as shown in the following example for Maven:
43 |
44 | [source,xml]
45 | ----
46 |
47 | org.springframework.cloud
48 | spring-cloud-stream-binder-kafka-streams
49 |
50 | ----
51 |
52 | = Appendices
53 | [appendix]
54 | include::building.adoc[]
55 | include::contributing.adoc[]
56 |
57 | // ======================================================================================
58 |
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/appendix.adoc:
--------------------------------------------------------------------------------
1 | [[appendix]]
2 | = Appendices
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/building.adoc:
--------------------------------------------------------------------------------
1 | [[building]]
2 | == Building
3 |
4 | :jdkversion: 1.7
5 |
6 | === Basic Compile and Test
7 |
8 | To build the source you will need to install JDK {jdkversion}.
9 |
10 | The build uses the Maven wrapper so you don't have to install a specific
11 | version of Maven. To enable the tests, you should have Kafka server 0.9 or above running
12 | before building. See below for more information on running the servers.
13 |
14 | The main build command is
15 |
16 | ----
17 | $ ./mvnw clean install
18 | ----
19 |
20 | You can also add '-DskipTests' if you like, to avoid running the tests.
21 |
22 | NOTE: You can also install Maven (>=3.3.3) yourself and run the `mvn` command
23 | in place of `./mvnw` in the examples below. If you do that you also
24 | might need to add `-P spring` if your local Maven settings do not
25 | contain repository declarations for spring pre-release artifacts.
26 |
27 | NOTE: Be aware that you might need to increase the amount of memory
28 | available to Maven by setting a `MAVEN_OPTS` environment variable with
29 | a value like `-Xmx512m -XX:MaxPermSize=128m`. We try to cover this in
30 | the `.mvn` configuration, so if you find you have to do it to make a
31 | build succeed, please raise a ticket to get the settings added to
32 | source control.
33 |
34 |
35 | The projects that require middleware generally include a
36 | `docker-compose.yml`, so consider using
37 | https://compose.docker.io/[Docker Compose] to run the middeware servers
38 | in Docker containers.
39 |
40 | === Documentation
41 |
42 | There is a "full" profile that will generate documentation.
43 |
44 | === Working with the code
45 | If you don't have an IDE preference we would recommend that you use
46 | https://www.springsource.com/developer/sts[Spring Tools Suite] or
47 | https://eclipse.org[Eclipse] when working with the code. We use the
48 | https://eclipse.org/m2e/[m2eclipe] eclipse plugin for maven support. Other IDEs and tools
49 | should also work without issue.
50 |
51 | ==== Importing into eclipse with m2eclipse
52 | We recommend the https://eclipse.org/m2e/[m2eclipe] eclipse plugin when working with
53 | eclipse. If you don't already have m2eclipse installed it is available from the "eclipse
54 | marketplace".
55 |
56 | Unfortunately m2e does not yet support Maven 3.3, so once the projects
57 | are imported into Eclipse you will also need to tell m2eclipse to use
58 | the `.settings.xml` file for the projects. If you do not do this you
59 | may see many different errors related to the POMs in the
60 | projects. Open your Eclipse preferences, expand the Maven
61 | preferences, and select User Settings. In the User Settings field
62 | click Browse and navigate to the Spring Cloud project you imported
63 | selecting the `.settings.xml` file in that project. Click Apply and
64 | then OK to save the preference changes.
65 |
66 | NOTE: Alternatively you can copy the repository settings from https://github.com/spring-cloud/spring-cloud-build/blob/master/.settings.xml[`.settings.xml`] into your own `~/.m2/settings.xml`.
67 |
68 | ==== Importing into eclipse without m2eclipse
69 | If you prefer not to use m2eclipse you can generate eclipse project metadata using the
70 | following command:
71 |
72 | [indent=0]
73 | ----
74 | $ ./mvnw eclipse:eclipse
75 | ----
76 |
77 | The generated eclipse projects can be imported by selecting `import existing projects`
78 | from the `file` menu.
79 |
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/contributing.adoc:
--------------------------------------------------------------------------------
1 | [[contributing]
2 | == Contributing
3 |
4 | Spring Cloud is released under the non-restrictive Apache 2.0 license,
5 | and follows a very standard Github development process, using Github
6 | tracker for issues and merging pull requests into master. If you want
7 | to contribute even something trivial please do not hesitate, but
8 | follow the guidelines below.
9 |
10 | === Sign the Contributor License Agreement
11 | Before we accept a non-trivial patch or pull request we will need you to sign the
12 | https://support.springsource.com/spring_committer_signup[contributor's agreement].
13 | Signing the contributor's agreement does not grant anyone commit rights to the main
14 | repository, but it does mean that we can accept your contributions, and you will get an
15 | author credit if we do. Active contributors might be asked to join the core team, and
16 | given the ability to merge pull requests.
17 |
18 | === Code Conventions and Housekeeping
19 | None of these is essential for a pull request, but they will all help. They can also be
20 | added after the original pull request but before a merge.
21 |
22 | * Use the Spring Framework code format conventions. If you use Eclipse
23 | you can import formatter settings using the
24 | `eclipse-code-formatter.xml` file from the
25 | https://github.com/spring-cloud/build/tree/master/eclipse-coding-conventions.xml[Spring
26 | Cloud Build] project. If using IntelliJ, you can use the
27 | https://plugins.jetbrains.com/plugin/6546[Eclipse Code Formatter
28 | Plugin] to import the same file.
29 | * Make sure all new `.java` files to have a simple Javadoc class comment with at least an
30 | `@author` tag identifying you, and preferably at least a paragraph on what the class is
31 | for.
32 | * Add the ASF license header comment to all new `.java` files (copy from existing files
33 | in the project)
34 | * Add yourself as an `@author` to the .java files that you modify substantially (more
35 | than cosmetic changes).
36 | * Add some Javadocs and, if you change the namespace, some XSD doc elements.
37 | * A few unit tests would help a lot as well -- someone has to do it.
38 | * If no-one else is using your branch, please rebase it against the current master (or
39 | other target branch in the main project).
40 | * When writing a commit message please follow https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions],
41 | if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit
42 | message (where XXXX is the issue number).
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/images/kafka-binder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-cloud-stream-binder-kafka/31ea10683422d38d8185c6b236b8954200562b77/docs/src/main/asciidoc/images/kafka-binder.png
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/images/kafka-streams-initializr.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-cloud-stream-binder-kafka/31ea10683422d38d8185c6b236b8954200562b77/docs/src/main/asciidoc/images/kafka-streams-initializr.png
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/images/spring-initializr-kafka-streams.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-cloud-stream-binder-kafka/31ea10683422d38d8185c6b236b8954200562b77/docs/src/main/asciidoc/images/spring-initializr-kafka-streams.png
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/index-docinfo.xml:
--------------------------------------------------------------------------------
1 | Spring Cloud Stream Kafka Binder
2 | {spring-cloud-stream-binder-kafka-version}
3 |
4 | 2013-2016
5 | Pivotal Software, Inc.
6 |
7 |
8 |
9 | Copies of this document may be made for your own use and for distribution to
10 | others, provided that you do not charge any fee for such copies and further
11 | provided that each copy contains this Copyright Notice, whether distributed in
12 | print or electronically.
13 |
14 |
15 |
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/partitions.adoc:
--------------------------------------------------------------------------------
1 | === Partitioning with the Kafka Binder
2 |
3 | Apache Kafka supports topic partitioning natively.
4 |
5 | Sometimes it is advantageous to send data to specific partitions -- for example, when you want to strictly order message processing (all messages for a particular customer should go to the same partition).
6 |
7 | The following example shows how to configure the producer and consumer side:
8 |
9 | [source, java]
10 | ----
11 | @SpringBootApplication
12 | @EnableBinding(Source.class)
13 | public class KafkaPartitionProducerApplication {
14 |
15 | private static final Random RANDOM = new Random(System.currentTimeMillis());
16 |
17 | private static final String[] data = new String[] {
18 | "foo1", "bar1", "qux1",
19 | "foo2", "bar2", "qux2",
20 | "foo3", "bar3", "qux3",
21 | "foo4", "bar4", "qux4",
22 | };
23 |
24 | public static void main(String[] args) {
25 | new SpringApplicationBuilder(KafkaPartitionProducerApplication.class)
26 | .web(false)
27 | .run(args);
28 | }
29 |
30 | @InboundChannelAdapter(channel = Source.OUTPUT, poller = @Poller(fixedRate = "5000"))
31 | public Message> generate() {
32 | String value = data[RANDOM.nextInt(data.length)];
33 | System.out.println("Sending: " + value);
34 | return MessageBuilder.withPayload(value)
35 | .setHeader("partitionKey", value)
36 | .build();
37 | }
38 |
39 | }
40 | ----
41 |
42 | .application.yml
43 | [source, yaml]
44 | ----
45 | spring:
46 | cloud:
47 | stream:
48 | bindings:
49 | output:
50 | destination: partitioned.topic
51 | producer:
52 | partition-key-expression: headers['partitionKey']
53 | partition-count: 12
54 | ----
55 |
56 | IMPORTANT: The topic must be provisioned to have enough partitions to achieve the desired concurrency for all consumer groups.
57 | The above configuration supports up to 12 consumer instances (6 if their `concurrency` is 2, 4 if their concurrency is 3, and so on).
58 | It is generally best to "`over-provision`" the partitions to allow for future increases in consumers or concurrency.
59 |
60 | NOTE: The preceding configuration uses the default partitioning (`key.hashCode() % partitionCount`).
61 | This may or may not provide a suitably balanced algorithm, depending on the key values.
62 | You can override this default by using the `partitionSelectorExpression` or `partitionSelectorClass` properties.
63 |
64 | Since partitions are natively handled by Kafka, no special configuration is needed on the consumer side.
65 | Kafka allocates partitions across the instances.
66 |
67 | The following Spring Boot application listens to a Kafka stream and prints (to the console) the partition ID to which each message goes:
68 |
69 | [source, java]
70 | ----
71 | @SpringBootApplication
72 | @EnableBinding(Sink.class)
73 | public class KafkaPartitionConsumerApplication {
74 |
75 | public static void main(String[] args) {
76 | new SpringApplicationBuilder(KafkaPartitionConsumerApplication.class)
77 | .web(false)
78 | .run(args);
79 | }
80 |
81 | @StreamListener(Sink.INPUT)
82 | public void listen(@Payload String in, @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition) {
83 | System.out.println(in + " received from partition " + partition);
84 | }
85 |
86 | }
87 | ----
88 |
89 | .application.yml
90 | [source, yaml]
91 | ----
92 | spring:
93 | cloud:
94 | stream:
95 | bindings:
96 | input:
97 | destination: partitioned.topic
98 | group: myGroup
99 | ----
100 |
101 | You can add instances as needed.
102 | Kafka rebalances the partition allocations.
103 | If the instance count (or `instance count * concurrency`) exceeds the number of partitions, some consumers are idle.
104 |
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/spring-cloud-stream-binder-kafka-aggregate.adoc:
--------------------------------------------------------------------------------
1 | include::overview.adoc[leveloffset=+1]
2 | include::dlq.adoc[leveloffset=+1]
3 | include::partitions.adoc[leveloffset=+1]
4 |
--------------------------------------------------------------------------------
/docs/src/main/asciidoc/spring-cloud-stream-binder-kafka.adoc:
--------------------------------------------------------------------------------
1 | :github-tag: master
2 | :github-repo: spring-cloud/spring-cloud-stream-binder-kafka
3 | :github-raw: https://raw.githubusercontent.com/{github-repo}/{github-tag}
4 | :github-code: https://github.com/{github-repo}/tree/{github-tag}
5 | :toc: left
6 | :toclevels: 8
7 | :nofooter:
8 | :sectlinks: true
9 |
10 |
11 | [[spring-cloud-stream-binder-kafka-reference]]
12 | = Spring Cloud Stream Kafka Binder Reference Guide
13 | Sabby Anandan, Marius Bogoevici, Eric Bottard, Mark Fisher, Ilayaperumal Gopinathan, Gunnar Hillert, Mark Pollack, Patrick Peralta, Glenn Renfro, Thomas Risberg, Dave Syer, David Turanski, Janne Valkealahti, Benjamin Klein, Henryk Konsek, Gary Russell, Arnaud Jardiné, Soby Chacko
14 | :doctype: book
15 | :toc:
16 | :toclevels: 4
17 | :source-highlighter: prettify
18 | :numbered:
19 | :icons: font
20 | :hide-uri-scheme:
21 | :spring-cloud-stream-binder-kafka-repo: snapshot
22 | :github-tag: master
23 | :spring-cloud-stream-binder-kafka-docs-version: current
24 | :spring-cloud-stream-binder-kafka-docs: https://docs.spring.io/spring-cloud-stream-binder-kafka/docs/{spring-cloud-stream-binder-kafka-docs-version}/reference
25 | :spring-cloud-stream-binder-kafka-docs-current: https://docs.spring.io/spring-cloud-stream-binder-kafka/docs/current-SNAPSHOT/reference/html/
26 | :github-repo: spring-cloud/spring-cloud-stream-binder-kafka
27 | :github-raw: https://raw.github.com/{github-repo}/{github-tag}
28 | :github-code: https://github.com/{github-repo}/tree/{github-tag}
29 | :github-wiki: https://github.com/{github-repo}/wiki
30 | :github-master-code: https://github.com/{github-repo}/tree/master
31 | :sc-ext: java
32 | // ======================================================================================
33 |
34 |
35 | *{project-version}*
36 |
37 |
38 | = Reference Guide
39 | include::overview.adoc[]
40 |
41 | include::dlq.adoc[]
42 |
43 | include::partitions.adoc[]
44 |
45 | include::kafka-streams.adoc[]
46 |
47 | include::tips.adoc[]
48 |
49 | = Appendices
50 | [appendix]
51 | include::building.adoc[]
52 |
53 | include::contributing.adoc[]
54 |
55 | // ======================================================================================
56 |
--------------------------------------------------------------------------------
/docs/src/main/ruby/generate_readme.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | base_dir = File.join(File.dirname(__FILE__),'../../..')
4 | src_dir = File.join(base_dir, "/src/main/asciidoc")
5 | require 'asciidoctor'
6 | require 'optparse'
7 |
8 | options = {}
9 | file = "#{src_dir}/README.adoc"
10 |
11 | OptionParser.new do |o|
12 | o.on('-o OUTPUT_FILE', 'Output file (default is stdout)') { |file| options[:to_file] = file unless file=='-' }
13 | o.on('-h', '--help') { puts o; exit }
14 | o.parse!
15 | end
16 |
17 | file = ARGV[0] if ARGV.length>0
18 |
19 | # Copied from https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/scripts/asciidoc-coalescer.rb
20 | doc = Asciidoctor.load_file file, safe: :unsafe, header_only: true, attributes: options[:attributes]
21 | header_attr_names = (doc.instance_variable_get :@attributes_modified).to_a
22 | header_attr_names.each {|k| doc.attributes[%(#{k}!)] = '' unless doc.attr? k }
23 | attrs = doc.attributes
24 | attrs['allow-uri-read'] = true
25 | puts attrs
26 |
27 | out = "// Do not edit this file (e.g. go instead to src/main/asciidoc)\n\n"
28 | doc = Asciidoctor.load_file file, safe: :unsafe, parse: false, attributes: attrs
29 | out << doc.reader.read
30 |
31 | unless options[:to_file]
32 | puts out
33 | else
34 | File.open(options[:to_file],'w+') do |file|
35 | file.write(out)
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/spring-cloud-starter-stream-kafka/.jdk8:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-cloud-stream-binder-kafka/31ea10683422d38d8185c6b236b8954200562b77/spring-cloud-starter-stream-kafka/.jdk8
--------------------------------------------------------------------------------
/spring-cloud-starter-stream-kafka/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | org.springframework.cloud
6 | spring-cloud-stream-binder-kafka-parent
7 | 4.0.0-SNAPSHOT
8 |
9 | spring-cloud-starter-stream-kafka
10 | Spring Cloud Starter Stream Kafka
11 | https://projects.spring.io/spring-cloud
12 |
13 | Pivotal Software, Inc.
14 | https://www.spring.io
15 |
16 |
17 | ${basedir}/../..
18 |
19 |
20 |
21 | org.springframework.cloud
22 | spring-cloud-stream-binder-kafka
23 | ${project.version}
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-core/.jdk8:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-cloud-stream-binder-kafka/31ea10683422d38d8185c6b236b8954200562b77/spring-cloud-stream-binder-kafka-core/.jdk8
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-core/.settings/org.eclipse.jdt.ui.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.ui.ignorelowercasenames=true
3 | org.eclipse.jdt.ui.importorder=java;javax;com;org;org.springframework;ch.qos;\#;
4 | org.eclipse.jdt.ui.ondemandthreshold=99
5 | org.eclipse.jdt.ui.staticondemandthreshold=99
6 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.cloud
7 | spring-cloud-stream-binder-kafka-parent
8 | 4.0.0-SNAPSHOT
9 |
10 | spring-cloud-stream-binder-kafka-core
11 | Spring Cloud Stream Kafka Binder Core
12 | https://projects.spring.io/spring-cloud
13 |
14 | Pivotal Software, Inc.
15 | https://www.spring.io
16 |
17 |
18 |
19 |
20 | org.springframework.cloud
21 | spring-cloud-stream
22 |
23 |
24 | org.springframework.integration
25 | spring-integration-kafka
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-configuration-processor
30 | true
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-test
35 | test
36 |
37 |
38 | org.springframework.kafka
39 | spring-kafka-test
40 | test
41 |
42 |
43 | org.springframework.cloud
44 | spring-cloud-stream-binder-test
45 | test
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/JaasLoginModuleConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.stream.binder.kafka.properties;
18 |
19 | import java.util.HashMap;
20 | import java.util.Map;
21 |
22 | import javax.security.auth.login.AppConfigurationEntry;
23 |
24 | import org.springframework.kafka.security.jaas.KafkaJaasLoginModuleInitializer;
25 | import org.springframework.util.Assert;
26 |
27 | /**
28 | * Contains properties for setting up an {@link AppConfigurationEntry} that can be used
29 | * for the Kafka or Zookeeper client.
30 | *
31 | * @author Marius Bogoevici
32 | * @author Soby Chacko
33 | */
34 | public class JaasLoginModuleConfiguration {
35 |
36 | private String loginModule = "com.sun.security.auth.module.Krb5LoginModule";
37 |
38 | private KafkaJaasLoginModuleInitializer.ControlFlag controlFlag = KafkaJaasLoginModuleInitializer.ControlFlag.REQUIRED;
39 |
40 | private Map options = new HashMap<>();
41 |
42 | public String getLoginModule() {
43 | return this.loginModule;
44 | }
45 |
46 | public void setLoginModule(String loginModule) {
47 | Assert.notNull(loginModule, "cannot be null");
48 | this.loginModule = loginModule;
49 | }
50 |
51 | public KafkaJaasLoginModuleInitializer.ControlFlag getControlFlag() {
52 | return this.controlFlag;
53 | }
54 |
55 | public void setControlFlag(String controlFlag) {
56 | Assert.notNull(controlFlag, "cannot be null");
57 | this.controlFlag = KafkaJaasLoginModuleInitializer.ControlFlag
58 | .valueOf(controlFlag.toUpperCase());
59 | }
60 |
61 | public Map getOptions() {
62 | return this.options;
63 | }
64 |
65 | public void setOptions(Map options) {
66 | this.options = options;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaBindingProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.stream.binder.kafka.properties;
18 |
19 | import org.springframework.cloud.stream.binder.BinderSpecificPropertiesProvider;
20 |
21 | /**
22 | * Container object for Kafka specific extended producer and consumer binding properties.
23 | *
24 | * @author Marius Bogoevici
25 | * @author Oleg Zhurakousky
26 | */
27 | public class KafkaBindingProperties implements BinderSpecificPropertiesProvider {
28 |
29 | /**
30 | * Consumer specific binding properties. @see {@link KafkaConsumerProperties}.
31 | */
32 | private KafkaConsumerProperties consumer = new KafkaConsumerProperties();
33 |
34 | /**
35 | * Producer specific binding properties. @see {@link KafkaProducerProperties}.
36 | */
37 | private KafkaProducerProperties producer = new KafkaProducerProperties();
38 |
39 | /**
40 | * @return {@link KafkaConsumerProperties}
41 | * Consumer specific binding properties. @see {@link KafkaConsumerProperties}.
42 | */
43 | public KafkaConsumerProperties getConsumer() {
44 | return this.consumer;
45 | }
46 |
47 | public void setConsumer(KafkaConsumerProperties consumer) {
48 | this.consumer = consumer;
49 | }
50 |
51 | /**
52 | * @return {@link KafkaProducerProperties}
53 | * Producer specific binding properties. @see {@link KafkaProducerProperties}.
54 | */
55 | public KafkaProducerProperties getProducer() {
56 | return this.producer;
57 | }
58 |
59 | public void setProducer(KafkaProducerProperties producer) {
60 | this.producer = producer;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaExtendedBindingProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2018 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.stream.binder.kafka.properties;
18 |
19 | import java.util.Map;
20 |
21 | import org.springframework.boot.context.properties.ConfigurationProperties;
22 | import org.springframework.cloud.stream.binder.AbstractExtendedBindingProperties;
23 | import org.springframework.cloud.stream.binder.BinderSpecificPropertiesProvider;
24 |
25 | /**
26 | * Kafka specific extended binding properties class that extends from
27 | * {@link AbstractExtendedBindingProperties}.
28 | *
29 | * @author Marius Bogoevici
30 | * @author Gary Russell
31 | * @author Soby Chacko
32 | * @author Oleg Zhurakousky
33 | */
34 | @ConfigurationProperties("spring.cloud.stream.kafka")
35 | public class KafkaExtendedBindingProperties extends
36 | AbstractExtendedBindingProperties {
37 |
38 | private static final String DEFAULTS_PREFIX = "spring.cloud.stream.kafka.default";
39 |
40 | @Override
41 | public String getDefaultsPrefix() {
42 | return DEFAULTS_PREFIX;
43 | }
44 |
45 | @Override
46 | public Map getBindings() {
47 | return this.doGetBindings();
48 | }
49 |
50 | @Override
51 | public Class extends BinderSpecificPropertiesProvider> getExtendedPropertiesEntryClass() {
52 | return KafkaBindingProperties.class;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/properties/KafkaTopicProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.stream.binder.kafka.properties;
18 |
19 | import java.util.HashMap;
20 | import java.util.List;
21 | import java.util.Map;
22 |
23 | /**
24 | * Properties for configuring topics.
25 | *
26 | * @author Aldo Sinanaj
27 | * @since 2.2
28 | *
29 | */
30 | public class KafkaTopicProperties {
31 |
32 | private Short replicationFactor;
33 |
34 | private Map> replicasAssignments = new HashMap<>();
35 |
36 | private Map properties = new HashMap<>();
37 |
38 | public Short getReplicationFactor() {
39 | return replicationFactor;
40 | }
41 |
42 | public void setReplicationFactor(Short replicationFactor) {
43 | this.replicationFactor = replicationFactor;
44 | }
45 |
46 | public Map> getReplicasAssignments() {
47 | return replicasAssignments;
48 | }
49 |
50 | public void setReplicasAssignments(Map> replicasAssignments) {
51 | this.replicasAssignments = replicasAssignments;
52 | }
53 |
54 | public Map getProperties() {
55 | return properties;
56 | }
57 |
58 | public void setProperties(Map properties) {
59 | this.properties = properties;
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/provisioning/AdminClientConfigCustomizer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021-2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.stream.binder.kafka.provisioning;
18 |
19 | import java.util.Map;
20 |
21 | /**
22 | * Customizer for configuring AdminClient.
23 | *
24 | * @author Soby Chacko
25 | * @since 3.1.2
26 | */
27 | @FunctionalInterface
28 | public interface AdminClientConfigCustomizer {
29 |
30 | void configure(Map adminClientProperties);
31 | }
32 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/utils/DlqDestinationResolver.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020-2020 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.stream.binder.kafka.utils;
18 |
19 | import java.util.function.BiFunction;
20 |
21 | import org.apache.kafka.clients.consumer.ConsumerRecord;
22 |
23 | /**
24 | * A {@link BiFunction} extension for defining DLQ destination resolvers.
25 | *
26 | * The BiFunction takes the {@link ConsumerRecord} and the exception as inputs
27 | * and returns a topic name as the DLQ.
28 | *
29 | * @author Soby Chacko
30 | * @since 3.0.9
31 | */
32 | @FunctionalInterface
33 | public interface DlqDestinationResolver extends BiFunction, Exception, String> {
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/utils/DlqPartitionFunction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.stream.binder.kafka.utils;
18 |
19 | import org.apache.commons.logging.Log;
20 | import org.apache.kafka.clients.consumer.ConsumerRecord;
21 |
22 | import org.springframework.lang.Nullable;
23 |
24 | /**
25 | * A TriFunction that takes a consumer group, consumer record, and throwable and returns
26 | * which partition to publish to the dead letter topic. Returning {@code null} means Kafka
27 | * will choose the partition.
28 | *
29 | * @author Gary Russell
30 | * @since 3.0
31 | *
32 | */
33 | @FunctionalInterface
34 | public interface DlqPartitionFunction {
35 |
36 | /**
37 | * Returns the same partition as the original recor.
38 | */
39 | DlqPartitionFunction ORIGINAL_PARTITION = (group, rec, ex) -> rec.partition();
40 |
41 | /**
42 | * Returns 0.
43 | */
44 | DlqPartitionFunction PARTITION_ZERO = (group, rec, ex) -> 0;
45 |
46 | /**
47 | * Apply the function.
48 | * @param group the consumer group.
49 | * @param record the consumer record.
50 | * @param throwable the exception.
51 | * @return the DLQ partition, or null.
52 | */
53 | @Nullable
54 | Integer apply(String group, ConsumerRecord, ?> record, Throwable throwable);
55 |
56 | /**
57 | * Determine the fallback function to use based on the dlq partition count if no
58 | * {@link DlqPartitionFunction} bean is provided.
59 | * @param dlqPartitions the partition count.
60 | * @param logger the logger.
61 | * @return the fallback.
62 | */
63 | static DlqPartitionFunction determineFallbackFunction(@Nullable Integer dlqPartitions, Log logger) {
64 | if (dlqPartitions == null) {
65 | return ORIGINAL_PARTITION;
66 | }
67 | else if (dlqPartitions > 1) {
68 | logger.error("'dlqPartitions' is > 1 but a custom DlqPartitionFunction bean is not provided");
69 | return ORIGINAL_PARTITION;
70 | }
71 | else {
72 | return PARTITION_ZERO;
73 | }
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-core/src/main/java/org/springframework/cloud/stream/binder/kafka/utils/KafkaTopicUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.stream.binder.kafka.utils;
18 |
19 | import java.io.UnsupportedEncodingException;
20 |
21 | /**
22 | * Utility methods releated to Kafka topics.
23 | *
24 | * @author Soby Chacko
25 | */
26 | public final class KafkaTopicUtils {
27 |
28 | private KafkaTopicUtils() {
29 |
30 | }
31 |
32 | /**
33 | * Validate topic name. Allowed chars are ASCII alphanumerics, '.', '_' and '-'.
34 | * @param topicName name of the topic
35 | */
36 | public static void validateTopicName(String topicName) {
37 | try {
38 | byte[] utf8 = topicName.getBytes("UTF-8");
39 | for (byte b : utf8) {
40 | if (!((b >= 'a') && (b <= 'z') || (b >= 'A') && (b <= 'Z')
41 | || (b >= '0') && (b <= '9') || (b == '.') || (b == '-')
42 | || (b == '_'))) {
43 | throw new IllegalArgumentException(
44 | "Topic name can only have ASCII alphanumerics, '.', '_' and '-', but was: '"
45 | + topicName + "'");
46 | }
47 | }
48 | }
49 | catch (UnsupportedEncodingException ex) {
50 | throw new AssertionError(ex); // Can't happen
51 | }
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-core/src/test/resources/test.truststore.ks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-cloud-stream-binder-kafka/31ea10683422d38d8185c6b236b8954200562b77/spring-cloud-stream-binder-kafka-core/src/test/resources/test.truststore.ks
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-core/src/test/resources/testclient.keystore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-cloud-stream-binder-kafka/31ea10683422d38d8185c6b236b8954200562b77/spring-cloud-stream-binder-kafka-core/src/test/resources/testclient.keystore
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-core/src/test/resources/testclient.truststore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-cloud-stream-binder-kafka/31ea10683422d38d8185c6b236b8954200562b77/spring-cloud-stream-binder-kafka-core/src/test/resources/testclient.truststore
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-streams/.jdk8:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/spring-attic/spring-cloud-stream-binder-kafka/31ea10683422d38d8185c6b236b8954200562b77/spring-cloud-stream-binder-kafka-streams/.jdk8
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-streams/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | spring-cloud-stream-binder-kafka-streams
6 | jar
7 | spring-cloud-stream-binder-kafka-streams
8 | Kafka Streams Binder Implementation
9 |
10 |
11 | org.springframework.cloud
12 | spring-cloud-stream-binder-kafka-parent
13 | 4.0.0-SNAPSHOT
14 |
15 |
16 |
17 | 1.8.2
18 |
19 |
20 |
21 |
22 | org.springframework.cloud
23 | spring-cloud-stream-binder-kafka-core
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-actuator
28 | true
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-configuration-processor
33 | true
34 |
35 |
36 | org.springframework.boot
37 | spring-boot-autoconfigure
38 | true
39 |
40 |
41 | org.apache.kafka
42 | kafka-streams
43 |
44 |
45 | org.springframework.kafka
46 | spring-kafka
47 |
48 |
49 | org.springframework.boot
50 | spring-boot-test
51 | test
52 |
53 |
54 | org.springframework.kafka
55 | spring-kafka-test
56 |
57 |
58 | org.springframework.cloud
59 | spring-cloud-stream-binder-test
60 | test
61 |
62 |
63 | org.springframework.boot
64 | spring-boot-autoconfigure-processor
65 | true
66 |
67 |
68 | org.apache.kafka
69 | kafka_2.13
70 |
71 |
72 | org.apache.kafka
73 | kafka_2.13
74 | test
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/DeserializationExceptionHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.stream.binder.kafka.streams;
18 |
19 | /**
20 | * Enumeration for various {@link org.apache.kafka.streams.errors.DeserializationExceptionHandler} types.
21 | *
22 | * @author Soby Chacko
23 | * @since 3.0.0
24 | */
25 | public enum DeserializationExceptionHandler {
26 |
27 | /**
28 | * Deserialization error handler with log and continue.
29 | * See {@link org.apache.kafka.streams.errors.LogAndContinueExceptionHandler}
30 | */
31 | logAndContinue,
32 | /**
33 | * Deserialization error handler with log and fail.
34 | * See {@link org.apache.kafka.streams.errors.LogAndFailExceptionHandler}
35 | */
36 | logAndFail,
37 | /**
38 | * Deserialization error handler with DLQ send.
39 | * See {@link org.springframework.kafka.streams.RecoveringDeserializationExceptionHandler}
40 | */
41 | sendToDlq,
42 | /**
43 | * Deserialization error handler that silently skips the error and continue.
44 | */
45 | skipAndContinue;
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/EncodingDecodingBindAdviceHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019-2019 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.stream.binder.kafka.streams;
18 |
19 | import org.springframework.boot.context.properties.ConfigurationPropertiesBindHandlerAdvisor;
20 | import org.springframework.boot.context.properties.bind.AbstractBindHandler;
21 | import org.springframework.boot.context.properties.bind.BindContext;
22 | import org.springframework.boot.context.properties.bind.BindHandler;
23 | import org.springframework.boot.context.properties.bind.BindResult;
24 | import org.springframework.boot.context.properties.bind.Bindable;
25 | import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
26 |
27 | /**
28 | * {@link ConfigurationPropertiesBindHandlerAdvisor} to detect nativeEncoding/Decoding settings
29 | * provided by the application explicitly.
30 | *
31 | * @author Soby Chacko
32 | * @since 3.0.0
33 | */
34 | public class EncodingDecodingBindAdviceHandler implements ConfigurationPropertiesBindHandlerAdvisor {
35 |
36 | private boolean encodingSettingProvided;
37 | private boolean decodingSettingProvided;
38 |
39 | public boolean isDecodingSettingProvided() {
40 | return decodingSettingProvided;
41 | }
42 |
43 | public boolean isEncodingSettingProvided() {
44 | return this.encodingSettingProvided;
45 | }
46 |
47 | @Override
48 | public BindHandler apply(BindHandler bindHandler) {
49 | BindHandler handler = new AbstractBindHandler(bindHandler) {
50 | @Override
51 | public Bindable onStart(ConfigurationPropertyName name,
52 | Bindable target, BindContext context) {
53 | final String configName = name.toString();
54 | if (configName.contains("use") && configName.contains("native") &&
55 | (configName.contains("encoding") || configName.contains("decoding"))) {
56 | BindResult result = context.getBinder().bind(name, target);
57 | if (result.isBound()) {
58 | if (configName.contains("encoding")) {
59 | EncodingDecodingBindAdviceHandler.this.encodingSettingProvided = true;
60 | }
61 | else {
62 | EncodingDecodingBindAdviceHandler.this.decodingSettingProvided = true;
63 | }
64 | return target.withExistingValue(result.get());
65 | }
66 | }
67 | return bindHandler.onStart(name, target, context);
68 | }
69 | };
70 | return handler;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/ExtendedBindingHandlerMappingsProviderAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.stream.binder.kafka.streams;
18 |
19 | import java.util.HashMap;
20 | import java.util.Map;
21 |
22 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
23 | import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
24 | import org.springframework.cloud.stream.config.BindingHandlerAdvise.MappingsProvider;
25 | import org.springframework.context.annotation.Bean;
26 | import org.springframework.context.annotation.Configuration;
27 |
28 | /**
29 | * {@link EnableAutoConfiguration Auto-configuration} for extended binding metadata for Kafka Streams.
30 | *
31 | * @author Chris Bono
32 | * @since 3.2
33 | */
34 | @Configuration(proxyBeanMethods = false)
35 | public class ExtendedBindingHandlerMappingsProviderAutoConfiguration {
36 |
37 | @Bean
38 | public MappingsProvider kafkaStreamsExtendedPropertiesDefaultMappingsProvider() {
39 | return () -> {
40 | Map mappings = new HashMap<>();
41 | mappings.put(
42 | ConfigurationPropertyName.of("spring.cloud.stream.kafka.streams"),
43 | ConfigurationPropertyName.of("spring.cloud.stream.kafka.streams.default"));
44 | mappings.put(
45 | ConfigurationPropertyName.of("spring.cloud.stream.kafka.streams.bindings"),
46 | ConfigurationPropertyName.of("spring.cloud.stream.kafka.streams.default"));
47 | return mappings;
48 | };
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/GlobalKTableBinderConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.stream.binder.kafka.streams;
18 |
19 | import java.util.Map;
20 |
21 | import org.springframework.beans.factory.ObjectProvider;
22 | import org.springframework.beans.factory.annotation.Qualifier;
23 | import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
25 | import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
26 | import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
27 | import org.springframework.cloud.stream.binder.kafka.provisioning.AdminClientConfigCustomizer;
28 | import org.springframework.cloud.stream.binder.kafka.provisioning.KafkaTopicProvisioner;
29 | import org.springframework.cloud.stream.binder.kafka.streams.properties.KafkaStreamsBinderConfigurationProperties;
30 | import org.springframework.cloud.stream.binder.kafka.streams.properties.KafkaStreamsExtendedBindingProperties;
31 | import org.springframework.context.ApplicationContext;
32 | import org.springframework.context.annotation.Bean;
33 | import org.springframework.context.annotation.Configuration;
34 | import org.springframework.context.annotation.Import;
35 |
36 | /**
37 | * Configuration for GlobalKTable binder.
38 | *
39 | * @author Soby Chacko
40 | * @since 2.1.0
41 | */
42 | @Configuration
43 | @Import({ KafkaAutoConfiguration.class,
44 | MultiBinderPropertiesConfiguration.class,
45 | KafkaStreamsBinderHealthIndicatorConfiguration.class,
46 | KafkaStreamsJaasConfiguration.class})
47 | public class GlobalKTableBinderConfiguration {
48 |
49 | @Bean
50 | public KafkaTopicProvisioner provisioningProvider(
51 | KafkaStreamsBinderConfigurationProperties binderConfigurationProperties,
52 | KafkaProperties kafkaProperties, ObjectProvider adminClientConfigCustomizer) {
53 | return new KafkaTopicProvisioner(binderConfigurationProperties, kafkaProperties, adminClientConfigCustomizer.getIfUnique());
54 | }
55 |
56 | @Bean
57 | public GlobalKTableBinder GlobalKTableBinder(
58 | KafkaStreamsBinderConfigurationProperties binderConfigurationProperties,
59 | KafkaTopicProvisioner kafkaTopicProvisioner,
60 | KafkaStreamsExtendedBindingProperties kafkaStreamsExtendedBindingProperties,
61 | KafkaStreamsBindingInformationCatalogue kafkaStreamsBindingInformationCatalogue,
62 | @Qualifier("streamConfigGlobalProperties") Map streamConfigGlobalProperties,
63 | KafkaStreamsRegistry kafkaStreamsRegistry) {
64 |
65 | GlobalKTableBinder globalKTableBinder = new GlobalKTableBinder(binderConfigurationProperties,
66 | kafkaTopicProvisioner, kafkaStreamsBindingInformationCatalogue, kafkaStreamsRegistry);
67 | globalKTableBinder.setKafkaStreamsExtendedBindingProperties(
68 | kafkaStreamsExtendedBindingProperties);
69 | return globalKTableBinder;
70 | }
71 |
72 | @Bean
73 | @ConditionalOnBean(name = "outerContext")
74 | public static BeanFactoryPostProcessor outerContextBeanFactoryPostProcessor() {
75 | return beanFactory -> {
76 |
77 | // It is safe to call getBean("outerContext") here, because this bean is
78 | // registered as first
79 | // and as independent from the parent context.
80 | ApplicationContext outerContext = (ApplicationContext) beanFactory
81 | .getBean("outerContext");
82 | beanFactory.registerSingleton(
83 | KafkaStreamsExtendedBindingProperties.class.getSimpleName(),
84 | outerContext.getBean(KafkaStreamsExtendedBindingProperties.class));
85 | beanFactory.registerSingleton(
86 | KafkaStreamsBindingInformationCatalogue.class.getSimpleName(),
87 | outerContext.getBean(KafkaStreamsBindingInformationCatalogue.class));
88 | beanFactory.registerSingleton(
89 | KafkaStreamsRegistry.class.getSimpleName(),
90 | outerContext.getBean(KafkaStreamsRegistry.class));
91 | };
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/GlobalKTableBoundElementFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018-2020 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.springframework.cloud.stream.binder.kafka.streams;
18 |
19 | import org.aopalliance.intercept.MethodInterceptor;
20 | import org.aopalliance.intercept.MethodInvocation;
21 | import org.apache.kafka.streams.kstream.GlobalKTable;
22 |
23 | import org.springframework.aop.framework.ProxyFactory;
24 | import org.springframework.cloud.stream.binder.ConsumerProperties;
25 | import org.springframework.cloud.stream.binding.AbstractBindingTargetFactory;
26 | import org.springframework.cloud.stream.config.BindingProperties;
27 | import org.springframework.cloud.stream.config.BindingServiceProperties;
28 | import org.springframework.util.Assert;
29 |
30 | /**
31 | * {@link org.springframework.cloud.stream.binding.BindingTargetFactory} for
32 | * {@link GlobalKTable}
33 | *
34 | * Input bindings are only created as output bindings on GlobalKTable are not allowed.
35 | *
36 | * @author Soby Chacko
37 | * @since 2.1.0
38 | */
39 | public class GlobalKTableBoundElementFactory
40 | extends AbstractBindingTargetFactory {
41 |
42 | private final BindingServiceProperties bindingServiceProperties;
43 | private final EncodingDecodingBindAdviceHandler encodingDecodingBindAdviceHandler;
44 | private final KafkaStreamsBindingInformationCatalogue kafkaStreamsBindingInformationCatalogue;
45 |
46 | GlobalKTableBoundElementFactory(BindingServiceProperties bindingServiceProperties,
47 | EncodingDecodingBindAdviceHandler encodingDecodingBindAdviceHandler,
48 | KafkaStreamsBindingInformationCatalogue kafkaStreamsBindingInformationCatalogue) {
49 | super(GlobalKTable.class);
50 | this.bindingServiceProperties = bindingServiceProperties;
51 | this.encodingDecodingBindAdviceHandler = encodingDecodingBindAdviceHandler;
52 | this.kafkaStreamsBindingInformationCatalogue = kafkaStreamsBindingInformationCatalogue;
53 | }
54 |
55 | @Override
56 | public GlobalKTable createInput(String name) {
57 | BindingProperties bindingProperties = this.bindingServiceProperties.getBindingProperties(name);
58 | ConsumerProperties consumerProperties = bindingProperties.getConsumer();
59 | if (consumerProperties == null) {
60 | consumerProperties = this.bindingServiceProperties.getConsumerProperties(name);
61 | consumerProperties.setUseNativeDecoding(true);
62 | }
63 | else {
64 | if (!encodingDecodingBindAdviceHandler.isDecodingSettingProvided()) {
65 | consumerProperties.setUseNativeDecoding(true);
66 | }
67 | }
68 | // Always set multiplex to true in the kafka streams binder
69 | consumerProperties.setMultiplex(true);
70 |
71 | // @checkstyle:off
72 | GlobalKTableBoundElementFactory.GlobalKTableWrapperHandler wrapper = new GlobalKTableBoundElementFactory.GlobalKTableWrapperHandler();
73 | // @checkstyle:on
74 | ProxyFactory proxyFactory = new ProxyFactory(
75 | GlobalKTableBoundElementFactory.GlobalKTableWrapper.class,
76 | GlobalKTable.class);
77 | proxyFactory.addAdvice(wrapper);
78 |
79 | final GlobalKTable proxy = (GlobalKTable) proxyFactory.getProxy();
80 | this.kafkaStreamsBindingInformationCatalogue.addBindingNamePerTarget(proxy, name);
81 | return proxy;
82 | }
83 |
84 | @Override
85 | public GlobalKTable createOutput(String name) {
86 | throw new UnsupportedOperationException(
87 | "Outbound operations are not allowed on target type GlobalKTable");
88 | }
89 |
90 | /**
91 | * Wrapper for GlobalKTable proxy.
92 | */
93 | public interface GlobalKTableWrapper {
94 |
95 | void wrap(GlobalKTable