• 问题引出

新产品的体系架构包含多个模块,模块集特点是数量多、模块间交互复杂。那么统一接口是一个很好的解决方案,为了实现统一接口打算采用微服务的核心思想,设计了采用restful service的数据交互方式技术架构。这里记录一下kafka资源访问的服务化搭建,后续记录api和实战。

  • 解决方案

restful api的出现在很大程度上降低了模块/系统数据交互的难度(开发和使用),特别是对前后端数据访问上。于是基于此,找到了confluent。confluent是kafka的创始团队离开Linkin后研发出来的产品,所以是一个很强大的产品级工具平台。confluent开源版本中包含了kafka rest proxy,具体如下:

  1. 下载confluent:

    https://www.confluent.io/download/
    

    备注:下载包过程中需要填写email信息,尽管填就行。

  2. zk集群、kafka集群启动,这里就不介绍,具体请参考kafka集群搭建
  3. 由于confluent中包含了zk和kafka,这里就不用去处理。直接配置kafka rest proxy, 配置文件位置:
    /Users/xnchall/Software/confluent/confluent-4.1./etc/kafka-rest/kafka-rest.properties

    配置如下:

  4. id=kafka-rest-test-server

    schema.registry.url=http://192.168.X.100:8081

    zookeeper.connect=192.168.X.100:2181,192.168.X.100:2182

    bootstrap.servers=PLAINTEXT://192.168.X.100:9092

    schema.registry.url这个参数是为数据序列化avor服务的,建议配置上,说不定将来就用上了呢。其余两个分别是zookeeper和kafka集群配置。

  5. 配置schema-registry:
    路径:/Users/xnchall/Software/confluent/confluent-4.1./etc/schema-registry
    配置如下:
    # The address the socket server listens on.
    # FORMAT:
    # listeners = listener_name://host_name:port
    # EXAMPLE:
    # listeners = PLAINTEXT://your.host.name:9092
    listeners=http://0.0.0.0:8088 # Zookeeper connection string for the Zookeeper cluster used by your Kafka cluster
    # (see zookeeper docs for details).
    # This is a comma separated host:port pairs, each corresponding to a zk
    # server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
    kafkastore.connection.url=192.168.x.100:,192.168.x.100: # Alternatively, Schema Registry can now operate without Zookeeper, handling all coordination via
    # Kafka brokers. Use this setting to specify the bootstrap servers for your Kafka cluster and it
    # will be used both for selecting the master schema registry instance and for storing the data for
    # registered schemas.
    # (Note that you cannot mix the two modes; use this mode only on new deployments or by shutting down
    # all instances, switching to the new configuration, and then starting the schema registry
    # instances again.)
    #kafkastore.bootstrap.servers=PLAINTEXT://localhost:9092 # The name of the topic to store schemas in
    kafkastore.topic=_schemas # If true, API requests that fail will include extra debugging information, including stack traces
    debug=True
  6. 启动kafka rest服务
    路径:/Users/xnchall/Software/confluent/confluent-4.1./bin
    启动命令:
    ./kafka-rest-start ../etc/kafka-rest/kafka-rest.properties 注意:前提是kafka和zk已经全部正常启动
  7. 启动schema-registry(可以不启动)
    路径:同kafka-rest
    启动命令:
    ./schema-registry-start ../etc/schema-registry/schema-registry.properties
  8. 检查kafka-rest否正常启动
    方式一:jps
    方式二:http://192.168.X.100:8082/topics
    建议使用方式二直观明了
  • 后续

至此,kafka-restful service算是搭建和启动完成,接下来就是具体通过kafka rest proxy访问kafka资源了,核心包括生产消息、各类消费消息、资源释放与本身负载均衡、以及存在问题等,请见待更新 kafka rest api介绍与实战

参考:https://www.confluent.io

05-11 19:28