static async Task Main(string[] args) { // configure Redis string redisIp = System.Configuration.ConfigurationSettings.AppSettings["RedisIP"]; var redis = new RedisClient(redisIp); while (true) { // read from Redis queue Console.WriteLine(redis.BLPop(30, "sensors_data")); // send value to remote API // TODO... using (var client = new HttpClient()) { //This would be the like http://www.uber.com string baseAddress = System.Configuration.ConfigurationSettings.AppSettings["baseAddress"]; client.BaseAddress = new Uri(baseAddress); //serialize your json using newtonsoft json serializer then add it to the StringContent var content = new StringContent(redis.BLPop(30, "sensors_data"), Encoding.UTF8, "application/json"); //method address would be like api/callUber:SomePort for example string APIaddress = System.Configuration.ConfigurationSettings.AppSettings["address"]; var result = await client.PostAsync(APIaddress, content); string resultContent = await result.Content.ReadAsStringAsync(); } } }
static void Main(string[] args) { int pullmanNumber = 6; int count = 0; var redis = new RedisClient("127.0.0.1"); Pullman p1 = new Pullman("CA128TD", 70); Pullman p2 = new Pullman("DB94111", 40); Pullman p3 = new Pullman("AA17424", 50); Pullman p4 = new Pullman("EE119CA", 70); Pullman p5 = new Pullman("PI11063", 70); Pullman p6 = new Pullman("PD54715", 30); while (true) { Thread.Sleep(3000); p1.Update(); p2.Update(); p3.Update(); p4.Update(); p5.Update(); p6.Update(); // sendToApi(JsonCreator(p1)); // sendToApi(JsonCreator(p2)); // sendToApi(JsonCreator(p3)); // sendToApi(JsonCreator(p4)); // sendToApi(JsonCreator(p5)); // sendToApi(JsonCreator(p6)); redis.LPush("sensors_data", JsonCreator(p1)); redis.LPush("sensors_data", JsonCreator(p2)); redis.LPush("sensors_data", JsonCreator(p3)); redis.LPush("sensors_data", JsonCreator(p4)); redis.LPush("sensors_data", JsonCreator(p5)); redis.LPush("sensors_data", JsonCreator(p6)); if (ping()) { if (count > 0) { for (int i = 0; i < count * pullmanNumber; i++) { sendToApi(redis.BLPop(30, "sensors_data")); } } for (int i = 0; i < pullmanNumber; i++) { sendToApi(redis.BLPop(30, "sensors_data")); } count = 0; } else { count++; } } }
public void TestBLPop() { string reply = "*2\r\n$4\r\ntest\r\n$5\r\ntest1\r\n"; using (var mock = new FakeRedisSocket(reply, reply)) using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999))) { Assert.AreEqual("test1", redis.BLPop(60, "test")); Assert.AreEqual("*3\r\n$5\r\nBLPOP\r\n$4\r\ntest\r\n$2\r\n60\r\n", mock.GetMessage()); Assert.AreEqual("test1", redis.BLPop(TimeSpan.FromMinutes(1), "test")); Assert.AreEqual("*3\r\n$5\r\nBLPOP\r\n$4\r\ntest\r\n$2\r\n60\r\n", mock.GetMessage()); } }
public void TestBLPop() { string reply = "*2\r\n$4\r\ntest\r\n$5\r\ntest1\r\n"; using (var mock = new MockConnector("localhost", 9999, reply, reply)) using (var redis = new RedisClient(mock)) { Assert.Equal("test1", (string)redis.BLPop(60, "test").Value); Assert.Equal("*3\r\n$5\r\nBLPOP\r\n$4\r\ntest\r\n$2\r\n60\r\n", mock.GetMessage()); Assert.Equal("test1", (string)redis.BLPop(TimeSpan.FromMinutes(1), "test").Value); Assert.Equal("*3\r\n$5\r\nBLPOP\r\n$4\r\ntest\r\n$2\r\n60\r\n", mock.GetMessage()); } }
public void TestBLPop() { string reply = "*2\r\n$4\r\ntest\r\n$5\r\ntest1\r\n"; using (var mock = new FakeRedisSocket(reply, reply)) using (var redis = new RedisClient(mock, new DnsEndPoint("fakehost", 9999))) { Assert.Equal("test1", redis.BLPop(60, "test")); Assert.Equal("*3\r\n$5\r\nBLPOP\r\n$4\r\ntest\r\n$2\r\n60\r\n", mock.GetMessage()); Assert.Equal("test1", redis.BLPop(TimeSpan.FromMinutes(1), "test")); Assert.Equal("*3\r\n$5\r\nBLPOP\r\n$4\r\ntest\r\n$2\r\n60\r\n", mock.GetMessage()); } }
public void TestBLPop() { string reply = "*2\r\n$4\r\ntest\r\n$5\r\ntest1\r\n"; using (var mock = new MockConnector("MockHost", 9999, reply, reply)) using (var redis = new RedisClient(mock)) { Assert.AreEqual("test1", redis.BLPop(60, "test")); Assert.AreEqual("*3\r\n$5\r\nBLPOP\r\n$4\r\ntest\r\n$2\r\n60\r\n", mock.GetMessage()); Assert.AreEqual("test1", redis.BLPop(TimeSpan.FromMinutes(1), "test")); Assert.AreEqual("*3\r\n$5\r\nBLPOP\r\n$4\r\ntest\r\n$2\r\n60\r\n", mock.GetMessage()); } }
public void Send() { try { if (redis.LLen("sensors_data") == 0) { } else { HttpWebRequest httpWebRequestData; httpWebRequestData = (HttpWebRequest)WebRequest.Create(url); httpWebRequestData.ContentType = "application/json"; httpWebRequestData.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequestData.GetRequestStream())) { string dataJson = redis.BLPop(30, "sensors_data"); streamWriter.Write(dataJson); streamWriter.Flush(); streamWriter.Close(); } var httpResponseData = (HttpWebResponse)httpWebRequestData.GetResponse(); using (var streamReader = new StreamReader(httpResponseData.GetResponseStream())) { var result = streamReader.ReadToEnd(); } } }catch (Exception e) { Console.WriteLine(e.Message); } }