Exemplo n.º 1
0
 public override void Dispose()
 {
     Dbg("Disposing of producer");
     if (Handle != null)
     {
         Handle.Dispose();
     }
 }
Exemplo n.º 2
0
        private static void Sending()
        {
            string input = string.Empty;

            try
            {
                while (input != "X")
                {
                    input = System.Console.ReadLine();

                    if (!int.TryParse(input, out int count))
                    {
                        System.Console.WriteLine("Enter a number");
                    }

                    for (int i = 0; i < count; i++)
                    {
                        var message = generator.GenerateNew();
                        producer.SendRequest(JsonConvert.SerializeObject(message));
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
            finally
            {
                producer.Dispose();
            }
        }
Exemplo n.º 3
0
 protected override void CleanUp()
 {
     _logger.LogInformation("Solicitação de cancelamento recebida pelo Produtor");
     _producer.Dispose();
     _producer = null;
     _logger.LogInformation("Produtor finalizado");
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Select(s => s.ToLower()).Contains("kafka"))
                {
                    //TODO: KafkaSettings
                    producer = new KafkaProducer();
                }
                else
                {
                    RabbitMQSettings settings = (RabbitMQSettings)ConfigurationManager.GetSection("rabbitMQSettings");
                    producer = new RabbitMQProducer(settings);
                }
                producer.Initialize();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
                producer?.Dispose();
                System.Console.Read();
                return;
            }

            System.Console.WriteLine("For exit enter \"X\"");
            System.Console.WriteLine("Enter count random messages");

            Sending();
        }
Exemplo n.º 5
0
        public void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            IHostApplicationLifetime applicationLifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app
            .UseHttpsRedirection()
            .UseRouting()
            .UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            // Add kafka consumer
            applicationLifetime.ApplicationStarted.Register(this.ConfigKafkaConsumer);

            // Dispose kafka producer and consumer
            applicationLifetime.ApplicationStopping.Register(() =>
            {
                _producerUserMessage.Flush();
                _producerUserMessage.Dispose();
                _consumer.Dispose();
            });
        }
Exemplo n.º 6
0
 /// <inheritdoc />
 public void Dispose()
 {
     // Because the tasks returned from ProduceAsync might not be finished, wait for all messages to be sent
     _producer?.Flush(TimeSpan.FromSeconds(5));
     _producer?.Dispose();
     _queueSubscriptionStorage?.Dispose();
 }
        /// <summary><see cref="IDisposable.Dispose"/></summary>
        public void Dispose()
        {
            // Stop all running tasks
            if (_cancellationTokenSource != null)
            {
                _cancellationTokenSource.Cancel();
            }
            // Stop the connection with the large file service
            if (_fileServiceClient != null)
            {
                _fileServiceClient.Dispose();
            }

            // Dispose all created producers
            foreach (IAbstractProducer producer in _producers.Values)
            {
                ((IDisposable)producer).Dispose();
            }
            // Dispose all created consumers
            foreach (IAbstractConsumer consumer in _consumers.Values)
            {
                ((IDisposable)consumer).Dispose();
            }

            // Dispose all system producers
            if (_heartbeatProducer != null)
            {
                _heartbeatProducer.Flush();
                _heartbeatProducer.Dispose();
            }
            if (_logProducer != null)
            {
                _logProducer.Flush();
                _logProducer.Dispose();
            }

            // Dispose all system consumers
            if (_heartbeatConsumer != null)
            {
                _heartbeatConsumer.Close();
                _heartbeatConsumer.Dispose();
            }
            if (_timeConsumer != null)
            {
                _timeConsumer.Close();
                _timeConsumer.Dispose();
            }
            if (_timeControlConsumer != null)
            {
                _timeControlConsumer.Close();
                _timeControlConsumer.Dispose();
            }
            if (_topicInviteConsumer != null)
            {
                _topicInviteConsumer.Close();
                _topicInviteConsumer.Dispose();
            }

            _instance = null;
        }
            public void Dispose()
            {
                var timeout = TimeSpan.FromSeconds(30);

                _producer.Flush(timeout);
                _producer.Dispose();
            }
Exemplo n.º 9
0
        public void Stop()
        {
            Stopped = true;
            _kafkaProducer.Dispose();

            _logger.InfoFormat("{0} stopped.", GetType().Name);
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            Initialize();
            string input = string.Empty;

            try
            {
                while (input != "X")
                {
                    System.Console.WriteLine("Enter count random messages");
                    input = System.Console.ReadLine();

                    int count;
                    count = Convert.ToInt32(input);

                    for (int i = 0; i < count; i++)
                    {
                        var message = GetRandomMessage();
                        SendRequest(JsonConvert.SerializeObject(message));
                    }
                }
            }
            catch { }
            finally
            {
                producer.Dispose();
            }
        }
Exemplo n.º 11
0
 public void Dispose()
 {
     if (_producer != null)
     {
         _producer.Dispose();
     }
 }
Exemplo n.º 12
0
 public void Dispose()
 {
     producer.Dispose();
     consumer.Dispose();
     consumingBag.Dispose();
     threadPool.Dispose();
 }
Exemplo n.º 13
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _producer?.Dispose();
     }
 }
Exemplo n.º 14
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }
            try
            {
                if (_consumers != null)
                {
                    _consumers.ForEach(customer =>
                    {
                        customer.Dispose();
                    });
                }

                if (_producer != null)
                {
                    _producer.Dispose();
                }
            }
            catch (IOException ex)
            {
                _logger.LogCritical(ex.ToString());
            }
            finally
            {
                _disposed = true;
            }
        }
Exemplo n.º 15
0
        public void Dispose()
        {
            Flush();

            _publisher?.Dispose();
            _publisher = null;
        }
Exemplo n.º 16
0
 public void Dispose()
 {
     _logger.LogInformation("Received request to dispose Kafka producer");
     _producer.Flush();
     _logger.LogDebug("Flushing of producer completed.");
     _producer.Dispose();
     _logger.LogDebug("Disposed of producer.");
 }
        void disconnectButton_Click(object sender, EventArgs e)
        {
            consumer.Dispose();
            producer.Dispose();

            connectButton.Enabled    = true;
            disconnectButton.Enabled = false;
        }
Exemplo n.º 18
0
 public void Dispose()
 {
     if (producer != null)
     {
         producer.Flush();
         producer.Dispose();
     }
 }
 public void Shutdown()
 {
     Console.WriteLine("Shutting down Kafka producer (may take up to 10 seconds)...");
     _p.Flush(TimeSpan.FromSeconds(10));
     _p.Dispose();
     _p = null;
     Console.WriteLine("Kafka producer closed.");
 }
Exemplo n.º 20
0
 private void CloseProducer()
 {
     if (Producer != null)
     {
         Producer?.Flush(TimeSpan.FromSeconds(60));
         Producer?.Dispose();
     }
     Producer = null;
 }
Exemplo n.º 21
0
        public void Dispose()
        {
            if (!_initialized)
            {
                return;
            }

            _producer?.Dispose();
        }
Exemplo n.º 22
0
        public void Dispose()
        {
            _isClosing = true;
            _cquePair  = null;

            _task?.Wait();

            _producer?.Dispose();
        }
Exemplo n.º 23
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _consumer?.Close();
         _consumer?.Dispose();
         _producer?.Dispose();
     }
 }
Exemplo n.º 24
0
 public void Close()
 {
     if (!NotInit)
     {
         _producer.Dispose();
         _producer = null;
     }
     NotInit = true;
 }
Exemplo n.º 25
0
        public void Dispose()
        {
            if (!_initialized)
            {
                return;
            }

            _producerBlocks?.Dispose();
            _producerTransactions?.Dispose();
        }
        /// <inheritdoc />
        public void Disconnect()
        {
            if (_isDisposed)
            {
                return;
            }

            _consumer?.Dispose();
            _producer?.Dispose();
        }
        public void Dispose()
        {
            cmdProducer.Dispose();

            commandConsumer.Close();
            commandConsumer.Dispose();

            changeLogConsumer.Close();
            changeLogConsumer.Dispose();
        }
Exemplo n.º 28
0
 /// <summary>
 /// 释放 producer
 /// </summary>
 private void Dispose()
 {
     try
     {
         _producer?.Dispose();
     }
     catch (Exception ex)
     {
         ErrorHandler.Error("could not dispose producer", ex);
     }
 }
 public void Dispose()
 {
     if (cons != null)
     {
         cons.Dispose();
     }
     if (prod != null)
     {
         prod.Dispose();
     }
 }
Exemplo n.º 30
0
        private bool _disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    _producer.Dispose();
                }

                _disposedValue = true;
            }
        }