本章将使用Docker来部署Confluent Schema Registry,
如果上一节的zoonavigator容器正在运行,需要将其先停止掉:docker stop zoonavigator
我们将继续使用AKHQ一节中的docker-compose.yaml
文件。
编辑docker-compose.yaml
的大概第69行的SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS
字段,将其替换为msk集群的broker连接地址,并增加ports
字段,将docker内部的8085端口映射:
schema-registry:
image: confluentinc/cp-schema-registry
depends_on:
- kafka
environment:
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: 'b-2.mskdemo.mxqzz7.c4.kafka.ap-southeast-1.amazonaws.com:9092,b-1.mskdemo.mxqzz7.c4.kafka.ap-southeast-1.amazonaws.com:9092,b-3.mskdemo.mxqzz7.c4.kafka.ap-southeast-1.amazonaws.com:9092'
SCHEMA_REGISTRY_HOST_NAME: 'schema-registry'
SCHEMA_REGISTRY_LISTENERS: 'http://0.0.0.0:8085'
SCHEMA_REGISTRY_LOG4J_ROOT_LOGLEVEL: 'INFO'
ports:
- 8085:8085
然后保存
重新更新docker-compose
并运行:
docker-compose up --force-recreate --build -d
等大概一分钟后所有镜像会创建完毕,并初始化完成。
访问本机的8085端口,会看到有json结果返回:
此时访问AKHQ的Schema Registry
页面,会看到Create a Subject
选项:
创建Schema:
Schema的文本如下:
{
"type":"record",
"name":"MyRecord",
"namespace":"com.mycompany",
"fields": [
{ "name": "id", "type": "string"},
{ "name": "first_name", "type": "string", "default": ""},
{ "name": "last_name", "type": "string", "default":""}
]
}
创建完成后,可以在Schema Registry
的页面看到所有Subject:
上一步中,我们创建了一个Record,其中有很多json字段,说明如下:
例如,一个record例子:
{
"type": "record",
"namespace": "com.aaa",
"name": "Employee",
"fields": [
{ "name": "id", "type": "string"},
{ "name": "first_name", "type": "string", "default": ""},
{ "name": "last_name", "type": "string", "default":""}
]
}