Beispiel #1
0
 protected override void ProcessRecord()
 {
     base.ProcessRecord();
     try
     {
         client?.Dispose();
         int timeout = GetPreferredTimeout();
         WriteDebug($"Cmdlet Timeout : {timeout} milliseconds.");
         client = new StreamAdminClient(AuthProvider, new Oci.Common.ClientConfiguration
         {
             RetryConfiguration = retryConfig,
             TimeoutMillis      = timeout,
             ClientUserAgent    = PSUserAgent
         });
         string region = GetPreferredRegion();
         if (region != null)
         {
             WriteDebug("Choosing Region:" + region);
             client.SetRegion(region);
         }
         if (Endpoint != null)
         {
             WriteDebug("Choosing Endpoint:" + Endpoint);
             client.SetEndpoint(Endpoint);
         }
     }
     catch (Exception ex)
     {
         TerminatingErrorDuringExecution(ex);
     }
 }
Beispiel #2
0
        private static async Task <Stream> GetStream(StreamAdminClient adminClient, string streamId)
        {
            GetStreamRequest getStreamRequest = new GetStreamRequest
            {
                StreamId = streamId
            };
            GetStreamResponse getStreamResponse = await adminClient.GetStream(getStreamRequest);

            return(getStreamResponse.Stream);
        }
        public static async Task MainNonRegionalClient()
        {
            logger.Info("Starting example");

            var    provider      = new ConfigFileAuthenticationDetailsProvider("DEFAULT");
            string compartmentId = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID");

            StreamAdminClient streamAdminClient = new StreamAdminClient(provider);
            StreamClient      streamClient      = new StreamClient(provider);
            string            streamId          = null;

            try
            {
                Stream stream = await GetOrCreateStream(streamAdminClient, compartmentId, STREAM_NAME, PARTITIONS);

                streamId = stream.Id;

                // Streams are assigned a specific endpoint url based on where they are provisioned.
                // Create a stream client using the provided message endpoint.
                streamClient.SetEndpoint(stream.MessagesEndpoint);

                // publish some messages to the stream
                await PublishExampleMessages(streamClient, streamId);

                // give the streaming service a second to propagate messages
                await Task.Delay(1000);

                // Use a cursor for getting messages
                // A cursor can be created at a given partition/offset.
                // This gives explicit offset management control to the consumer.
                logger.Info("Starting a simple message loop with a partition cursor");
                string partitionCursor = await GetCursorByPartition(streamClient, streamId, "0");
                await SimpleMessageLoop(streamClient, streamId, partitionCursor);
            }
            catch (Exception e)
            {
                logger.Error($"NonRegional client example failed: {e}");
            }
            finally
            {
                // Cleanup; remember to delete streams which are not in use.
                await DeleteStream(streamAdminClient, streamId);

                // Stream deletion is an asynchronous operation, give it some time to complete.
                GetStreamRequest getStreamRequest = new GetStreamRequest
                {
                    StreamId = streamId
                };
                streamAdminClient.Waiters.ForStream(getStreamRequest, Stream.LifecycleStateEnum.Deleted).Execute();

                streamAdminClient.Dispose();

                logger.Info("End example");
            }
        }
Beispiel #4
0
        private static async Task <Stream> CreateStream(StreamAdminClient client, string compartmentId, string streamName, int partitions)
        {
            logger.Info($"Creating stream {streamName} with {partitions} partitions");

            CreateStreamDetails createStreamDetails = new CreateStreamDetails
            {
                CompartmentId = compartmentId,
                Name          = streamName,
                Partitions    = partitions
            };
            CreateStreamRequest createStreamRequest = new CreateStreamRequest
            {
                CreateStreamDetails = createStreamDetails
            };
            CreateStreamResponse createStreamResponse = await client.CreateStream(createStreamRequest);

            return(createStreamResponse.Stream);
        }
Beispiel #5
0
        private static async Task DeleteStream(StreamAdminClient adminClient, String streamId)
        {
            logger.Info($"Deleting stream {streamId}");
            DeleteStreamRequest deleteStreamRequest = new DeleteStreamRequest
            {
                StreamId = streamId
            };
            await adminClient.DeleteStream(deleteStreamRequest);

            WaiterConfiguration waiterConfiguration = new WaiterConfiguration
            {
                MaxAttempts           = 20,
                GetNextDelayInSeconds = DelayStrategy.GetExponentialDelayInSeconds
            };
            GetStreamRequest getStreamRequest = new GetStreamRequest
            {
                StreamId = streamId
            };

            adminClient.Waiters.ForStream(getStreamRequest, waiterConfiguration, Stream.LifecycleStateEnum.Deleted).Execute();
        }
Beispiel #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);
        }