public void GetMessage(string queueName) { JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); ch.QueueDeclare("TEXT"); BasicGetResult result = ch.BasicGet(queueName, false); if (result == null) { Console.WriteLine("No message available."); } else { string str = System.Text.Encoding.Default.GetString(result.Body); Console.WriteLine(str); Flipper f = jsSerializer.Deserialize<Flipper>(str); var s = Summary.GetInfo(f); Twillio t = new Twillio() { phone = s.PersonSummaryService.response.contact_information.work_phone, message = f.message }; if (t.Send()) ch.BasicAck(result.DeliveryTag, false); } }
private static void ReceiveMessages(Subscription sub) { JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); Console.WriteLine("Receiving messages (using Subscriber's IEnumerator)"); int i = 0; foreach (BasicDeliverEventArgs ev in sub) { Console.WriteLine("Message {0}: {1}", i, messageText(ev)); try { Flipper f = jsSerializer.Deserialize<Flipper>(messageText(ev)); var s = Summary.GetInfo(f); Twillio t = new Twillio() { phone = s.PersonSummaryService.response.contact_information.work_phone, message = f.message }; if (t.Send()) { sub.Ack(); Console.WriteLine("TEXT SENT"); } else Console.WriteLine("TEXT FAILED"); } catch (Exception x) { Console.WriteLine("Problem {0}: {1}", i, x.Message); } i++; } Console.WriteLine("Done.\n"); }