spring-cloud / spring-cloud-stream

Framework for building Event-Driven Microservices
http://cloud.spring.io/spring-cloud-stream
Apache License 2.0
987 stars 602 forks source link

Two BinderConfigurationPropertiesBeans are created #2351

Closed zhaozhiguang closed 2 years ago

zhaozhiguang commented 2 years ago

https://github.com/spring-cloud/spring-cloud-stream-binder-kafka/issues/879

There seems to be a similar problem in my previous 3.2

error: Parameter 0 of method jaasInitializer in org.springframework.cloud.stream.binder.kafka.streams.KafkaStreamsJaasConfiguration required a single bean, but 2 were found:

my config

spring:
  kafka:
    bootstrap-servers:
      - xx:9092
      - xx:9093
      - xx:9092
  cloud:
    stream:
      kafka:
        streams:
          bindings:
            process-in-0:
              consumer:
                application-id: myKafkaStreamApp
                native-decoding: true 
          binder:
            deserialization-exception-handler: logAndContinue 
            state-store-retry: 
              max-attempts: 1 
              backoff-period: 1000 
            configuration:
              num.stream.threads: 8 
      function:
        definition: process 
      binders:
        myKafkaStream:
          type: kstream
      bindings:
        process-in-0: 
          destination: newTopic10 
          content-type: text/plain
          group: myStream
          binder: myKafkaStream
<properties>
        <java.version>11</java.version>
        <spring-cloud.version>2021.0.1</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-kafka-streams</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
            <scope>test</scope>
            <classifier>test-binder</classifier>
            <type>test-jar</type>
        </dependency>
    </dependencies>

my code

@Bean
public Consumer<KStream<Object, String>> process() {
    return input ->
            input.foreach((key, value) -> {
                System.out.println("Key: " + key + " Value: " + value);
            });
}

)

sobychacko commented 2 years ago

This issue was addressed before. Any chance you can create a minimally reproducible sample and share it here? Then we can triage the issue further.

zhaozhiguang commented 2 years ago

This issue was addressed before. Any chance you can create a minimally reproducible sample and share it here? Then we can triage the issue further.

I uploaded the yml before,Then I'll send you others

java code

@SpringBootApplication
public class ControlKafkaStreamApplication {

    @Bean
    public Consumer<KStream<Object, String>> process() {
        return input ->
                input.foreach((key, value) -> {
                    System.out.println("Key: " + key + " Value: " + value);
                });
    }

    public static void main(String[] args) {
        SpringApplication.run(ControlKafkaStreamApplication.class, args);
    }

}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>control_kafka_stream</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>control_kafka_stream</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
        <spring-cloud.version>2021.0.1</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-kafka-streams</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream</artifactId>
            <scope>test</scope>
            <classifier>test-binder</classifier>
            <type>test-jar</type>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
olegz commented 2 years ago

No, please create a complete project that reproduces the issue, push it to github somewhere and post a link here so we can test it exactly the same way as you do. Posting fragments here is not useful and time consuming for us to create something reproducible without any guarantee

sobychacko commented 2 years ago

@zhaozhiguang, Any updates on creating a minimal sample to reproduce the issue?

olegz commented 2 years ago

Closing it due to lack of followup from the original reporter