Google云端平台:Pub / Sub到Bigtable

时间:2017-08-23 05:26:55

标签: python google-cloud-platform google-cloud-dataflow google-cloud-pubsub google-cloud-bigtable

我正在使用Python在Google Cloud Platform上构建管道。我在Cloud Pub / Sub中有我的数据。我想使用Dataflow将它存储到Bigtable中。到目前为止,我有一些从Pub / Sub到Bigtable的数据流传输示例。

有人可以帮我提供一些资源或链接,了解如何使用Python中的Dataflow将数据从Pub / Sub流式传输到Bigtable吗?

1 个答案:

答案 0 :(得分:4)

萨姆 我不确定我们是如何在Python中执行此操作的。但我用Java做过这个。希望这个想法可以帮助您解决问题。

执行此操作时应牢记的步骤

  1. 从Pub / Sub读取,将流设置为true

    PubsubIO.readStrings().fromTopic(PUBSUB_SUBSCRIPTION))
    
  2. 使用常量键

    对集合进行分组
    PCollection<KV<String, String>> keyedStream = streamData
            .apply(WithKeys.of(new SerializableFunction<String, String>() {
                /**
                 * serial version id
                 */
                private static final long serialVersionUID = 1L;
    
                public String apply(String s) {
                    return CONSTANT_KEY;
                }
            }));
    
  3. 创建一个变换,用于将PCollection中的元素划分为窗口,并在输出这些元素时触发控件。

    Window.<String>into(new GlobalWindows())
            .triggering(Repeatedly
                    .forever(AfterProcessingTime
                            .pastFirstElementInPane()
                            .plusDelayOf(Duration.standardSeconds(30))
                        )).withAllowedLateness(Duration.standardDays(1)).discardingFiredPanes()
    
  4. PCollection写入Bigtable。