想要在 BootStrap url 中输入 hostname:9092(我的主机文件 windows 中有针对实际 url 的主机名条目)JAVA

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

想输入 subham-virtualbox:9092 而不是 172.16.6.86:9092 作为我的 bootstrapURL 和 schemaRegistryurl。

我的主机文件中有这个条目需要解决

172.16.6.86 subham-virtualbox

尝试这样做,出现错误,

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)

错误不是说 UnknownHostException

schema.registry.url需要协议,端口不是9092

http://subham-virtualbox:8081

您的 bootstrap 服务器可以是 subham-virtualbox:9092

就我个人而言,我建议使用 Docker 和注册表的简单端口转发,而不是整个 VM。
否则,Vagrant works great 并且可以通过插件为您编辑主机文件