public async Task<string[]> GetFieldsByMachines(IList<string> machines) { if (machines.Count > 0) { var machinesJson = JsonConvert.SerializeObject(machines); Utils.Query q = new Utils.Query { Type = "GetFieldsByMachines", Field = machinesJson }; var message = new AMQPMessage { Type = AMQPMessageType.Query, Data = JsonConvert.SerializeObject(q), Sender = "management" }; await _amqpconn.SendMessageAsync("direct_message", "database", JsonConvert.SerializeObject(message)); //ricezione query result string result = await taskCompletionSource.Task; if (String.IsNullOrEmpty(result)) { return null; } else { var fields = JsonConvert.DeserializeObject<List<String>>(result).ToArray(); return fields; } } else { return null; } }
public static async void GetTelemetryFromDB(string machineId, int period, string field) { try { var query = new Query(); query.MachineId = machineId; query.Period = period; query.Field = field; var data = JsonConvert.SerializeObject(query); var request = new AMQPMessage(); request.Sender = _config.Communications.AMQP.Queue; request.Data = data; request.Type = AMQPMessageType.Query; var json = JsonConvert.SerializeObject(request); //Inizializzo nuovo canale dedicato e riservato al thread corrente var channel = _amqpconn.CreateChannel(); //Scrivo messaggio query sul canale appena creato await _amqpconn.SendMessageAsync(_config.Communications.AMQP.Exchange, "database", json, channel); //Chiudo canale _amqpconn.CloseChannel(channel); } catch (Exception e) { log.Error($"Error: {e.Message}"); } }
public async Task<string[]> GetMachines() { //invio richiesta query a microservizio database Utils.Query q = new Utils.Query { Type = "GetMachines" }; var message = new AMQPMessage { Type = AMQPMessageType.Query, Data = JsonConvert.SerializeObject(q), Sender = "management" }; await _amqpconn.SendMessageAsync("direct_message", "database", JsonConvert.SerializeObject(message)); //ricezione query result string result = await taskCompletionSource.Task; var machines = JsonConvert.DeserializeObject<List<String>>(result).ToArray(); return machines; }