Пример #1
0
        private void Consumer_Received(object sender, BasicDeliverEventArgs ea)
        {
            try
            {
                _semaphore.Wait();
                LocationWriteDataQueue message = _objectDataConverter.JsonToObject <LocationWriteDataQueue>(Encoding.UTF8.GetString(ea.Body));
                MessageReceived?.Invoke(this, message);

                Task.Run(() =>
                {
                    try
                    {
                        var task = _locationInfoService.FileWritingOperation(message);
                        task.Wait();
                        var result = task.Result;
                        MessageProcessed?.Invoke(this, result);
                    }
                    catch (Exception ex)
                    {
                        //log
                        //throw new Exception(ex.InnerException.Message.ToString());
                    }
                    finally
                    {
                        _channel.BasicAck(ea.DeliveryTag, false);
                        _semaphore.Release();
                    }
                });
            }
            catch (Exception ex)
            {
                //loglama
                //throw new Exception(ex.InnerException.Message.ToString());
            }
        }
        private void Consumer_Received(object sender, BasicDeliverEventArgs ea)
        {
            try
            {
                _semaphore.Wait();
                LocationReadDataQueue message = _objectDataConverter.JsonToObject <LocationReadDataQueue>(Encoding.UTF8.GetString(ea.Body));
                MessageReceived?.Invoke(this, message);

                Task.Run(() =>
                {
                    try
                    {
                        var task = _locationInfoService.GetLocationsDistanceAsync(message);
                        task.Wait();
                        var result = task.Result;

                        var insertedTask = _locationInfoService.QueueDatabaseCreatedAfterSendFileProcess(result);
                        insertedTask.Wait();

                        MessageProcessed?.Invoke(this, result);
                    }
                    catch (Exception ex)
                    {
                        //throw new Exception(ex.InnerException.Message.ToString());
                    }
                    finally
                    {
                        _channel.BasicAck(ea.DeliveryTag, false);
                        _semaphore.Release();
                    }
                });
            }
            catch (Exception ex)
            {
                throw new Exception(ex.InnerException.Message.ToString());
            }
        }