dongzhouzhang8696 2018-04-05 18:36
浏览 723

Kafka-Json(最佳做法)

I need to push output of RESTAPI call into KAFKA. Restapi returns json output which has supporting information along with data output into json.RawMessage

type Response struct {
    RequestID     string `json:"requestId"`
    Success       bool   `json:"success"`
    NextPageToken string `json:"nextPageToken,omitempty"`
    MoreResult    bool   `json:"moreResult,omitempty"`
    Errors        []struct {
        Code    string `json:"code"`
        Message string `json:"message"`
    } `json:"errors,omitempty"`
    **Result   json.RawMessage `json:"result,omitempty"`**
    Warnings []struct {
        Code    string `json:"code"`
        Message string `json:"message"`
    } `json:"warning,omitempty"`
}

json.RawMessage has data for 200 records.

Question: 1. As a producer, should I put the whole raw message into kafka topic as one message? Or unmarshal(parse) the json raw message and put each message records as a message( In this case there will be 200 records) 2. if I unmarshal(parse) the data will not be in json format anymore.

I'm not providing any code here... my code can be in GO, python

End consumer for the topic is Spark or custom program which read the data from topic and push the data to another system.

Please let me know what's the best design/ approach?

Thanks

  • 写回答

1条回答 默认 最新

  • douhuan1901 2018-04-05 19:00
    关注

    There's no other answer than a great big "It Depends" :)

    It Depends on what you're doing with the data ("push to another system" is just a step on the way to doing something with the data), and it depends on the semantic and business meaning of the data.

    If each of your 200 messages means something on its own, independent from other messages, then unbundling and putting as individual messages on Kafka makes sense.

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮