Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
techjourney010 opened this issue May 20, 2021 · 2 comments · Fixed by #1082
Milestone

Comments

@techjourney010
Copy link

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
Copy link
Contributor

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
Copy link
Contributor

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

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

sobychacko added a commit to sobychacko/spring-cloud-stream-binder-kafka that referenced this issue May 24, 2021
Going forward, binder will use the default ack on error settings
in Spring Kafka, which is true by default. If the applicaitons
need to change this behavior, then a custom error handler must
be provided through ListenerContainerCustomizer.

Resolves spring-cloud#1079
garyrussell pushed a commit that referenced this issue May 24, 2021
Going forward, binder will use the default ack on error settings
in Spring Kafka, which is true by default. If the applicaitons
need to change this behavior, then a custom error handler must
be provided through ListenerContainerCustomizer.

Resolves #1079
@sobychacko sobychacko added this to the 3.2.0 milestone Dec 1, 2021
akutschera added a commit to akutschera/how-do-i-test-this that referenced this issue May 4, 2022
Add property to tests with embedded kafka (see spring-cloud/spring-cloud-stream-binder-kafka#1079 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants