基於kafka rest實現資源訪問服務化(實戰)


  • 問題引出

新產品的體系架構包含多個模塊,模塊集特點是數量多、模塊間交互復雜。那么統一接口是一個很好的解決方案,為了實現統一接口打算采用微服務的核心思想,設計了采用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.2/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.2/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:2181,192.168.x.100:2182
    
    # 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.2/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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM