Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        private static void CreateStream()
        {
            CreateStreamRequest createStreamRequest = new CreateStreamRequest();

            createStreamRequest.StreamName = myStreamName;
            oClient.CreateStream(createStreamRequest);
        }
Exemple #2
0
        /// <summary>
        /// This method verifies your credentials, creates a Kinesis stream, waits for the stream
        /// to become active, then puts 10 records in it, and (optionally) deletes the stream.
        /// </summary>
        public static void Main(string[] args)
        {
            const string myStreamName = "myTestStream";
            const int    myStreamSize = 1;

            try
            {
                var createStreamRequest = new CreateStreamRequest();
                createStreamRequest.StreamName = myStreamName;
                createStreamRequest.ShardCount = myStreamSize;
                var createStreamReq = createStreamRequest;
                kinesisClient.CreateStream(createStreamReq);
                Console.Error.WriteLine("Created Stream : " + myStreamName);
            }
            catch (ResourceInUseException)
            {
                Console.Error.WriteLine("Producer is quitting without creating stream " + myStreamName +
                                        " to put records into as a stream of the same name already exists.");
                Environment.Exit(1);
            }

            WaitForStreamToBecomeAvailable(myStreamName);

            Console.Error.WriteLine("Putting records in stream : " + myStreamName);
            // Write 10 UTF-8 encoded records to the stream.
            for (int j = 0; j < 10; ++j)
            {
                PutRecordRequest requestRecord = new PutRecordRequest();
                requestRecord.StreamName   = myStreamName;
                requestRecord.Data         = new MemoryStream(Encoding.UTF8.GetBytes("testData-" + j));
                requestRecord.PartitionKey = "partitionKey-" + j;
                PutRecordResult putResult = kinesisClient.PutRecord(requestRecord);
                Console.Error.WriteLine(
                    String.Format("Successfully putrecord {0}:\n\t partition key = {1,15}, shard ID = {2}",
                                  j, requestRecord.PartitionKey, putResult.ShardId));
            }

            // Uncomment the following if you wish to delete the stream here.
            //Console.Error.WriteLine("Deleting stream : " + myStreamName);
            //DeleteStreamRequest deleteStreamReq = new DeleteStreamRequest();
            //deleteStreamReq.StreamName = myStreamName;
            //try
            //{
            //    kinesisClient.DeleteStream(deleteStreamReq);
            //    Console.Error.WriteLine("Stream is now being deleted : " + myStreamName);
            //}
            //catch (ResourceNotFoundException ex)
            //
            //    Console.Error.WriteLine("Stream could not be found; " + ex);
            //}
            //catch (AmazonClientException ex)
            //{
            //    Console.Error.WriteLine("Error deleting stream; " + ex);
            //}
        }
Exemple #3
0
        public static string CreateDataStream(string streamName)
        {
            string streamArn = "";

            try
            {
                List <string> streamlList = GetDataStreamList();

                if (streamlList != null)
                {
                    if (streamlList.FindAll(dataStreamName => dataStreamName == streamName).Count > 0)
                    {
                        streamArn = "contain";
                    }
                    else
                    {
                        AmazonKinesisClient kinesisClient;

                        using (kinesisClient = new AmazonKinesisClient(Models.MyAWSConfigs.KinesisRegion))
                        {
                            CreateStreamRequest createStreamRequest = new CreateStreamRequest()
                            {
                                StreamName = streamName,
                                ShardCount = 1,
                            };

                            CreateStreamResponse createStreamResponse = kinesisClient.CreateStream(createStreamRequest);

                            if (createStreamResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
                            {
                                StreamDescriptionSummary streamSummary = DescribeDataStream(streamName);
                                if (streamSummary != null)
                                {
                                    streamArn = streamSummary.StreamARN;

                                    while (streamSummary.StreamStatus != StreamStatus.ACTIVE ||
                                           streamSummary.StreamStatus == StreamStatus.CREATING)
                                    {
                                        Thread.Sleep(1 * 1000);
                                        streamSummary = DescribeDataStream(streamName);
                                        if (streamSummary == null)
                                        {
                                            streamArn = "";
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("Error creating kinesis data stream");
                            }
                        }
                    }
                }
            }
            catch (AmazonKinesisException e)
            {
                Console.WriteLine("AmazonKinesisException: " + e);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e);
            }

            return(streamArn);
        }