Пример #1
0
        /// <summary>
        /// Start asynchronously the <see cref="KafkaStream"/> instance by starting all its threads.
        /// This function is expected to be called only once during the life cycle of the client.
        /// Because threads are started in the background, this method does not block.
        /// </summary>
        /// <param name="token">Token for propagates notification that the stream should be canceled.</param>
        public async Task StartAsync(CancellationToken?token = null)
        {
            if (token.HasValue)
            {
                token.Value.Register(() => {
                    _cancelSource.Cancel();
                    Dispose();
                });
            }

            await Task.Factory.StartNew(() =>
            {
                if (SetState(State.REBALANCING))
                {
                    logger.Info($"{logPrefix}Starting Streams client with this topology : {topology.Describe()}");

                    if (globalStreamThread != null)
                    {
                        globalStreamThread.Start(_cancelSource.Token);
                    }

                    foreach (var t in threads)
                    {
                        t.Start(_cancelSource.Token);
                    }
                }
            }, token.HasValue?token.Value : _cancelSource.Token);
        }
Пример #2
0
        /// <summary>
        /// Start the <see cref="KafkaStream"/> instance by starting all its threads.
        /// This function is expected to be called only once during the life cycle of the client.
        /// Because threads are started in the background, this method does not block.
        /// </summary>
        /// <param name="token">Token for propagates notification that the stream should be canceled.</param>
        public void Start(CancellationToken token = default)
        {
            if (SetState(State.REBALANCING))
            {
                logger.Info($"{logPrefix}Starting Streams client with this topology : {topology.Describe()}");

                if (globalStreamThread != null)
                {
                    globalStreamThread.Start(token);
                }

                foreach (var t in threads)
                {
                    t.Start(token);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Start asynchronously the <see cref="KafkaStream"/> instance by starting all its threads.
        /// This function is expected to be called only once during the life cycle of the client.
        /// Because threads are started in the background, this method does not block.
        /// </summary>
        /// <param name="token">Token for propagates notification that the stream should be canceled.</param>
        public async Task StartAsync(CancellationToken?token = null)
        {
            if (token.HasValue)
            {
                token.Value.Register(() => {
                    _cancelSource.Cancel();
                    Dispose();
                });
            }

            await Task.Factory.StartNew(async() =>
            {
                if (SetState(State.REBALANCING))
                {
                    logger.LogInformation("{LogPrefix}Starting Streams client with this topology : {Topology}", logPrefix, topology.Describe());

                    await InitializeInternalTopicManagerAsync();

                    RunMiddleware(true, true);

                    if (globalStreamThread != null)
                    {
                        globalStreamThread.Start(_cancelSource.Token);
                    }

                    foreach (var t in threads)
                    {
                        t.Start(_cancelSource.Token);
                    }

                    RunMiddleware(false, true);
                }
            }, token ?? _cancelSource.Token);


            try
            {
                // Allow time for streams thread to run
                await Task.Delay(TimeSpan.FromMilliseconds(configuration.StartTaskDelayMs),
                                 token ?? _cancelSource.Token);
            }
            catch
            {
                // nothing, in case or Application crash or stop before end of configuration.StartTaskDelayMs
            }
        }
        public void ShouldConvertExceptionsToStreamsException()
        {
            streamConfigMock.Setup(x => x.PollMs).Throws(new Exception("boom"));

            Assert.Throws <StreamsException>(() => globalStreamThread.Start(cancellationTokenSource.Token));
        }