Hello Do you know how can we connect "SchemaRegistry TestContainer" to Kafka TestContainer if we used @ServiceAnnotation. do have any working example for the same, I don't want to use DynamicPropertyRegistry.
@Bean
@ServiceConnection
KafkaContainer kafkaContainer() {
return new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka")
.withTag(KAFKA_VERSION)).withReuse(true);
}
@Bean
@ServiceConnection
GenericContainer schemaRegistryContainer(KafkaContainer kafkaContainer) {
return new GenericContainer("confluentinc/cp-schema-registry:7.6.1")
.withExposedPorts(8081)
.withReuse(true)
.dependsOn(kafkaContainer)
.withNetwork(kafkaContainer.getNetwork())
.withEnv("SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS",
"PLAINTEXT://" + kafkaContainer.getNetworkAliases().get(0) + ":9092")
.withEnv("SCHEMA_REGISTRY_HOST_NAME", "schema-registry")
.withEnv("SCHEMA_REGISTRY_LISTENERS", "http://0.0.0.0:9092");
}
Comment From: wilkinsona
There's no @ServiceConnection support for cp-schema-registry so you'll have to either:
- use
DynamicPropertyRegistryto configure properties based on settings from the running schema registry container. - Create your own
ContainerConnectionDetailsFactorysub-class forcp-schema-registryand register it inspring.factoriesunder theorg.springframework.boot.autoconfigure.service.connection.ConnectionDetailsFactorykey
Beyond these two options, configuring two containers to be able to communicate with each other is a Testcontainers feature for which Spring Boot has no additional support. You'll have to use Testcontainers' standard APIs to set things up.
Comment From: eddumelendez
Hi @deepakraghav0 , please take a look at this, where all the confluent images are configured.
Comment From: wilkinsona
Thanks very much, @eddumelendez.
Comment From: deepakraghav0
Hi @deepakraghav0 , please take a look at this, where all the confluent images are configured.
Hi @eddumelendez
Thanks for the reply, I tried to use your example, though it started the containers. But as there is no integration test-cases written in it, I tried to written one, but it was not able to find kafka bootstrap urls, if would be very helpful if you can give me some example having integration test written in it.
Comment From: deepakraghav0
Hi @deepakraghav0 , please take a look at this, where all the confluent images are configured.
Hi @eddumelendez
Thanks for the reply, I tried to use your example, though it started the containers. But as there is no integration test-cases written in it, I tried to written one, but it was not able to find kafka bootstrap urls, if would be very helpful if you can give me some example having integration test written in it.
can you please reply.