I checked that the hostname can be resolved and that the port works by running a socket when the container starts.
1 of 3 attempts to connect to schema-registry/172.18.0.4:8081
[main] INFO Readiness - Connecting to schema-registry/172.18.0.4:8081 successful
But when I use the
CachedSchemaRegistryClient to register a schema form the same container, it throws a Connection Refused exception.
ERROR io.confluent.kafka.schemaregistry.client.rest.RestService - Failed to send HTTP request to endpoint: http://schema-registry/172.18.0.4:8081/subjects/FindRecentReviews/versions
java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
at sun.net.www.http.HttpClient.New(HttpClient.java:339)
at sun.net.www.http.HttpClient.New(HttpClient.java:357)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1202)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:966)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291)
at io.confluent.kafka.schemaregistry.client.rest.RestService.sendHttpRequest(RestService.java:142)
at io.confluent.kafka.schemaregistry.client.rest.RestService.httpRequest(RestService.java:187)
at io.confluent.kafka.schemaregistry.client.rest.RestService.registerSchema(RestService.java:238)
at io.confluent.kafka.schemaregistry.client.rest.RestService.registerSchema(RestService.java:230)
at io.confluent.kafka.schemaregistry.client.rest.RestService.registerSchema(RestService.java:225)
at io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.registerAndGetId(CachedSchemaRegistryClient.java:59)
at io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.register(CachedSchemaRegistryClient.java:91)
at science.peers.message.model.MessageSchemaRegistry.register(MessageSchemaRegistry.scala:27)
at science.peers.protocol.AvroBinarySerializable.toByteArray(BinarySerializable.scala:30)
at science.peers.protocol.AvroBinarySerializable.toByteArray$(BinarySerializable.scala:26)
at science.peers.unsorted.protocol.FindRecentReviews.toByteArray(UnsortedOrder.scala:105)
at science.peers.message.model.serializers.MessageSerializer.serializeImpl(MessageSerializer.scala:27)
at science.peers.message.model.serializers.MessageSerializer.serialize(MessageSerializer.scala:22)
at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:463)
at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:440)
This is my docker compose file.
# For development purposes
version: '3'
services:
kafka:
image: confluentinc/cp-kafka:3.2.1
hostname: kafka
container_name: kafka
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:32181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092
zookeeper:
image: confluentinc/cp-zookeeper:3.2.1
hostname: zookeeper
container_name: zookeeper
environment:
ZOOKEEPER_CLIENT_PORT: 32181
ZOOKEEPER_TICK_TIME: 2000
schema-registry:
image: confluentinc/cp-schema-registry:3.2.1
hostname: schema-registry
container_name: schema-registry
depends_on:
- zookeeper
- kafka
environment:
SCHEMA_REGISTRY_HOST_NAME: 0.0.0.0
SCHEMA_REGISTRY_LISTENERS: http://0.0.0.0:8081
SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: zookeeper:32181
web-server:
image: my-image:0.0.1
container_name: my_image
ports:
- "8080:8080"