charlespnh commented on code in PR #35151: URL: https://github.com/apache/beam/pull/35151#discussion_r2132988057
########## sdks/python/apache_beam/yaml/examples/README.md: ########## @@ -71,25 +79,173 @@ Examples in this directory show off the various built-in transforms of the Beam YAML framework. ### Aggregation + These examples leverage the built-in `Combine` transform for performing simple aggregations including sum, mean, count, etc. ### Blueprints + These examples leverage DF or other existing templates and convert them to yaml blueprints. ### Element-wise + These examples leverage the built-in mapping transforms including `MapToFields`, `Filter` and `Explode`. More information can be found about mapping transforms [here](https://beam.apache.org/documentation/sdks/yaml-udf/). ### IO -These examples leverage the built-in `Spanner_Read` and `Spanner_Write` -transform for performing simple reads and writes from a spanner DB. + +#### Spanner + +Examples [Spanner Read](transforms/io/spanner_read.yaml) and [Spanner Write]( +transforms/io/spanner_write.yaml) leverage the built-in `Spanner_Read` and +`Spanner_Write` transform for performing simple reads and writes from a spanner +DB. + +#### Kafka + +Examples involving Kafka such as [Streaming Wordcount](streaming_wordcount.yaml) +and [Kafka Read Write](transforms/io/kafka.yaml) require users to set up +a Kafka cluster that Dataflow runner executing the +Beam pipeline has access to. See +issue [here](https://github.com/apache/beam/issues/22809) for context on running +streaming pipelines with Kafka on Dataflow runner vs. portable runners. + +See [here](https://kafka.apache.org/quickstart) for general instructions on +setting up a Kafka cluster. An option is to use [Click to Deploy]( +https://console.cloud.google.com/marketplace/details/click-to-deploy-images/kafka?) +to quickly launch a Kafka cluster on [GCE]( +https://cloud.google.com/products/compute?hl=en). [SASL/PLAIN]( +https://kafka.apache.org/documentation/#security_sasl_plain) authentication +mechanism is configured for the brokers as part of the deployment. See +also [here]( +https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/dataflow/flex-templates/kafka_to_bigquery) +for an alternative step-by-step guide on setting up Kafka on GCE without the +authentication mechanism. + +Let's assume one of the bootstrap servers is on VM instance `kafka-vm-0` +with the internal IP address `123.45.67.89` and port `9092` that the bootstrap +server is listening on. SASL/PLAIN `USERNAME` and `PASSWORD` can be viewed from +the VM instance's metadata on the GCE console, or with gcloud CLI: + +```sh +gcloud compute instances describe kafka-vm-0 \ + --format='value[](metadata.items.kafka-user)' +gcloud compute instances describe kafka-vm-0 \ + --format='value[](metadata.items.kafka-password)' +``` + +Beam pipeline [Streaming Wordcount](streaming_wordcount.yaml) reads from an +existing Kafka topic `MY-TOPIC` containing lines of text and then applies +transformation logic similar to [Wordcount](wordcount_minimal.yaml) example, +before finally logs out the output. Run the pipeline: + +```sh +export PROJECT="$(gcloud config get-value project)" +export TEMP_LOCATION="gs://MY-BUCKET/tmp" +export REGION="us-central1" +export JOB_NAME="streaming-wordcount-`date +%Y%m%d-%H%M%S`" +export NUM_WORKERS="1" + +python -m apache_beam.yaml.main \ + --yaml_pipeline_file streaming_wordcount.yaml \ + --runner DataflowRunner \ + --temp_location $TEMP_LOCATION \ + --project $PROJECT \ + --region $REGION \ + --num_workers $NUM_WORKERS \ + --job_name $JOB_NAME \ + --jinja_variables '{ "BOOTSTRAP_SERVERS": "123.45.67.89:9092", Review Comment: That'd be neat but AKAIK there's isn't a way to put in the env variables in the `--jinja_variables` flag. It expects JSON string so hardcoded value string is required. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@beam.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org