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

Add support for Apache Kafka native image #8993

Merged
merged 1 commit into from
Jul 25, 2024
Merged

Conversation

eddumelendez
Copy link
Member

No description provided.

@eddumelendez eddumelendez requested a review from a team as a code owner July 25, 2024 13:34
@eddumelendez eddumelendez added this to the next milestone Jul 25, 2024
@eddumelendez eddumelendez merged commit b08a232 into main Jul 25, 2024
5 of 6 checks passed
@eddumelendez eddumelendez deleted the support-kafka-native branch July 25, 2024 14:37
@davetroiano
Copy link

Hi @eddumelendez do you know when a new org.testcontainers:kafka module (v 1.20.1? 1.21.0?) will be released? Is there a pre-release module available anywhere?

@eddumelendez
Copy link
Member Author

eddumelendez commented Jul 25, 2024

I'm planning to release it next week. In the meantime you can use new org.testcontainers.kafka.KafkaContainer(DockerImageName.parse("apache/kafka-native:3.8.0-rc3"). asCompatibleSubstituteFor("apache/kafka"));

@davetroiano
Copy link

In the meantime you can use new org.testcontainers.kafka.KafkaContainer(DockerImageName.parse("apache/kafka-native:3.8.0-rc3"));

Won't I need the new release to avoid an exception? I tried this out and hit:

java.lang.IllegalStateException: Failed to verify that image 'apache/kafka-native:3.8.0-rc3' is a compatible substitute for 'apache/kafka'.

@eddumelendez
Copy link
Member Author

I have updated my previous answer. You don't need a new release if you do so. Look at Image Name Substitution

@prabhamanepalli
Copy link

Hi Eddu and Dave,

I am directly using without image substitution. However, I am still facing the error Dave shared above.
Can you explain my next steps ?
Do I have to wait for the next module release to make it work without image substitution?

Thanks.

@eddumelendez
Copy link
Member Author

Hi @prabhamanepalli, this has not been released yet. So, the substitution should be done. This change will be part of the next release and could be used without image substitution.

@jabrena
Copy link

jabrena commented Jul 31, 2024

Hi,

I am testing with Spring boot the new native image and using latest version fo testcontainers 1.20.1:

//private static final String kafkaVersion = "confluentinc/cp-kafka:7.7.0";
private static final String kafkaVersion = "apache/kafka-native:3.8.0";

private static Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(logger);

@Bean
@ServiceConnection
KafkaContainer kafkaContainer() {
        logger.info("Creating Kafka Broker");
        var imageName = DockerImageName.parse(kafkaVersion).asCompatibleSubstituteFor("confluentinc/cp-kafka");
        return new KafkaContainer(imageName).withLogConsumer(logConsumer);
}

but I am receiving the following error:

2024-07-31 16:51:22.430  INFO tc.apache/kafka-native:3.8.0 - Creating container for image: apache/kafka-native:3.8.0
2024-07-31 16:51:22.586  INFO tc.apache/kafka-native:3.8.0 - Container apache/kafka-native:3.8.0 is starting: 32c567b0f548459ff257c88b30dd06d7a60f9cee4ab579b925da8edfdffd9861
2024-07-31 16:51:23.072  INFO i.j.m.c.KafkaContainerConfig - STDERR: /tmp/testcontainers_start.sh: line 3: /etc/confluent/docker/ensure: No such file or directory
2024-07-31 16:51:23.072  INFO i.j.m.c.KafkaContainerConfig - STDERR: /tmp/testcontainers_start.sh: line 7: zookeeper-server-start: command not found
2024-07-31 16:51:23.072  INFO i.j.m.c.KafkaContainerConfig - STDERR: /tmp/testcontainers_start.sh: line 8: /etc/confluent/docker/run: No such file or directory

If I don´t put the compability option:

.asCompatibleSubstituteFor("confluentinc/cp-kafka")

I receive:

Caused by: java.lang.IllegalStateException: Failed to verify that image 'apache/kafka-native:3.8.0' is a compatible substitute for 'confluentinc/cp-kafka'. This generally means that you are trying to use an image that Testcontainers has not been designed to use. If this is deliberate, and if you are confident that the image is compatible, you should declare compatibility in code using the `asCompatibleSubstituteFor` method. For example:
   DockerImageName myImage = DockerImageName.parse("apache/kafka-native:3.8.0").asCompatibleSubstituteFor("confluentinc/cp-kafka");
and then use `myImage` instead.

How to solve this issue?

@eddumelendez
Copy link
Member Author

Hi, you are using org.testcontainers.containers.KafkaContainer but apache/kafka-native is supported at org.testcontainers.kafka.KafkaContainer

@jabrena
Copy link

jabrena commented Jul 31, 2024

Many thanks @eddumelendez, now it is working the example but not using Service Connection:

Caused by: org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsNotFoundException: No ConnectionDetails found for source '@ServiceConnection source for Bean 'kafkaContainer' defined in class path resource [info/jab/ms/controller/KafkaContainerConfig.class]'

To run the test, I used the previous approach:

public class KafkaContainerInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
...
}

The question that I have is why not use the same annotation for all kafka containers:

  • Confluent
  • Apache Kafka
  • Apache Kafka native
  • Red Panda

BTW, the performance improvement is huge :)

Juan Antonio

@eddumelendez
Copy link
Member Author

@jabrena this is expected because org.testcontainers.kafka.KafkaConainer is a new implementation. Support in spring boot has been added for 3.4.0-M1. See spring-projects/spring-boot#40695

The question that I have is why not use the same annotation for all kafka containers

You can take a look at each implementation and those handle different things, env vars or configuration files, in order to set it up correctly.

@jabrena
Copy link

jabrena commented Jul 31, 2024

@eddumelendez it is clear for me.

Great job 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants