Advertisement
pjotrekk

pubsub_dataflow_simple

Mar 31st, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. from __future__ import absolute_import
  2.  
  3. import logging
  4.  
  5. import apache_beam as beam
  6. from apache_beam.options.pipeline_options import PipelineOptions, GoogleCloudOptions, SetupOptions
  7. from apache_beam.options.pipeline_options import StandardOptions
  8.  
  9. '''
  10. python -m apache_beam.testing.load_tests.dataflow_test
  11. '''
  12.  
  13. def run():
  14.   pipeline_options = PipelineOptions()
  15.   pipeline_options.view_as(StandardOptions).streaming = True
  16.   pipeline_options.view_as(SetupOptions).sdk_location = 'dist/apache-beam-2.21.0.dev0.tar.gz'
  17.   pipeline_options.view_as(GoogleCloudOptions).temp_location = 'gs://beam-test-pszuberski/tmp'
  18.   pipeline_options.view_as(GoogleCloudOptions).staging_location = 'gs://beam-test-pszuberski/staging'
  19.   pipeline_options.view_as(GoogleCloudOptions).project = 'apache-beam-io-testing'
  20.   pipeline_options.view_as(StandardOptions).runner = 'DataflowRunner'
  21.  
  22.   topic_name = 'projects/apache-beam-io-testing/topics/abc'
  23.   sub_name = 'projects/apache-beam-io-testing/subscriptions/abc_sub'
  24.  
  25.   with beam.Pipeline(options=pipeline_options) as p:
  26.     _ = p | beam.Create([b'simplified']).with_output_types(bytes) | beam.io.WriteToPubSub(topic_name)
  27.  
  28.  
  29. if __name__ == '__main__':
  30.   logging.getLogger().setLevel(logging.INFO)
  31.   run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement