Search code examples
javaapache-kafkakafka-producer-apiconfluent-schema-registry

Want to enter the hostname:9092 in BootStrap url(I have the hostname entry against the actual url in my host file windows) JAVA


Want to enter subham-virtualbox:9092 instead of 172.16.6.86:9092 as my bootstrapURL and schemaRegistryurl.

I have this entry in my host file to get resolved

172.16.6.86 subham-virtualbox

Tried doing this, got error,

Exception in thread "main" org.apache.kafka.common.errors.SerializationException: Error serializing Avro message
Caused by: java.net.MalformedURLException: unknown protocol: subham-virtualbox
    at java.net.URL.<init>(URL.java:617)
    at java.net.URL.<init>(URL.java:507)
    at java.net.URL.<init>(URL.java:456)
    at io.confluent.kafka.schemaregistry.client.rest.RestService.sendHttpRequest(RestService.java:175)
    at io.confluent.kafka.schemaregistry.client.rest.RestService.httpRequest(RestService.java:256)
    at io.confluent.kafka.schemaregistry.client.rest.RestService.registerSchema(RestService.java:356)
    at io.confluent.kafka.schemaregistry.client.rest.RestService.registerSchema(RestService.java:348)
    at io.confluent.kafka.schemaregistry.client.rest.RestService.registerSchema(RestService.java:334)
    at io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.registerAndGetId(CachedSchemaRegistryClient.java:168)
    at io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.register(CachedSchemaRegistryClient.java:222)
    at io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.register(CachedSchemaRegistryClient.java:198)
    at io.confluent.kafka.serializers.AbstractKafkaAvroSerializer.serializeImpl(AbstractKafkaAvroSerializer.java:70)
    at io.confluent.kafka.serializers.KafkaAvroSerializer.serialize(KafkaAvroSerializer.java:53)
    at org.apache.kafka.common.serialization.Serializer.serialize(Serializer.java:62)
    at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:903)
    at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:865)
    at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:752)
    at com.github.meSubhamSaraf.AvroSerializerDemo.main(AvroSerializerDemo.java:58)

Solution

  • The error is not saying UnknownHostException

    schema.registry.url requires a protocol, and it's port is not 9092

    http://subham-virtualbox:8081

    Your bootstrap servers can be subham-virtualbox:9092

    Personally, I would suggest using Docker with a simple port forward for the Registry, not a whole VM.
    Otherwise, Vagrant works great and can edit the hosts file for you via a plugin