public void SendCommunicationReceita(int empresaId) { Empresa emp = this.Find(empresaId); String host = ConfigurationManager.AppSettings["RabbitMQHost"]; String user = ConfigurationManager.AppSettings["RabbitMQUser"]; String pass = ConfigurationManager.AppSettings["RabbitMQPass"]; String exchange = ConfigurationManager.AppSettings["RabbitMQExchange"]; try { using (RabbitMQProducer rabbit = new RabbitMQProducer(host, user, pass, exchange, emp.RabbitmqQueue)) { GetValuesModel gvm = new GetValuesModel(); gvm.GetValuesEnum = GetValuesEnum.GetReceitas; using (MemoryStream ms = new MemoryStream()) { DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(GetValuesModel)); deserializer.WriteObject(ms, gvm); rabbit.Produce(ms.ToArray()); } } } catch (Exception ex) { throw new Exception("A Mensagem não foi enviado para o Rabbit."); } }
private void Execute() { if (ExecuteProperty.Instance.GetStartCommunication) { return; } try { using (RabbitMQConsumer c = new RabbitMQConsumer(this._rabbitmqConfig.Server, this._rabbitmqConfig.User, this._rabbitmqConfig.Pass, this._rabbitmqConfig.Queue, this._rabbitmqConfig.Port)) { try { GetValuesModel wc = GetMessage(c); if (wc == null) { return; } if (!ExecuteProperty.Instance.GetStartCommunication) { ExecuteProperty.Instance.SetStartCommunication(); } else { return; } switch (wc.GetValuesEnum) { case GetValuesEnum.GetReceitas: new ReceitaCommunicationService(); break; default: throw new Exception("O Tipo não está configurado"); } c.AcknowledgeMsg(true); Thread.Sleep(100); } catch (Exception ex) { Singleton.ExecuteProperty.Instance.EventLog.WriteEntry(ex.Message, System.Diagnostics.EventLogEntryType.Error); c.AcknowledgeMsg(false); } } } catch (Exception ex) { Singleton.ExecuteProperty.Instance.EventLog.WriteEntry(ex.Message, System.Diagnostics.EventLogEntryType.Error); } finally { ExecuteProperty.Instance.SetCloseCommunication(); } Thread.Sleep(100); }