spring-cloud / spring-cloud-stream-binder-kafka

Spring Cloud Stream binders for Apache Kafka and Kafka Streams
Apache License 2.0
331 stars 301 forks source link

Consumer creation invokes a method that doesn't exist in ContainerProperties from spring-kafka:2.7.1 #1079

Closed techjourney010 closed 3 years ago

techjourney010 commented 3 years ago

ContainerProperties.setAckOnError(boolean) doesn't exist in spring-kafka:2.7.1 and consumer creation tries to invoke it

Spring Cloud Stream project is generated using: start.spring.io

@SpringBootApplication
public class Application {

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

    @Bean
    Consumer<Expense> expense() {
        return (expense -> {
            System.out.println("Received Type:" + expense.getClass().getCanonicalName());
            System.out.println("Received:" + expense);
        });
    }

}

application.yml:

spring:
  cloud:
      stream:
        bindings:
          expense-in-0:
            destination: expensetopic
            content-type: application/*+avro
            group: gr1
            consumer:
              use-native-encoding: true
        kafka:
          binder:
            brokers: 127.0.0.1:9092
          bindings:
              expense-in-0:
                consumer:
                  configuration:
                    value.deserializer: io.confluent.kafka.serializers.KafkaAvroDeserializer
                    specific.avro.reader: true

Consumer creation fails at start up Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'inputBindingLifecycle'; nested exception is java.lang.NoSuchMethodError: 'void org.springframework.kafka.listener.ContainerProperties.setAckOnError(boolean)'

Spring boot parent: <version>2.5.0-SNAPSHOT</version> Spring cloud:
<spring-cloud.version>2020.0.3-SNAPSHOT</spring-cloud.version>

As binder I use Kafka:

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-kafka</artifactId>
</dependency>

and it brings to the project spring-kafka:2.7.1 image

Starting the app:

***************************
APPLICATION FAILED TO START
***************************

Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.cloud.stream.binder.kafka.KafkaMessageChannelBinder.createConsumerEndpoint(KafkaMessageChannelBinder.java:716)

The following method did not exist:

    'void org.springframework.kafka.listener.ContainerProperties.setAckOnError(boolean)'

The method's class, org.springframework.kafka.listener.ContainerProperties, is available from the following locations:

    jar:file:/C:/Users/me/.m2/repository/org/springframework/kafka/spring-kafka/2.7.1/spring-kafka-2.7.1.jar!/org/springframework/kafka/listener/ContainerProperties.class

The class hierarchy was loaded from the following locations:

    org.springframework.kafka.listener.ContainerProperties: file:/C:/Users/me/.m2/repository/org/springframework/kafka/spring-kafka/2.7.1/spring-kafka-2.7.1.jar
    org.springframework.kafka.listener.ConsumerProperties: file:/C:/Users/me/.m2/repository/org/springframework/kafka/spring-kafka/2.7.1/spring-kafka-2.7.1.jar

Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.kafka.listener.ContainerProperties
sobychacko commented 3 years ago

I suggest downgrading to Spring Kafka 2.6.x in your application. We will see if we can get that fixed in the meantime.

garyrussell commented 3 years ago

Explicitly setting the ackMode property (RECORD or BATCH) avoids this problem.

spring.cloud.stream.kafka.bindings.input-in-0.consumer.ack-mode=BATCH