开始使用基本的 Kinesis 数据流操作 AWS SDK - AWS SDK 代码示例

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

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

开始使用基本的 Kinesis 数据流操作 AWS SDK

以下代码示例展示了如何:

  • 创建流并在其中放置一条记录。

  • 创建分片迭代器。

  • 读取记录,然后清理函数。

SAP ABAP
SDK对于 SAP ABAP
注意

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

DATA lo_stream_describe_result TYPE REF TO /aws1/cl_knsdescrstreamoutput. DATA lo_stream_description TYPE REF TO /aws1/cl_knsstreamdescription. DATA lo_sharditerator TYPE REF TO /aws1/cl_knsgetsharditerator01. DATA lo_record_result TYPE REF TO /aws1/cl_knsputrecordoutput. "Create stream." TRY. lo_kns->createstream( iv_streamname = iv_stream_name iv_shardcount = iv_shard_count ). MESSAGE 'Stream created.' TYPE 'I'. CATCH /aws1/cx_knsinvalidargumentex. MESSAGE 'The specified argument was not valid.' TYPE 'E'. CATCH /aws1/cx_knslimitexceededex . MESSAGE 'The request processing has failed because of a limit exceeded exception.' TYPE 'E'. CATCH /aws1/cx_knsresourceinuseex . MESSAGE 'The request processing has failed because the resource is in use.' TYPE 'E'. ENDTRY. "Wait for stream to becomes active." lo_stream_describe_result = lo_kns->describestream( iv_streamname = iv_stream_name ). lo_stream_description = lo_stream_describe_result->get_streamdescription( ). WHILE lo_stream_description->get_streamstatus( ) <> 'ACTIVE'. IF sy-index = 30. EXIT. "maximum 5 minutes" ENDIF. WAIT UP TO 10 SECONDS. lo_stream_describe_result = lo_kns->describestream( iv_streamname = iv_stream_name ). lo_stream_description = lo_stream_describe_result->get_streamdescription( ). ENDWHILE. "Create record." TRY. lo_record_result = lo_kns->putrecord( iv_streamname = iv_stream_name iv_data = iv_data iv_partitionkey = iv_partition_key ). MESSAGE 'Record created.' TYPE 'I'. CATCH /aws1/cx_knsinvalidargumentex . MESSAGE 'The specified argument was not valid.' TYPE 'E'. CATCH /aws1/cx_knskmsaccessdeniedex . MESSAGE 'You do not have permission to perform this AWS KMS action.' TYPE 'E'. CATCH /aws1/cx_knskmsdisabledex . MESSAGE 'KMS key used is disabled.' TYPE 'E'. CATCH /aws1/cx_knskmsinvalidstateex . MESSAGE 'KMS key used is in an invalid state. ' TYPE 'E'. CATCH /aws1/cx_knskmsnotfoundex . MESSAGE 'KMS key used is not found.' TYPE 'E'. CATCH /aws1/cx_knskmsoptinrequired . MESSAGE 'KMS key option is required.' TYPE 'E'. CATCH /aws1/cx_knskmsthrottlingex . MESSAGE 'The rate of requests to AWS KMS is exceeding the request quotas.' TYPE 'E'. CATCH /aws1/cx_knsprovthruputexcdex . MESSAGE 'The request rate for the stream is too high, or the requested data is too large for the available throughput.' TYPE 'E'. CATCH /aws1/cx_knsresourcenotfoundex . MESSAGE 'Resource being accessed is not found.' TYPE 'E'. ENDTRY. "Create a shard iterator in order to read the record." TRY. lo_sharditerator = lo_kns->getsharditerator( iv_shardid = lo_record_result->get_shardid( ) iv_sharditeratortype = iv_sharditeratortype iv_streamname = iv_stream_name ). MESSAGE 'Shard iterator created.' TYPE 'I'. CATCH /aws1/cx_knsinvalidargumentex. MESSAGE 'The specified argument was not valid.' TYPE 'E'. CATCH /aws1/cx_knsprovthruputexcdex . MESSAGE 'The request rate for the stream is too high, or the requested data is too large for the available throughput.' TYPE 'E'. CATCH /aws1/cx_sgmresourcenotfound. MESSAGE 'Resource being accessed is not found.' TYPE 'E'. ENDTRY. "Read the record." TRY. oo_result = lo_kns->getrecords( " oo_result is returned for testing purposes. " iv_sharditerator = lo_sharditerator->get_sharditerator( ) ). MESSAGE 'Shard iterator created.' TYPE 'I'. CATCH /aws1/cx_knsexpirediteratorex . MESSAGE 'Iterator expired.' TYPE 'E'. CATCH /aws1/cx_knsinvalidargumentex . MESSAGE 'The specified argument was not valid.' TYPE 'E'. CATCH /aws1/cx_knskmsaccessdeniedex . MESSAGE 'You do not have permission to perform this AWS KMS action.' TYPE 'E'. CATCH /aws1/cx_knskmsdisabledex . MESSAGE 'KMS key used is disabled.' TYPE 'E'. CATCH /aws1/cx_knskmsinvalidstateex . MESSAGE 'KMS key used is in an invalid state. ' TYPE 'E'. CATCH /aws1/cx_knskmsnotfoundex . MESSAGE 'KMS key used is not found.' TYPE 'E'. CATCH /aws1/cx_knskmsoptinrequired . MESSAGE 'KMS key option is required.' TYPE 'E'. CATCH /aws1/cx_knskmsthrottlingex . MESSAGE 'The rate of requests to AWS KMS is exceeding the request quotas.' TYPE 'E'. CATCH /aws1/cx_knsprovthruputexcdex . MESSAGE 'The request rate for the stream is too high, or the requested data is too large for the available throughput.' TYPE 'E'. CATCH /aws1/cx_knsresourcenotfoundex . MESSAGE 'Resource being accessed is not found.' TYPE 'E'. ENDTRY. "Delete stream." TRY. lo_kns->deletestream( iv_streamname = iv_stream_name ). MESSAGE 'Stream deleted.' TYPE 'I'. CATCH /aws1/cx_knslimitexceededex . MESSAGE 'The request processing has failed because of a limit exceeded exception.' TYPE 'E'. CATCH /aws1/cx_knsresourceinuseex . MESSAGE 'The request processing has failed because the resource is in use.' TYPE 'E'. ENDTRY.