我通过以下方式运行Zookeeper,Kafka和Schema Registry:

#zookeper
docker run -d -it \
    --net=host \
    --name=zookeeper \
    -e ZOOKEEPER_CLIENT_PORT=32181 \
    confluentinc/cp-zookeeper:4.0.0

#kafka
docker run -d \
    --net=host \
    --name=kafka \
    -e KAFKA_ZOOKEEPER_CONNECT=localhost:32181 \
    -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:29092 \
    -e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 \
    confluentinc/cp-kafka:4.0.0

#schema-registry
docker run -d \
  --net=host \
  --name=schema-registry \
  -e SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL=localhost:32181 \
  -e SCHEMA_REGISTRY_HOST_NAME=localhost \
  -e SCHEMA_REGISTRY_LISTENERS=http://localhost:8081 \
  confluentinc/cp-schema-registry:4.0.0

我已经在Kafka中手动创建了一个主题,如下所示:
kafka-topics --create --topic newflow --partitions 1 --replication-factor 1 --if-not-exists --zookeeper localhost:32181

我可以通过以下方式将架构分配给主题:
kafka-avro-console-producer --broker-list localhost:29092 --topic newflow --property value.schema='{"type":"record","name":"myrecord","fields":[{"name":"A","type":"int"},{"name":"B","type":"long"},{"name":"C","type":"string"},{"name":"D","type":"int"}]}'

我无法通过以下方式在REST命中URL的架构注册表中找到其架构:
curl -X GET http://localhost:8081/subjects
[]

最佳答案

可以通过以下方式通过CURL选项在Schema Registry中显式注册该架构:

curl -X POST -H "Content-Type:application/vnd.schemaregistry.v1+json" \
--data '{"schema": "{\"type\":\"record\",\"name\":\"myrecord\",\"fields\":[{\"name\":\"A\",\"type\":\"int\"},{\"name\":\"B\",\"type\":\"long\"},{\"name\":\"C\",\"type\":\"string\"},{\"name\":\"D\",\"type\":\"int\"}]}"}' \
http://localhost:8081/subjects/newflow-value/versions

关于docker - 在架构注册表中使用主题注册Avro架构,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49873281/

10-16 23:54