建立串流工作的狀態快照 (非同步)
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
示範如何非同步拍攝串流工作狀態的快照。
程式碼範例
Java
如要向 Dataflow 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Node.js
如要向 Dataflow 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
Python
如要向 Dataflow 進行驗證,請設定應用程式預設憑證。
詳情請參閱「為本機開發環境設定驗證」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page provides code examples demonstrating how to asynchronously snapshot the state of a streaming Dataflow job.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples are available in C#, Java, Node.js, and Python, showcasing the process of using the \u003ccode\u003eSnapshotJobAsync\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication to Dataflow requires setting up Application Default Credentials, and the provided link offers more information on this process.\u003c/p\u003e\n"],["\u003cp\u003eEach language code sample requires some manual adjustments with correct/in-range values to be functional.\u003c/p\u003e\n"],["\u003cp\u003eThe snapshot operation can be customized using parameters like project ID, job ID, time-to-live (TTL), location, snapshot sources, and description, as shown in the code.\u003c/p\u003e\n"]]],[],null,["# Snapshot the state of a streaming job (async)\n\nDemonstrates how to snapshot the state of a streaming job asynchronously.\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 using System.Threading.Tasks;\n\n public sealed partial class GeneratedJobsV1Beta3ClientSnippets\n {\n /// \u003csummary\u003eSnippet for SnapshotJobAsync\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 async Task SnapshotJobRequestObjectAsync()\n {\n // Create client\n https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.JobsV1Beta3Client.html jobsV1Beta3Client = await 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_CreateAsync_System_Threading_CancellationToken_();\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 = await jobsV1Beta3Client.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dataflow.V1Beta3/latest/Google.Cloud.Dataflow.V1Beta3.JobsV1Beta3Client.html#Google_Cloud_Dataflow_V1Beta3_JobsV1Beta3Client_SnapshotJobAsync_Google_Cloud_Dataflow_V1Beta3_SnapshotJobRequest_Google_Api_Gax_Grpc_CallSettings_(request);\n }\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.api.core.https://cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.ApiFuture.html;\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 AsyncSnapshotJob {\n\n public static void main(String[] args) throws Exception {\n asyncSnapshotJob();\n }\n\n public static void asyncSnapshotJob() 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.https://cloud.google.com/java/docs/reference/api-common/latest/com.google.api.core.SettableApiFuture.html#com_google_api_core_SettableApiFuture__V_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 ApiFuture\u003cSnapshot\u003e future = jobsV1Beta3Client.snapshotJobCallable().futureCall(request);\n // Do something.\n Snapshot response = future.get();\n }\n }\n }\n\n### Node.js\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 * 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 * TODO(developer): Uncomment these variables before running the sample.\n */\n /**\n * The project which owns the job to be snapshotted.\n */\n // const projectId = 'abc123'\n /**\n * The job to be snapshotted.\n */\n // const jobId = 'abc123'\n /**\n * TTL for the snapshot.\n */\n // const ttl = {}\n /**\n * The location that contains this job.\n */\n // const location = 'abc123'\n /**\n * If true, perform snapshots for sources which support this.\n */\n // const snapshotSources = true\n /**\n * User specified description of the snapshot. Maybe empty.\n */\n // const description = 'abc123'\n\n // Imports the Dataflow library\n const {JobsV1Beta3Client} = require('https://cloud.google.com/nodejs/docs/reference/dataflow/latest/overview.html').v1beta3;\n\n // Instantiates a client\n const dataflowClient = new https://cloud.google.com/nodejs/docs/reference/dataflow/latest/overview.html();\n\n async function callSnapshotJob() {\n // Construct request\n const request = {\n };\n\n // Run request\n const response = await dataflowClient.snapshotJob(request);\n console.log(response);\n }\n\n callSnapshotJob();\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 async 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.JobsV1Beta3AsyncClient.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 = await client.https://cloud.google.com/python/docs/reference/dataflow/latest/google.cloud.dataflow_v1beta3.services.jobs_v1_beta3.JobsV1Beta3AsyncClient.html#google_cloud_dataflow_v1beta3_services_jobs_v1_beta3_JobsV1Beta3AsyncClient_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)."]]