forked from docs/doc-exports
Reviewed-by: Kacur, Michal <michal.kacur@t-systems.com> Co-authored-by: Xiong, Chen Xiao <chenxiaoxiong@huawei.com> Co-committed-by: Xiong, Chen Xiao <chenxiaoxiong@huawei.com>
60 lines
9.0 KiB
HTML
60 lines
9.0 KiB
HTML
<a name="dis_02_0003"></a><a name="dis_02_0003"></a>
|
|
|
|
<h1 class="topictitle1">Application Example</h1>
|
|
<div id="body1493371267863"><div class="section" id="dis_02_0003__section4237340205619"><h4 class="sectiontitle">Scenarios</h4><p id="dis_02_0003__p622561555310">DIS provides efficient collection, transmission, and distribution capabilities for real-time data and provides a variety of APIs to help you quickly build real-time data applications.</p>
|
|
<div class="p" id="dis_02_0003__p1669275285219">The following describes how to create a DIS stream by calling the <a href="dis_02_0511.html">Before You Start</a> API. For details, see <a href="dis_02_0516.html">Calling APIs</a>.<div class="note" id="dis_02_0003__note78851219195410"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="dis_02_0003__p13885419115419">The token obtained on IAM is valid for only 24 hours. If you want to use one token for authentication, you can cache it to avoid frequent calling.</p>
|
|
</div></div>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="dis_02_0003__section101152312311"><h4 class="sectiontitle">Involved APIs</h4><p id="dis_02_0003__p208391848152419">If you use a token for authentication, you must obtain the token and add <strong id="dis_02_0003__b93839580536">X-Auth-Token</strong> to the request header of the API request.</p>
|
|
<ul id="dis_02_0003__ul18839104814240"><li id="dis_02_0003__li48397486241">API for obtaining a token from IAM</li><li id="dis_02_0003__li1583954822419">API for creating a DIS stream</li></ul>
|
|
</div>
|
|
<div class="section" id="dis_02_0003__section153811408573"><h4 class="sectiontitle">Prerequisites</h4><p id="dis_02_0003__p169218462419">You have planned the region where DIS is located and determined the endpoint for calling an API based on the region.</p>
|
|
<p id="dis_02_0003__p15283119165716">An endpoint is the <strong id="dis_02_0003__en-us_topic_0000001082451448_b16300195371816">request address</strong> for calling an API. Endpoints vary depending on services and regions. You can obtain endpoints of the service from <a href="https://docs.otc.t-systems.com/en-us/endpoint/index.html" target="_blank" rel="noopener noreferrer">Regions and Endpoints</a>.</p>
|
|
</div>
|
|
<div class="section" id="dis_02_0003__section84735913247"><h4 class="sectiontitle">Creating a Stream</h4><p id="dis_02_0003__p14816162615113">The following is an example of creating a stream with the simplest configuration.</p>
|
|
<ol id="dis_02_0003__ol17437102653012"><li id="dis_02_0003__li672483213012">Obtain the token by following the instructions in <a href="dis_02_0517.html#dis_02_0517__en-us_topic_0183235768_en-us_topic_0181281305_dis_02_0517_en-us_topic_0121671869_section2417768214391">Token-based Authentication</a>.</li><li id="dis_02_0003__li105531825183417">Send <strong id="dis_02_0003__b19876121263010">POST https://Endpoint of DIS/v2/{project_id}/streams</strong>.</li><li id="dis_02_0003__li207811546133015">Add <strong id="dis_02_0003__b71221716183020">X-Auth-Token</strong> to the request header.</li><li id="dis_02_0003__li17564135310303">Specify the following parameters in the request body:<pre class="screen" id="dis_02_0003__screen336756143714">{
|
|
"stream_name": "dis-DLpR",
|
|
"partition_count": 1,
|
|
"stream_type": "COMMON",
|
|
"data_duration": 24
|
|
}</pre>
|
|
<ul id="dis_02_0003__ul19791196017"><li id="dis_02_0003__li15791191700"><strong id="dis_02_0003__b02057187211">stream_name</strong> indicates the stream name, which can be customized, for example, <strong id="dis_02_0003__b11703171152111">newstream</strong>.</li><li id="dis_02_0003__li2792917014"><strong id="dis_02_0003__b4622123172119">partition_count</strong> indicates the number of partitions. A partition is the base throughput unit of a DIS stream. You can specify the number of partitions based on your service throughput requirements.</li><li id="dis_02_0003__li18791894017"><strong id="dis_02_0003__b19806716343">stream_type</strong> indicates the stream type. <strong id="dis_02_0003__b1357571813415">COMMON</strong> indicates a common partition. A single partition supports a maximum of 1 MB/s for data writing and a maximum of 2 MB/s for data reading.</li><li id="dis_02_0003__li16792096014"><strong id="dis_02_0003__b2821543194010">data_duration</strong> indicates the lifecycle of a stream, that is, the duration for storing data in the stream partition.</li></ul>
|
|
<p id="dis_02_0003__p143117175381">If the request is successful, 201 Created is returned.</p>
|
|
<p id="dis_02_0003__p199019514316">If the request fails, an error code and error information are returned. For details, see <a href="ErrorCode.html">Error Codes</a>.</p>
|
|
</li></ol>
|
|
</div>
|
|
<div class="section" id="dis_02_0003__section45378497019"><h4 class="sectiontitle">Creating a Stream That Supports Auto Scaling</h4><p id="dis_02_0003__p155381430213">You can also create a stream that supports auto scaling. The number of partitions can be automatically increased or decreased based on the stream traffic. The following is an example configuration:</p>
|
|
<ol id="dis_02_0003__ol15537124912020"><li id="dis_02_0003__li135377491300">Obtain the token by following the instructions provided in <a href="dis_02_0517.html#dis_02_0517__en-us_topic_0183235768_en-us_topic_0181281305_dis_02_0517_en-us_topic_0121671869_section2417768214391">Token-based Authentication</a>.</li><li id="dis_02_0003__li85372498017">Send <strong id="dis_02_0003__b1221952918">POST https://Endpoint of DIS/v2/{project_id}/streams</strong>.</li><li id="dis_02_0003__li3537114920016">Add <strong id="dis_02_0003__b86753726">X-Auth-Token</strong> to the request header.</li><li id="dis_02_0003__li153718493010">Specify the following parameters in the request body:<pre class="screen" id="dis_02_0003__screen553720495019">{
|
|
"stream_name": "dis-DLpR",
|
|
"partition_count": 1,
|
|
"stream_type": "COMMON",
|
|
"data_duration": 24
|
|
<strong id="dis_02_0003__b17295172481811">"auto_scale_enabled": true,</strong>
|
|
<strong id="dis_02_0003__b1029752431814">"auto_scale_min_partition_count": 2,</strong>
|
|
<strong id="dis_02_0003__b17298724141810">"auto_scale_max_partition_count": 10</strong>
|
|
}</pre>
|
|
<p id="dis_02_0003__p13057251210">In this example, a stream that supports auto scaling is created. The number of partitions to scale ranges from 2 to 10. If the stream has 10 partitions, auto scaling-out will not be triggered.</p>
|
|
<ul id="dis_02_0003__ul1830511253216"><li id="dis_02_0003__li7305112510216"><strong id="dis_02_0003__b1222391055817">auto_scale_enabled</strong> specifies whether to enable auto scaling. The value <strong id="dis_02_0003__b12448131920582">true</strong> indicates that auto scaling is enabled.</li><li id="dis_02_0003__li029103810214"><strong id="dis_02_0003__b15929339582">auto_scale_min_partition_count</strong> indicates the minimum number of partitions allowed when auto scale-in is enabled. In this example, as there are two partitions, automatic scale-in will not be triggered.</li><li id="dis_02_0003__li2305825722"><strong id="dis_02_0003__b176151291411">auto_scale_max_partition_count</strong> indicates the maximum number of partitions allowed when auto scale-out is enabled. In this example, as there are 10 partitions, automatic scale-out will not be triggered.</li></ul>
|
|
<p id="dis_02_0003__p1553810492011">If the request is successful, 201 Created is returned.</p>
|
|
<p id="dis_02_0003__p25386491108">If the request fails, an error code and error information are returned. For details, see <a href="ErrorCode.html">Error Codes</a>.</p>
|
|
</li></ol>
|
|
</div>
|
|
<div class="section" id="dis_02_0003__section126311019314"><h4 class="sectiontitle">Creating a Stream with Data Schemas</h4><p id="dis_02_0003__p1763201934">You can also configure a schema for the stream. When using DIS to dump data to other services, you can map data based on the schema configured for the stream. The following is an example configuration:</p>
|
|
<ol id="dis_02_0003__ol463809313"><li id="dis_02_0003__li163509316">Obtain the token by following the instructions provided in <a href="dis_02_0517.html#dis_02_0517__en-us_topic_0183235768_en-us_topic_0181281305_dis_02_0517_en-us_topic_0121671869_section2417768214391">Token-based Authentication</a>.</li><li id="dis_02_0003__li1631011319">Send <strong id="dis_02_0003__b1158478934">POST https://Endpoint of DIS/v2/{project_id}/streams</strong>.</li><li id="dis_02_0003__li166314014315">Add <strong id="dis_02_0003__b378052235">X-Auth-Token</strong> to the request header.</li><li id="dis_02_0003__li96313017318">Specify the following parameters in the request body:<pre class="screen" id="dis_02_0003__screen663501318">{
|
|
"stream_name": "dis-DLpR",
|
|
"partition_count": 1,
|
|
"stream_type": "COMMON",
|
|
"data_duration": 24
|
|
"auto_scale_enabled": true,
|
|
"auto_scale_min_partition_count": 1,
|
|
"auto_scale_max_partition_count": 10
|
|
<strong id="dis_02_0003__b12918159151914">"data_type": "BLOG",</strong>
|
|
}</pre>
|
|
<p id="dis_02_0003__p126320020316">If the request is successful, 201 Created is returned.</p>
|
|
<p id="dis_02_0003__p206314015310">If the request fails, an error code and error information are returned. For details, see <a href="ErrorCode.html">Error Codes</a>.</p>
|
|
</li></ol>
|
|
</div>
|
|
</div>
|
|
|