/// <summary> /// Creates a cursor. Cursors are used to consume a stream, starting from a specific point in the partition and going forward from there. /// You can create a cursor based on an offset, a time, the trim horizon, or the most recent message in the stream. As the oldest message /// inside the retention period boundary, using the trim horizon effectively lets you consume all messages in the stream. A cursor based /// on the most recent message allows consumption of only messages that are added to the stream after you create the cursor. Cursors expire /// five minutes after you receive them from the service. /// /// </summary> /// <param name="request">The request object containing the details to send. Required.</param> /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param> /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param> /// <returns>A response object containing details about the completed operation</returns> /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/streaming/CreateCursor.cs.html">here</a> to see an example of how to use CreateCursor API.</example> public async Task <CreateCursorResponse> CreateCursor(CreateCursorRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { logger.Trace("Called createCursor"); Uri uri = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/streams/{streamId}/cursors".Trim('/'))); HttpMethod method = new HttpMethod("POST"); HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request); requestMessage.Headers.Add("Accept", "application/json"); GenericRetrier retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration); HttpResponseMessage responseMessage; try { if (retryingClient != null) { responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false); } else { responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false); } this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage); return(Converter.FromHttpResponseMessage <CreateCursorResponse>(responseMessage)); } catch (Exception e) { logger.Error($"CreateCursor failed with error: {e.Message}"); throw; } }
private static async Task <string> GetCursorByPartition(StreamClient streamClient, string streamId, string partition) { logger.Info($"Creating a cursor for partition {partition}"); CreateCursorDetails createCursorDetails = new CreateCursorDetails { Partition = partition, Type = CreateCursorDetails.TypeEnum.TrimHorizon }; CreateCursorRequest createCursorRequest = new CreateCursorRequest { StreamId = streamId, CreateCursorDetails = createCursorDetails }; CreateCursorResponse createCursorResponse = await streamClient.CreateCursor(createCursorRequest); return(createCursorResponse.Cursor.Value); }
protected override void ProcessRecord() { base.ProcessRecord(); CreateCursorRequest request; try { request = new CreateCursorRequest { StreamId = StreamId, CreateCursorDetails = CreateCursorDetails, OpcRequestId = OpcRequestId }; response = client.CreateCursor(request).GetAwaiter().GetResult(); WriteOutput(response, response.Cursor); FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }