与 AWS SDK或RegisterStreamConsumer一起使用 CLI - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

与 AWS SDK或RegisterStreamConsumer一起使用 CLI

以下代码示例演示如何使用 RegisterStreamConsumer

.NET
AWS SDK for .NET
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

using System; using System.Threading.Tasks; using Amazon.Kinesis; using Amazon.Kinesis.Model; /// <summary> /// This example shows how to register a consumer to an Amazon Kinesis /// stream. /// </summary> public class RegisterConsumer { public static async Task Main() { IAmazonKinesis client = new AmazonKinesisClient(); string consumerName = "NEW_CONSUMER_NAME"; string streamARN = "arn:aws:kinesis:us-east-2:000000000000:stream/AmazonKinesisStream"; var consumer = await RegisterConsumerAsync(client, consumerName, streamARN); if (consumer is not null) { Console.WriteLine($"{consumer.ConsumerName}"); } } /// <summary> /// Registers the consumer to a Kinesis stream. /// </summary> /// <param name="client">The initialized Kinesis client object.</param> /// <param name="consumerName">A string representing the consumer.</param> /// <param name="streamARN">The ARN of the stream.</param> /// <returns>A Consumer object that contains information about the consumer.</returns> public static async Task<Consumer> RegisterConsumerAsync(IAmazonKinesis client, string consumerName, string streamARN) { var request = new RegisterStreamConsumerRequest { ConsumerName = consumerName, StreamARN = streamARN, }; var response = await client.RegisterStreamConsumerAsync(request); return response.Consumer; } }
CLI
AWS CLI

注册数据流使用者

以下register-stream-consumer示例使用指定的数据流注册了一个名为KinesisConsumerApplication的使用者。

aws kinesis register-stream-consumer \ --stream-arn arn:aws:kinesis:us-west-2:012345678912:stream/samplestream \ --consumer-name KinesisConsumerApplication

输出:

{ "Consumer": { "ConsumerName": "KinesisConsumerApplication", "ConsumerARN": "arn:aws:kinesis:us-west-2: 123456789012:stream/samplestream/consumer/KinesisConsumerApplication:1572383852", "ConsumerStatus": "CREATING", "ConsumerCreationTimestamp": 1572383852.0 } }

有关更多信息,请参阅亚马逊 Kinesis Data Streams 开发者指南API中的使用 Kinesis 数据流开发具有增强扇出功能的消费者

SAP ABAP
SDK对于 SAP ABAP
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

TRY. oo_result = lo_kns->registerstreamconsumer( " oo_result is returned for testing purposes. " iv_streamarn = iv_stream_arn iv_consumername = iv_consumer_name ). MESSAGE 'Stream consumer registered.' TYPE 'I'. CATCH /aws1/cx_knsinvalidargumentex . MESSAGE 'The specified argument was not valid.' TYPE 'E'. CATCH /aws1/cx_sgmresourcelimitexcd. MESSAGE 'You have reached the limit on the number of resources.' TYPE 'E'. CATCH /aws1/cx_sgmresourceinuse. MESSAGE 'Resource being accessed is in use.' TYPE 'E'. CATCH /aws1/cx_sgmresourcenotfound. MESSAGE 'Resource being accessed is not found.' TYPE 'E'. ENDTRY.