寫入SDK用戶端 - Amazon Timestream

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

寫入SDK用戶端

您可以使用下列程式碼片段為寫入 建立 Timestream 用戶端SDK。寫入SDK用於執行CRUD操作,並將時間序列資料插入 Timestream。

注意

這些程式碼片段是以 上的完整範例應用程式為基礎GitHub。如需如何開始使用範例應用程式的詳細資訊,請參閱 範例應用程式

Java
private static AmazonTimestreamWrite buildWriteClient() { final ClientConfiguration clientConfiguration = new ClientConfiguration() .withMaxConnections(5000) .withRequestTimeout(20 * 1000) .withMaxErrorRetry(10); return AmazonTimestreamWriteClientBuilder .standard() .withRegion("us-east-1") .withClientConfiguration(clientConfiguration) .build(); }
Java v2
private static TimestreamWriteClient buildWriteClient() { ApacheHttpClient.Builder httpClientBuilder = ApacheHttpClient.builder(); httpClientBuilder.maxConnections(5000); RetryPolicy.Builder retryPolicy = RetryPolicy.builder(); retryPolicy.numRetries(10); ClientOverrideConfiguration.Builder overrideConfig = ClientOverrideConfiguration.builder(); overrideConfig.apiCallAttemptTimeout(Duration.ofSeconds(20)); overrideConfig.retryPolicy(retryPolicy.build()); return TimestreamWriteClient.builder() .httpClientBuilder(httpClientBuilder) .overrideConfiguration(overrideConfig.build()) .region(Region.US_EAST_1) .build(); }
Go
tr := &http.Transport{ ResponseHeaderTimeout: 20 * time.Second, // Using DefaultTransport values for other parameters: https://golang.org/pkg/net/http/#RoundTripper Proxy: http.ProxyFromEnvironment, DialContext: (&net.Dialer{ KeepAlive: 30 * time.Second, DualStack: true, Timeout: 30 * time.Second, }).DialContext, MaxIdleConns: 100, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, } // So client makes HTTP/2 requests http2.ConfigureTransport(tr) sess, err := session.NewSession(&aws.Config{ Region: aws.String("us-east-1"), MaxRetries: aws.Int(10), HTTPClient: &http.Client{ Transport: tr }}) writeSvc := timestreamwrite.New(sess)
Python
write_client = session.client('timestream-write', config=Config(read_timeout=20, max_pool_connections = 5000, retries={'max_attempts': 10})) 
Node.js

下列程式碼片段AWSSDK用於 JavaScript v3。如需如何安裝用戶端和用量的詳細資訊,請參閱 Timestream Write Client - AWS SDK for JavaScript v3

此處顯示額外的命令匯入。建立用戶端不需要CreateDatabaseCommand匯入。

import { TimestreamWriteClient, CreateDatabaseCommand } from "@aws-sdk/client-timestream-write"; const writeClient = new TimestreamWriteClient({ region: "us-east-1" });

下列程式碼片段使用 AWS SDK適用於 JavaScript V2 樣式的 。它以 Node.js 範例應用程式為基礎,適用於 上的 LiveAnalytics 應用程式 GitHub

var https = require('https'); var agent = new https.Agent({ maxSockets: 5000 }); writeClient = new AWS.TimestreamWrite({ maxRetries: 10, httpOptions: { timeout: 20000, agent: agent } });
.NET
var writeClientConfig = new AmazonTimestreamWriteConfig { RegionEndpoint = RegionEndpoint.USEast1, Timeout = TimeSpan.FromSeconds(20), MaxErrorRetry = 10 }; var writeClient = new AmazonTimestreamWriteClient(writeClientConfig);

我們建議您使用下列組態。

  • 將SDK重試計數設定為 10

  • 請使用 SDK DEFAULT_BACKOFF_STRATEGY

  • RequestTimeout 設定為 20 秒。

  • 將最大連線設定為 5000 或更高。