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()); } }
public async Task <LocationWriteDataQueue> GetLocationsDistanceAsync(LocationReadDataQueue locationReadDataQueue) { Console.WriteLine($"RabbitMQProcessor DataBaseConsumerManager GetLocationsDistance method => Calısma zamanı: {DateTime.Now.ToShortTimeString()}"); LocationWriteDataQueue locationWriteDataQueue = new LocationWriteDataQueue(); locationWriteDataQueue.LocationReadDataQueue = locationReadDataQueue; locationWriteDataQueue.Distance = DistanceCalculate(locationReadDataQueue.LocationInfoInputDto.SourceLatitude, locationReadDataQueue.LocationInfoInputDto.SourceLongitude, locationReadDataQueue.LocationInfoInputDto.DestinationLatitude, locationReadDataQueue.LocationInfoInputDto.DestinationLongitude, 'K' ); var a = await AddAsync(new DominosLocation { DestinationLatitude = locationWriteDataQueue.LocationReadDataQueue.LocationInfoInputDto.DestinationLatitude, DestinationLongitude = locationWriteDataQueue.LocationReadDataQueue.LocationInfoInputDto.DestinationLongitude, SourceLatitude = locationWriteDataQueue.LocationReadDataQueue.LocationInfoInputDto.SourceLatitude, SourceLongitude = locationWriteDataQueue.LocationReadDataQueue.LocationInfoInputDto.SourceLongitude }); if (a.Id != 0) { await QueueDatabaseCreatedAfterSendFileProcess(locationWriteDataQueue); } var data = await Task.FromResult(locationWriteDataQueue); return(data); }
public async Task <bool> FileWritingOperation(LocationWriteDataQueue locationWriteDataQueue) { Console.WriteLine($"RabbitMQProcessor FileOperationConsumerManager FileWritingOperation method => Calısma zamanı: {DateTime.Now.ToShortTimeString()}"); var fileRootAndName = GetFileOutputOperation(); ProcessWrite(locationWriteDataQueue, fileRootAndName).Wait(); var data = await Task.FromResult(true); return(data); }
private Task ProcessWrite(LocationWriteDataQueue locationWriteDataQueue, string filePath) { var fileTextData = Math.Round(locationWriteDataQueue.LocationReadDataQueue.LocationInfoInputDto.SourceLatitude, 10).ToString() + "\t" + Math.Round(locationWriteDataQueue.LocationReadDataQueue.LocationInfoInputDto.SourceLongitude, 10).ToString() + "\t" + Math.Round(locationWriteDataQueue.LocationReadDataQueue.LocationInfoInputDto.DestinationLatitude, 10).ToString() + "\t" + Math.Round(locationWriteDataQueue.LocationReadDataQueue.LocationInfoInputDto.DestinationLongitude, 10).ToString() + "\t" + Math.Round(locationWriteDataQueue.Distance, 3).ToString() + "\r\n"; return(WriteTextAsync(filePath, fileTextData)); }
public async Task QueueDatabaseCreatedAfterSendFileProcess(LocationWriteDataQueue locationWriteDataQueue) { List <LocationWriteDataQueue> locationWriteDataQueues = new List <LocationWriteDataQueue>(); locationWriteDataQueues.Add(locationWriteDataQueue); await _publisherService.EnqueueAsync( locationWriteDataQueues, RabbitMqConsts.RabbitMqConstsList.DominosLocationFileOptionQueue.ToString() ); }