Snapshot the state of a streaming job
Stay organized with collections
Save and categorize content based on your preferences.
Demonstrates how to snapshot the state of a streaming job.
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page provides code examples demonstrating how to snapshot the state of a streaming Dataflow job in C#, Go, Java, and Python.\u003c/p\u003e\n"],["\u003cp\u003eThe examples use the \u003ccode\u003eSnapshotJob\u003c/code\u003e method to create a snapshot of a running job, capturing its current state.\u003c/p\u003e\n"],["\u003cp\u003eEach code sample outlines the necessary steps for creating a request object, including setting project ID, job ID, time to live, location, whether to snapshot sources, and a description.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication for the Dataflow API is required for each of the examples, and this can be achieved by setting up Application Default Credentials.\u003c/p\u003e\n"],["\u003cp\u003eThe documentation links to the Google cloud sample browser, where other code samples for other Google cloud products can be found.\u003c/p\u003e\n"]]],[],null,["# Snapshot the state of a streaming job\n\nDemonstrates how to snapshot the state of a streaming job.\n\nCode sample\n-----------\n\n### C#\n\n\nTo authenticate to Dataflow, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n using https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.html;\n using https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.html;\n\n public sealed partial class GeneratedJobsV1Beta3ClientSnippets\n {\n /// \u003csummary\u003eSnippet for SnapshotJob\u003c/summary\u003e\n /// \u003cremarks\u003e\n /// This snippet has been automatically generated and should be regarded as a code template only.\n /// It will require modifications to work:\n /// - It may require correct/in-range values for request initialization.\n /// - It may require specifying regional endpoints when creating the service client as shown in\n /// https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.\n /// \u003c/remarks\u003e\n public void SnapshotJobRequestObject()\n {\n // Create client\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.JobsV1Beta3Client.html jobsV1Beta3Client = https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.JobsV1Beta3Client.html.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.JobsV1Beta3Client.html#Google_Cloud_Dataflow_V1Beta3_JobsV1Beta3Client_Create();\n // Initialize request argument(s)\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.SnapshotJobRequest.html request = new https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.SnapshotJobRequest.html\n {\n ProjectId = \"\",\n JobId = \"\",\n Ttl = new https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Duration.html(),\n Location = \"\",\n SnapshotSources = false,\n Description = \"\",\n };\n // Make the request\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.Snapshot.html response = jobsV1Beta3Client.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.JobsV1Beta3Client.html#Google_Cloud_Dataflow_V1Beta3_JobsV1Beta3Client_SnapshotJob_Google_Cloud_Dataflow_V1Beta3_SnapshotJobRequest_Google_Api_Gax_Grpc_CallSettings_(request);\n }\n }\n\n### Go\n\n\nTo authenticate to Dataflow, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n package main\n\n import (\n \t\"context\"\n\n \tdataflow \"cloud.google.com/go/dataflow/apiv1beta3\"\n \tdataflowpb \"cloud.google.com/go/dataflow/apiv1beta3/dataflowpb\"\n )\n\n func main() {\n \tctx := context.Background()\n \t// This snippet has been automatically generated and should be regarded as a code template only.\n \t// It will require modifications to work:\n \t// - It may require correct/in-range values for request initialization.\n \t// - It may require specifying regional endpoints when creating the service client as shown in:\n \t// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options\n \tc, err := dataflow.NewJobsV1Beta3Client(ctx)\n \tif err != nil {\n \t\t// TODO: Handle error.\n \t}\n \tdefer c.Close()\n\n \treq := &dataflowpb.SnapshotJobRequest{\n \t\t// TODO: Fill request struct fields.\n \t\t// See https://pkg.go.dev/cloud.google.com/go/dataflow/apiv1beta3/dataflowpb#SnapshotJobRequest.\n \t}\n \tresp, err := c.SnapshotJob(ctx, req)\n \tif err != nil {\n \t\t// TODO: Handle error.\n \t}\n \t// TODO: Use resp.\n \t_ = resp\n }\n\n### Java\n\n\nTo authenticate to Dataflow, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import com.google.dataflow.v1beta3.JobsV1Beta3Client;\n import com.google.dataflow.v1beta3.Snapshot;\n import com.google.dataflow.v1beta3.SnapshotJobRequest;\n import com.google.protobuf.https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Duration.html;\n\n public class SyncSnapshotJob {\n\n public static void main(String[] args) throws Exception {\n syncSnapshotJob();\n }\n\n public static void syncSnapshotJob() throws Exception {\n // This snippet has been automatically generated and should be regarded as a code template only.\n // It will require modifications to work:\n // - It may require correct/in-range values for request initialization.\n // - It may require specifying regional endpoints when creating the service client as shown in\n // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library\n try (JobsV1Beta3Client jobsV1Beta3Client = JobsV1Beta3Client.create()) {\n SnapshotJobRequest request =\n SnapshotJobRequest.newBuilder()\n .setProjectId(\"projectId-894832108\")\n .setJobId(\"jobId101296568\")\n .setTtl(https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Duration.html.newBuilder().build())\n .setLocation(\"location1901043637\")\n .setSnapshotSources(true)\n .setDescription(\"description-1724546052\")\n .build();\n Snapshot response = jobsV1Beta3Client.snapshotJob(request);\n }\n }\n }\n\n### Python\n\n\nTo authenticate to Dataflow, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n # This snippet has been automatically generated and should be regarded as a\n # code template only.\n # It will require modifications to work:\n # - It may require correct/in-range values for request initialization.\n # - It may require specifying regional endpoints when creating the service\n # client as shown in:\n # https://googleapis.dev/python/google-api-core/latest/client_options.html\n from google.cloud import https://cloud.google.com/python/docs/reference/dataflow/latest/\n\n\n def sample_snapshot_job():\n # Create a client\n client = https://cloud.google.com/python/docs/reference/dataflow/latest/.https://cloud.google.com/python/docs/reference/dataflow/latest/google.cloud.dataflow_v1beta3.services.jobs_v1_beta3.JobsV1Beta3Client.html()\n\n # Initialize request argument(s)\n request = https://cloud.google.com/python/docs/reference/dataflow/latest/.https://cloud.google.com/python/docs/reference/dataflow/latest/google.cloud.dataflow_v1beta3.types.SnapshotJobRequest.html(\n )\n\n # Make the request\n response = client.https://cloud.google.com/python/docs/reference/dataflow/latest/google.cloud.dataflow_v1beta3.services.jobs_v1_beta3.JobsV1Beta3Client.html#google_cloud_dataflow_v1beta3_services_jobs_v1_beta3_JobsV1Beta3Client_snapshot_job(request=request)\n\n # Handle the response\n print(response)\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=dataflow)."]]