Punkty kontrolne
Disable and re-enable the Dataflow API
/ 25
Create Project Resources
/ 25
Start the cloud scheduler job
/ 25
Start the pipeline and launch dataflow job
/ 25
Stream Processing with Cloud Pub/Sub and Dataflow: Qwik Start
GSP903
Overview
Google Cloud Pub/Sub is a messaging service for exchanging event data among applications and services. A producer of data publishes messages to a Cloud Pub/Sub topic. A consumer creates a subscription to that topic. Subscribers either pull messages from a subscription or are configured as webhooks for push subscriptions. Every subscriber must acknowledge each message within a configurable window of time.
Dataflow is a fully-managed service for transforming and enriching data in stream (real-time) and batch modes with equal reliability and expressiveness. It provides a simplified pipeline development environment using the Apache Beam SDK, which has a rich set of windowing and session analysis primitives as well as an ecosystem of source and sink connectors.
Pub/Sub is a scalable, durable event ingestion and delivery system. Dataflow compliments Pub/Sub's scalable, at-least-once delivery model with message deduplication and exactly-once, in-order processing if you use windows and buffering.
What you'll do
- Read messages published to a Pub/Sub topic
- Window (or group) the messages by timestamp
- Write the messages to Cloud Storage
Setup
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud console
-
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
- The Open Google Cloud console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username below and paste it into the Sign in dialog.
{{{user_0.username | "Username"}}} You can also find the Username in the Lab Details panel.
-
Click Next.
-
Copy the Password below and paste it into the Welcome dialog.
{{{user_0.password | "Password"}}} You can also find the Password in the Lab Details panel.
-
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Google Cloud console opens in this tab.
Activate Cloud Shell
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
- Click Activate Cloud Shell at the top of the Google Cloud console.
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
- (Optional) You can list the active account name with this command:
- Click Authorize.
Output:
- (Optional) You can list the project ID with this command:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Set the region
- In Cloud Shell, run the following command to set the project region for this lab:
Ensure that the Dataflow API is successfully enabled
To ensure access to the necessary API, restart the connection to the Dataflow API.
-
In the Cloud Console, enter "Dataflow API" in the top search bar. Click on the result for Dataflow API.
-
Click Manage.
-
Click Disable API.
If asked to confirm, click Disable.
- Click Enable.
When the API has been enabled again, the page will show the option to disable.
Click Check my progress to verify the objective.
Task 1. Create project resources
- In Cloud Shell, create variables for your bucket, project, and region.
- Set your App Engine region.
us-central1
and europe-west1
, set the AppEngine region variable to be the same as the assigned region. If you are assigned us-central1
, set the AppEngine region variable to us-central
. If you are assigned europe-west1
, set the AppEngine region variable to europe-west
.You can refer to the App Engine locations for more information.
- Create a Cloud Storage bucket owned by this project:
- Create a Pub/Sub topic in this project:
- Create an App Engine app for your project:
- Create a Cloud Scheduler job in this project. The job publishes a message to a Pub/Sub topic at one-minute intervals:
- If prompted to enable the Cloud Scheduler API, press
y
and enter.
Click Check my progress to verify the objective.
- Start the job:
RESOURCE_EXHAUSTED
, attempt to execute the command again.
- Use the following commands to clone the quickstart repository and navigate to the sample code directory:
Click Check my progress to verify the objective.
Task 2. Review code to stream messages from Pub/Sub to Cloud Storage
Code sample
Review the following sample code, which uses Dataflow to:
- Read Pub/Sub messages.
- Window (or group) messages into fixed-size intervals by publish timestamps.
- Write the messages in each window to files in Cloud Storage.
Task 3. Start the pipeline
- To start the pipeline, run the following command:
project_id
, bucket_name
, and region
with your project id, bucket name, and assigned lab region.The preceding command runs locally and launches a Dataflow job that runs in the cloud.
StaticLoggerBinder
, you can safely ignore it and move ahead in the lab.Click Check my progress to verify the objective.
Task 4. Observe job and pipeline progress
-
Go to Dataflow console to observe the job's progress.
-
Click Refresh to see the job and the latest status updates.
- Click on the job name to open the job details and review the following:
- Job structure
- Job logs
- Stage metrics
You may have to wait a few more minutes to see the output files in Cloud Storage.
- You can see the output files by navigating to Navigation menu > Cloud Storage, and clicking on your bucket name and then clicking Samples.
- Alternately, you can exit the application in Cloud Shell using CTRL+C (and for the Python option, type
exit
), and then execute the command below to list the files that have been written out to Cloud Storage:
The output should look like the following:
Task 5. Cleanup
- If you have not already, exit the application in Cloud Shell using CTRL+C.
For the Python option, type exit
to exit the Python environment.
- In Cloud Shell, delete the Cloud Scheduler job:
If prompted "Do you want to continue", press Y
and enter.
- In the Dataflow console, stop the job by selecting your job name, and clicking Stop.
When prompted, click Stop Job > Cancel to cancel the pipeline without draining.
- In Cloud Shell, delete the topic:
- In Cloud Shell, delete the files created by the pipeline:
- In Cloud Shell, delete the Cloud Storage bucket:
Congratulations!
You created a Dataflow pipeline which read messages from your Pub/Sub topic, windowed them by timestamp, and wrote them to your cloud storage bucket.
Next step / Learn more
- If you would like to window Pub/Sub messages by a custom timestamp, you can specify the timestamp as an attribute in the Pub/Sub message, and then use the custom timestamp with PubsubIO's withTimestampAttribute.
- Learn about the Beam programming model used to write streaming and batch Dataflow jobs
- Check out these example Beam pipelines for streaming data into BigQuery: Java, Python.
- Take a look at Google's open-source Dataflow templates designed for streaming.
Google Cloud training and certification
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated September 02, 2024
Lab Last Tested September 02, 2024
Copyright 2024 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.