小编Ben*_*min的帖子

如何从Dataflow批量(高效)发布到Pub/Sub?

由于批处理模式下的数据流作业,我想将消息发布到具有某些属性的 Pub/Sub 主题。

我的数据流管道是用 python 3.8 和 apache-beam 2.27.0 编写的

它与@Ankur解决方案一起使用:/sf/answers/3907700121/

但我认为使用共享的 Pub/Sub 客户端可能会更有效:/sf/answers/3908379821/

然而发生了错误:

return StockUnpickler.find_class(self, module, name) AttributeError: 无法从 '/usr/local/lib/python3.8/site-packages/dataflow_worker/start 获取 <module 'dataflow_worker.start' 上的属性 'PublishFn'。 py'>

问题:

  1. 共享发布器的实现会提高光束管道性能吗?
  2. 是否有其他方法可以避免我的共享发布者客户端上的酸洗错误?

我的数据流管道:

import apache_beam as beam
from apache_beam.io.gcp import bigquery
from apache_beam.options.pipeline_options import PipelineOptions
from apache_beam.options.pipeline_options import SetupOptions

from google.cloud.pubsub_v1 import PublisherClient

import json
import argparse
import re
import logging


class PubsubClient(PublisherClient):
    def __reduce__(self):
        return self.__class__, (self.batch_settings,)


# The DoFn to perform on each element in the input …
Run Code Online (Sandbox Code Playgroud)

python-3.x google-cloud-platform google-cloud-pubsub google-cloud-dataflow apache-beam

6
推荐指数
1
解决办法
3138
查看次数