我正在以下列方式运行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
[]
答案 0 :(得分:1)
可以通过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