使用confluent本地安装和使用kafka(3)
- UID
- 1066743
|
使用confluent本地安装和使用kafka(3)
启动服务
启动kafka-rest
bin/kafka-rest-start etc/kafka-rest/kafka-rest.properties
上面的这种方式是前台启动,也可以以后台方式启动。
nohup bin/kafka-rest-start etc/kafka-rest/kafka-rest.properties &
启动zookeeper
bin/zookeeper-server-start -daemon etc/kafka/zookeeper.properties
启动kafka broker
bin/kafka-server-start -daemon etc/kafka/server.properties
启动schema registry
bin/schema-registry-start -daemon etc/schema-registry/schema-registry.properties
测试使用
查看topics
浏览器访问或者curl都可以
http://192.168.11.91:8082/topics
查看集群的brokers
curl http://192.168.11.91:8082/brokers
注册consumer group
curl -X POST -H "Content-Type: application/vnd.kafka.v2+json" -H "Accept: application/vnd.kafka.v2+json" --data '{"name": "my_consumer_instance", "format": "json", "auto.offset.reset": "earliest"}' http://localhost:8082/consumers/my_test_consumer
把topic和消费者my_consumer关联起来
curl -X POST -H "Content-Type: application/vnd.kafka.v2+json" --data '{"topics":["bear"]}' http://localhost:8082/consumers/my_test_consumer/instances/my_consumer_instance/subscription
通过rest接口向bear push数据
curl -X POST -H "Content-Type: application/vnd.kafka.json.v2+json" --data '{"records":[{"value":{"name": "testUser"}}]}' "http://localhost:8082/topics/bear"
通过rest接口消费数据
curl -X GET -H "Accept: application/vnd.kafka.json.v2+json" http://localhost:8082/consumers/my_test_consumer/instances/my_consumer_instance/records
删除注册的consumer实例:
curl -X DELETE -H "Accept: application/vnd.kafka.v2+json" http://localhost:8082/consumers/my_test_consumer/in |
|
|
|
|
|