chamikaramj commented on code in PR #35151: URL: https://github.com/apache/beam/pull/35151#discussion_r2129410914
########## 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 Review Comment: nit: s/transform/transforms ########## 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 Review Comment: Probably change this sentence to. Please note that \`ReadFromKafka\` transform has a \[known issue\](https://github.com/apache/beam/issues/22809) when using non-Dataflow portable runners where reading may get stuck in streaming pipelines. Hence we recommend using the Dataflow runner for examples that involve reading from Kafka in a streaming pipeline. ########## sdks/python/apache_beam/yaml/examples/streaming_wordcount.yaml: ########## @@ -0,0 +1,97 @@ +# coding=utf-8 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +pipeline: + type: chain + transforms: + # Assuming the given topic exists with the following message JSON schema, + # read the records from Kafka + - type: ReadFromKafka + config: + format: JSON + schema: | + { + "type": "object", + "properties": { + "value": {"type": "string"} + } + } + topic: {{ TOPIC }} + bootstrap_servers: {{ BOOTSTRAP_SERVERS }} + auto_offset_reset_config: earliest + consumer_config: + sasl.jaas.config: "org.apache.kafka.common.security.plain.PlainLoginModule required \ + username={{ USERNAME }} \ + password={{ PASSWORD }};" + security.protocol: "SASL_PLAINTEXT" + sasl.mechanism: "PLAIN" + + # Split line field in each row into list of words. Review Comment: \`value\` field ########## 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 Review Comment: s/spanner DB/Google Spanner database ########## sdks/python/apache_beam/yaml/examples/transforms/io/kafka.yaml: ########## @@ -0,0 +1,87 @@ +# coding=utf-8 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# A non-linear pipeline that both writes to and reads from the same Kafka topic. + +pipeline: + transforms: + - type: ReadFromText + name: ReadFromGCS + config: + path: gs://dataflow-samples/shakespeare/kinglear.txt + + - type: MapToFields + name: BuildKafkaRecords + input: ReadFromGCS + config: + language: python + fields: + value: + callable: | + def func(row): + return row.line.encode('utf-8') + output_type: bytes + + - type: WriteToKafka + name: SendRecordsToKafka + input: BuildKafkaRecords + config: + format: RAW + topic: {{ TOPIC }} + bootstrap_servers: {{ BOOTSTRAP_SERVERS }} + producer_config_updates: + sasl.jaas.config: "org.apache.kafka.common.security.plain.PlainLoginModule required \ + username={{ USERNAME }} \ + password={{ PASSWORD }};" + security.protocol: "SASL_PLAINTEXT" + sasl.mechanism: "PLAIN" + + - type: ReadFromKafka + name: ReadFromMyTopic + config: + format: RAW + topic: {{ TOPIC }} + bootstrap_servers: {{ BOOTSTRAP_SERVERS }} + auto_offset_reset_config: earliest + consumer_config: + sasl.jaas.config: "org.apache.kafka.common.security.plain.PlainLoginModule required \ + username={{ USERNAME }} \ + password={{ PASSWORD }};" + security.protocol: "SASL_PLAINTEXT" + sasl.mechanism: "PLAIN" + + - type: MapToFields + name: ParseKafkaRecords + input: ReadFromMyTopic + config: + language: python + fields: + text: + callable: | + def func(row): + return row.payload.decode('utf-8') + + - type: LogForTesting + input: ParseKafkaRecords + +# Expected: +# Row(text="\tLook there, look there!") +# Row(text="\tNever, never, never, never, never!") Review Comment: Let's add instructions regarding pushing this data into the Iceberg table for testing. ########## sdks/python/apache_beam/yaml/examples/transforms/io/iceberg_write.yaml: ########## @@ -0,0 +1,45 @@ +# coding=utf-8 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +pipeline: + type: chain + transforms: + - type: Create + name: CreateSampleData + config: + elements: + - { id: 1, name: "John", email: "[email protected]", zip: "WA" } + - { id: 2, name: "Jane", email: "[email protected]", zip: "CA" } + - { id: 3, name: "Beamberg", email: "[email protected]", zip: "NY" } + + - type: LogForTesting + + - type: WriteToIceberg + name: WriteToAnIcebergTable + config: + # Dynamic destinations + table: "demo.users.{zip}" + catalog_name: "hadoop_catalog" + catalog_properties: + type: "hadoop" + warehouse: "gs://MY-WAREHOUSE" Review Comment: Let's clearly identify the things used have to set, may be in a comment at the top of the file (in here and other examples). ########## sdks/python/apache_beam/yaml/examples/streaming_wordcount.yaml: ########## @@ -0,0 +1,97 @@ +# coding=utf-8 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +pipeline: + type: chain + transforms: + # Assuming the given topic exists with the following message JSON schema, + # read the records from Kafka + - type: ReadFromKafka + config: + format: JSON + schema: | + { + "type": "object", + "properties": { + "value": {"type": "string"} + } + } + topic: {{ TOPIC }} + bootstrap_servers: {{ BOOTSTRAP_SERVERS }} + auto_offset_reset_config: earliest + consumer_config: + sasl.jaas.config: "org.apache.kafka.common.security.plain.PlainLoginModule required \ + username={{ USERNAME }} \ + password={{ PASSWORD }};" + security.protocol: "SASL_PLAINTEXT" + sasl.mechanism: "PLAIN" + + # Split line field in each row into list of words. + - type: MapToFields + config: + language: python + fields: + words: + callable: | + import re + def my_mapping(row): + return re.findall(r"[A-Za-z\']+", row.value.lower()) + + # Explode each list of words into separate rows. + - type: Explode + config: + fields: words + + # Since each word is now distinct row, rename field to "word". + - type: MapToFields + config: + fields: + word: words + + # With an unbounded source such as Kafka, a window is required for + # any subsequent GroupBy transform. + - type: WindowInto + name: Windowing + windowing: + type: fixed + size: 3s + + # Group by distinct words in the collection and add field "count" that + # contains number of instances, or count, for each word in the collection. + - type: Combine + config: + language: python + group_by: word + combine: + count: + value: word + fn: count + + - type: LogForTesting + +# Expected: +# Row(word='king', count=311) Review Comment: Should we also add instructions for pushing to data into the Kafka cluster ? Otherwise this example will be less useful. ########## sdks/python/apache_beam/yaml/examples/streaming_wordcount.yaml: ########## @@ -0,0 +1,97 @@ +# coding=utf-8 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +pipeline: + type: chain + transforms: + # Assuming the given topic exists with the following message JSON schema, + # read the records from Kafka + - type: ReadFromKafka + config: + format: JSON + schema: | + { + "type": "object", + "properties": { + "value": {"type": "string"} + } + } + topic: {{ TOPIC }} + bootstrap_servers: {{ BOOTSTRAP_SERVERS }} + auto_offset_reset_config: earliest + consumer_config: + sasl.jaas.config: "org.apache.kafka.common.security.plain.PlainLoginModule required \ + username={{ USERNAME }} \ + password={{ PASSWORD }};" + security.protocol: "SASL_PLAINTEXT" + sasl.mechanism: "PLAIN" + + # Split line field in each row into list of words. + - type: MapToFields + config: + language: python + fields: + words: + callable: | + import re + def my_mapping(row): + return re.findall(r"[A-Za-z\']+", row.value.lower()) + + # Explode each list of words into separate rows. + - type: Explode + config: + fields: words + + # Since each word is now distinct row, rename field to "word". + - type: MapToFields + config: + fields: + word: words + + # With an unbounded source such as Kafka, a window is required for + # any subsequent GroupBy transform. + - type: WindowInto + name: Windowing + windowing: + type: fixed + size: 3s Review Comment: Probably make this a bit larger. We use 15 seconds in other Kafka examples. ########## 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: Probably also put the IP to an environmental variable so that someone can quickly modify. ########## 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", + "TOPIC": "MY-TOPIC", "USERNAME": "USERNAME", "PASSWORD": "PASSWORD" }' +``` + +Beam pipeline [Kafka Read Write](transforms/io/kafka.yaml) is a non-linear Review Comment: Probably change is a non-linear pipeline that both writes to and reads from the same Kafka topic to first write data to the Kafka topic using the \`WriteToKafka\` transform and then reads that data back using the \`ReadFromKafka\` transform. ########## sdks/python/apache_beam/yaml/examples/transforms/io/iceberg_read.yaml: ########## @@ -0,0 +1,41 @@ +# coding=utf-8 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +pipeline: + type: chain + transforms: + - type: ReadFromIceberg + name: ReadFromAnIcebergTable + config: + table: "demo.users.NY" + catalog_name: "hadoop_catalog" + catalog_properties: + type: "hadoop" Review Comment: Also add instructions regarding creating the warehouse/table and pushing data into it ? ########## 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 \ Review Comment: Seems like this is run as a batch pipeline (without the --streaming) option ? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
