本章将使用Docker来部署Confluent REST Proxy,
如果上一节的zooNavigator容器正在运行,需要将其先停止掉:docker stop zoonavigator
我们将继续使用AKHQ一节中的docker-compose.yaml
文件, 在此基础上增加REST Proxy的定义。
在schema-registry
的下面增加rest-proxy
容器定义
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
# 新增下面部分,将KAFKA_REST_BOOTSTRAP_SERVERS根据实际情况替换
rest-proxy:
image: confluentinc/cp-kafka-rest
ports:
- "8082:8082"
depends_on:
- schema-registry
environment:
KAFKA_REST_SCHEMA_REGISTRY_URL: schema-registry
KAFKA_REST_HOST_NAME: rest-proxy
KAFKA_REST_LISTENERS: 'http://0.0.0.0:8082'
KAFKA_REST_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'
完整的docker-compose.yaml
文件可从 https://pingfan.s3.amazonaws.com/files/rest-proxy-docker-compose.yaml 下载
重新更新docker-compose
并运行:
docker-compose up --force-recreate --build -d
等大概一分钟后所有镜像会创建完毕,并初始化完成。
访问本机的8082端口,会看到有json结果返回:
查看topic详情:
其他的API,例如创建topic、发送消息、接收消息等,参考 https://docs.confluent.io/platform/current/kafka-rest/api.html#topics 文档,在此不做测试。