json数据的Apache Beam流处理 [英] Apache Beam stream processing of json data

查看:36
本文介绍了json数据的Apache Beam流处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在分析 Apache Beam 数据流处理.我从事过 Apache Kafka 流处理(生产者、消费者等).我现在想和 Beam 比较一下.

I am analyzing Apache Beam stream processing of data. I have worked on Apache Kafka stream processing (Producer, Consumer etc). I want to compare it with Beam now.

我想以编程方式 (Java) 使用 Apache Beam 流式传输简单的 json 数据.

I want to to stream simple json data using Apache Beam programmatically (Java).

{"UserID":"1","Address":"XXX","ClassNo":"989","UserName":"Stella","ClassType":"YYY"}

有人可以指导我或通过示例链接指导我吗?

Can someone please guide me or direct me with an example link?

推荐答案

这有多个方面:

  • 首先,您需要确定数据的来源:
    • 您需要在 Beam 管道中使用某种 IO,请参阅 此处;
    • 有一堆内置 IO,请参阅列表这里;
    • 通过使用上述链接中的 IO,您可能会获得包含这些 JSON 对象的字符串流;
    • 有些 IO 可以原生解析 Avro 和其他格式 (PubsubIO),这取决于具体的 IO 实现;

    那么您可能需要转换数据:

    then you may need to transform the data:

    • 您需要创建自己的 PTransform,它处理从 JSON 字符串到 Java 类的转换:
      • 查看关于 PTransforms 的部分这里;
      • 此 JsonToRow PTransform 接受带有 JSON 对象的字符串并将其转换为 Beam Row 使用 Jackson ObjectMapper;
      • 您可以尝试自己使用 Row 对象,也可以实现类似的转换,将 JSON 字符串转换为您的自定义 Java 类型而不是 Row;
      • this JsonToRow PTransform accepts a string with JSON object and converts it to a Beam Row using Jackson ObjectMapper;
      • you can either try using the Row object yourself, or you can implement a similar transform to convert JSON strings to your custom Java type instead of Row;

      您还可以查看 examples 文件夹在光束源中;

      you may also take a look at examples folder in Beam source;

      这篇关于json数据的Apache Beam流处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆