/// <summary> /// 启动 /// </summary> async Task ILifeFlow.Open() { var files = IOHelper.GetAllFiles(path, "*.msg"); if (files.Count == 0) { return; } ILogger logger = DependencyHelper.LoggerFactory.CreateLogger <ReConsumerMiddleware>(); logger.Information($"重新消费错误消息.共{files.Count}个"); var service = new ZeroService { Receiver = new EmptyReceiver() }; await Task.Yield(); foreach (var file in files) { if (!ZeroAppOption.Instance.IsRuning) { return; } await Task.Delay(10); try { var json = File.ReadAllText(file); if (SmartSerializer.TryToMessage(json, out var message)) { service.ServiceName = message.Service; await MessageProcessor.OnMessagePush(service, message, true, null); } } catch (Exception e) { logger.Exception(e, "异常消息重新处理出错"); } } }
static void RetistTest() { var service = new ZeroService { IsAutoService = true, ServiceName = "MyTest", Receiver = new EmptyReceiver(), Serialize = new NewtonJsonSerializeProxy() } as IService; service.RegistWildcardAction(new ApiActionInfo { Name = "*", Route = "*", ControllerName = "DataEventProxy", ControllerCaption = "DataEventProxy", AccessOption = ApiOption.Public | ApiOption.Anymouse, ResultType = typeof(Task), IsAsync = true, Action = (msg, seri, arg) => null }); ZeroFlowControl.RegistService(service); }
/// <summary> /// 消息处理 /// </summary> /// <param name="station"></param> /// <param name="message"></param> public static void OnMessagePush(ZeroService station, string message) { station.NetPool.Commit(); PublishItem frame = null; try { frame = JsonHelper.DeserializeObject <PublishItem>(message); } catch (Exception e) { station.NetPool.OnError(e, "格式错误"); return; } Interlocked.Increment(ref station.CallCount); try { var executer = new ApiExecuter { Station = station, Item = new ApiCallItem { Station = frame.Topic, Command = frame.Command, Argument = frame.Argument } }; executer.Execute().Wait(); } catch (Exception e) { station.NetPool.OnError(e, "未处理异常"); LogRecorder.Exception(e); } }