示例#1
0
        private static async Task DisplayStreams()
        {
            Console.WriteLine("------- Streams ----------");
            var request = new ListStreamsRequest {
                Scope = ScopeName
            };

            using var call = _client.ListStreams(request);
            while (await call.ResponseStream.MoveNext())
            {
                var result = call.ResponseStream.Current;
                Console.WriteLine($"Scope: {result.Scope}, Stream: {result.Stream}");
            }
        }
示例#2
0
        internal ListStreamsResponse ListStreams(ListStreamsRequest request)
        {
            var task = ListStreamsAsync(request);

            try
            {
                return(task.Result);
            }
            catch (AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return(null);
            }
        }
 /// <summary>
 /// Creates a new enumerable which will iterate over the responses received from the ListStreams operation. This enumerable
 /// will fetch more data from the server as needed.
 /// </summary>
 /// <param name="request">The request object containing the details to send</param>
 /// <param name="retryConfiguration">The configuration for retrying, may be null</param>
 /// <param name="cancellationToken">The cancellation token object</param>
 /// <returns>The enumerator, which supports a simple iteration over a collection of a specified type</returns>
 public IEnumerable <ListStreamsResponse> ListStreamsResponseEnumerator(ListStreamsRequest request, Common.Retry.RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default)
 {
     return(new Common.Utils.ResponseEnumerable <ListStreamsRequest, ListStreamsResponse>(
                response => response.OpcNextPage,
                input =>
     {
         if (!string.IsNullOrEmpty(input))
         {
             request.Page = input;
         }
         return request;
     },
                request => client.ListStreams(request, retryConfiguration, cancellationToken)
                ));
 }
        /// <summary>
        /// Initiates the asynchronous execution of the ListStreams operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the ListStreams operation on AmazonKinesisClient.</param>
        /// <param name="callback">An Action delegate that is invoked when the operation completes.</param>
        /// <param name="options">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        public void ListStreamsAsync(ListStreamsRequest request, AmazonServiceCallback <ListStreamsRequest, ListStreamsResponse> callback, AsyncOptions options = null)
        {
            options = options == null?new AsyncOptions():options;
            var marshaller   = new ListStreamsRequestMarshaller();
            var unmarshaller = ListStreamsResponseUnmarshaller.Instance;
            Action <AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;

            if (callback != null)
            {
                callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => {
                    AmazonServiceResult <ListStreamsRequest, ListStreamsResponse> responseObject
                        = new AmazonServiceResult <ListStreamsRequest, ListStreamsResponse>((ListStreamsRequest)req, (ListStreamsResponse)res, ex, ao.State);
                    callback(responseObject);
                }
            }
            ;
            BeginInvoke <ListStreamsRequest>(request, marshaller, unmarshaller, options, callbackHelper);
        }
示例#5
0
        public static async Task AddEventSourceAsync()
        {
            #region add_dynamodb_event_source
            using (var streamClient = new AmazonDynamoDBStreamsClient())
                using (var lambdaClient = new AmazonLambdaClient())
                {
                    // TODO: Enter Lambda function name, this is most likely: ServerlessTODOListStreamProcessor
                    var functionName = "";
                    if (string.IsNullOrEmpty(functionName))
                    {
                        Console.Error.WriteLine("You must set the name of the Lambda function you deployed to the \"functionName\" variable");
                        return;
                    }

                    var listRequest = new ListStreamsRequest
                    {
                        TableName = "TODOList"
                    };

                    var listResponse = await streamClient.ListStreamsAsync(listRequest);

                    if (listResponse.Streams.Count == 0)
                    {
                        Console.Error.WriteLine($"A stream is not enabled for the table {listRequest.TableName}");
                        return;
                    }

                    var streamArn = listResponse.Streams[0].StreamArn;
                    Console.WriteLine($"Stream ARN is {streamArn}");

                    var request = new CreateEventSourceMappingRequest
                    {
                        FunctionName     = functionName,
                        EventSourceArn   = streamArn,
                        StartingPosition = EventSourcePosition.LATEST,
                        BatchSize        = 100
                    };

                    await lambdaClient.CreateEventSourceMappingAsync(request);

                    Console.WriteLine($"Event source mapping made between stream {streamArn} and function {functionName}");
                }
            #endregion
        }
示例#6
0
        private static async Task <Stream> GetOrCreateStream(StreamAdminClient client, string compartmentId, string streamName, int partitions)
        {
            ListStreamsRequest listRequest = new ListStreamsRequest
            {
                CompartmentId  = compartmentId,
                LifecycleState = Stream.LifecycleStateEnum.Active,
                Name           = streamName
            };
            ListStreamsResponse listStreamsResponse = await client.ListStreams(listRequest);

            if (listStreamsResponse.Items.Count != 0)
            {
                // if we find an active stream with the correct name, we'll use it.
                logger.Info($"An active stream named {streamName} was found");

                string streamId = listStreamsResponse.Items[0].Id;
                return(await GetStream(client, streamId));
            }

            logger.Info($"No active stream named {streamName} was found; creating it now");
            Stream createdStream = await CreateStream(client, compartmentId, streamName, partitions);

            // GetStream provides details about a specific stream.
            // Since stream creation is asynchronous; we need to wait for the stream to become active.
            WaiterConfiguration waiterConfiguration = new WaiterConfiguration
            {
                MaxAttempts           = 20,
                GetNextDelayInSeconds = DelayStrategy.GetExponentialDelayInSeconds
            };
            GetStreamRequest streamRequest = new GetStreamRequest
            {
                StreamId = createdStream.Id
            };
            Stream activeStream = client.Waiters.ForStream(streamRequest, waiterConfiguration, Stream.LifecycleStateEnum.Active).Execute().Stream;

            // Give a little time for the stream to be ready.
            await Task.Delay(1000);

            return(activeStream);
        }
示例#7
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListStreamsRequest request;

            try
            {
                request = new ListStreamsRequest
                {
                    CompartmentId  = CompartmentId,
                    StreamPoolId   = StreamPoolId,
                    Id             = Id,
                    Name           = Name,
                    Limit          = Limit,
                    Page           = Page,
                    SortBy         = SortBy,
                    SortOrder      = SortOrder,
                    LifecycleState = LifecycleState,
                    OpcRequestId   = OpcRequestId
                };
                IEnumerable <ListStreamsResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.Items, true);
                }
                if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null)
                {
                    WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources.");
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
示例#8
0
 /// <summary>
 /// This operation returns an array of the names of all the streams that are associated with the AWS account
 /// making the ListStreams request.
 ///
 /// More info: http://docs.aws.amazon.com/kinesis/latest/APIReference/API_ListStreams.html
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public ListStreamsResponse ListStreams(ListStreamsRequest request)
 {
     return(Invoke <ListStreamsResponse>(request, "ListStreams"));
 }
 public void ListStreamsAsync(ListStreamsRequest request, AmazonServiceCallback <ListStreamsRequest, ListStreamsResponse> callback, AsyncOptions options = null)
 {
     throw new System.NotImplementedException();
 }