static void Main(string[] args) { HttpServer.GetInst("http://127.0.0.1:9090/cache/").Run((req) => { var res = RES.FAIL("尚未进行任何处理"); try { var buffer = req.DATA as byte[]; if (0 < buffer.Length) { var jsonString = Encoding.UTF8.GetString(buffer); var jquest = JRequest.Parse(jsonString); if (jquest.Method == "Execute") { var serverId = jquest.Param[0]; var command = jquest.Param[1]; var paramArr = jquest.Param.ToList().Skip(2).Take(jquest.Param.Length - 2).ToArray(); var resExe = REDIS.GetInst("127.0.0.1", 7379).Execute(serverId, command, paramArr); return(RES.OK(resExe, ENUM.数据类型.ByteArray)); } } return(res); } catch (Exception ex) { return(RES.FAIL(ex, ENUM.数据类型.ByteArray)); } finally { } }); Console.WriteLine("Hello World!"); Console.ReadKey(); }
///清空队列 public RES QueueClear(string appId, string queueName) { try { var res = this.Http.UploadString(this.url, JRequest.ToJson("Execute", new string[] { appId, "DEL", $"{redisKeyQueue}:{queueName}" })); return(RES.OK(res)); } catch (Exception ex) { return(RES.FAIL(ex)); } }
///入队列 public RES EnQueue(string appId, string queueName, string data) { try { var res = this.Http.UploadString(this.url, JRequest.ToJson("Execute", new string[] { appId, "RPUSH", $"{redisKeyQueue}:{queueName}", data })); return(RES.OK(res)); } catch (Exception ex) { return(RES.FAIL(ex)); } }
public RES CacheRemove(string appId, string cacheName, string key) { try { var res = this.Http.UploadString(this.url, JRequest.ToJson("Execute", new string[] { appId, "DEL", $"{cacheName}:{key}" })); return(RES.OK(res)); } catch (Exception ex) { return(RES.FAIL(ex)); } }
public RES DictExistItem(string appId, string dictName, string key) { try { var res = this.Http.UploadString(this.url, JRequest.ToJson("Execute", new string[] { appId, "HEXISTS", $"{redisKeyDict}:{dictName}", key })); return(RES.OK(res)); } catch (Exception ex) { return(RES.FAIL(ex)); } }
///栈深度 public RES StackDepth(string appId, string stackName) { try { var res = this.Http.UploadString(this.url, JRequest.ToJson("Execute", new string[] { appId, "LLEN", $"{redisKeyStack}:{stackName}" })); return(RES.OK(res)); } catch (Exception ex) { return(RES.FAIL(ex)); } }
public RES Delete(string param) { try { var req = JRequest.Parse(this.HttpContext.Request.Body); var res = REDIS.Current.Execute(string.Empty, req.Method, req.Param); return(res); } catch (Exception ex) { return(RES.FAIL(ex)); } }
public virtual RES Delete() { try { var req = JRequest.Parse(this.Request.Body); if (null != req) { var res = req.Execute(req); return(res); } return(RES.FAIL("未传入有效参数")); } catch (Exception ex) { return(RES.FAIL(ex)); } }
public virtual RES Get(string param) { try { var req = JRequest.Parse(param); if (null != req) { var res = req.Execute(req); return(res); } return(RES.FAIL("未传入有效参数")); } catch (Exception ex) { return(RES.FAIL(ex)); } }
/// <summary> /// Starts a new thread where the consumer runs and waits for data /// </summary> /// <param name="cancel"> Cancellation token, to cancel this thread and close the consumer connection to the broker gracefully</param> public void run(CancellationToken cancel) { Action action = async() => { try { logger.Info("is ON and starting consuming"); while (true) { try { logger.Debug("consuming...."); try{ var consumeResult = _consumer.Consume(cancel); logger.Debug("Received kafka message in topic:" + consumeResult.Topic + " key:" + consumeResult.Message.Key + " value:" + consumeResult.Message.Value); JResponse res = new JResponse(); try{ JRequest req = validateRequest(consumeResult.Message.Value); // at this point only write signle variable to opc is supported FIXME string[] names = { (string)req.parameters[0] }; object[] values = { req.parameters[1] }; var w_resp = await _serv.writeToOPCserver(names, values); if (w_resp[0].success) { res.setWriteResult(consumeResult, (string)req.parameters[1]); await sendResponse(res); logger.Debug("Successful Write action to opc-server and Response"); } else { res.setError(consumeResult, "Error in writing to OPC server"); await sendResponse(res); } } catch { logger.Error("Invalid Request, value: " + consumeResult.Message.Value); res.setError(consumeResult, "Invalid Request"); await sendResponse(res); } } catch (MessageNullException e) { logger.Error(e.Message); } } catch (ConsumeException e) { logger.Error($"Consume error: {e.Error.Reason}"); // producer send error } } } catch (OperationCanceledException) { logger.Debug("Operation canceled, Closing consumer."); _consumer.Close(); } }; Task.Run(action, cancel); }
public JRequest validateRequest(GenericRecord input) { object method; object parameters; object[] parameters_array; object id; List <String> supported_methods = new List <String> { "write" }; JRequest req = new JRequest(); // Validate correct types input.TryGetValue("method", out method); if (method == null || method.GetType() != typeof(String)) { throw new Exception("'method' field null or not a string"); } input.TryGetValue("params", out parameters); if (parameters == null || !parameters.GetType().IsArray) { throw new Exception("'params' field null or not an array"); } parameters_array = (Object[])parameters; input.TryGetValue("id", out id); if (id == null) { id = -999; } else if (id.GetType() != typeof(Int32)) { throw new Exception("'id' field null or not a integer"); } // method not supported if (!supported_methods.Contains((String)method)) { throw new Exception("method '" + method + "' is not supported."); } // Check if fullfills the write method parameters if ((String)method == "write") { if (parameters_array.Length != 2) { throw new Exception("For method 'write', 'params' must have only 2 entry"); } if (parameters_array[0].GetType() != typeof(String)) { throw new Exception("'params' is not an array of strings"); } if (parameters_array[1].GetType() != typeof(String)) { throw new Exception("'params' is not an array of strings"); } } req.method = (String)method; req.parameters = parameters_array; req.id = (Int32)id; return(req); }