async Task IHostedService.StartAsync(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { if (!ZeroAppOption.Instance.IsRuning) { await Task.Delay(1000); continue; } await Task.Delay(100); //await Task.Delay(1); //await MessagePoster.PublishAsync("test1", "test/res", "agebull"); //await MessagePoster.PublishAsync("test1", "test/arg", "{'Value':'test'}"); await MessagePoster.PublishAsync("test1", "test/full", "{'name':'test'}"); //await MessagePoster.PublishAsync("test1", "test/void", "agebull"); //await MessagePoster.PublishAsync("test1", "async/res", "{'Value':'test'}"); //await MessagePoster.PublishAsync("test1", "async/arg", "{'Value':'test'}"); //await MessagePoster.PublishAsync("test1", "async/full", "{'Value':'test'}"); //await MessagePoster.PublishAsync("test1", "async/void", "{'Value':'test'}"); } }
async Task IHostedService.StartAsync(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { FlowTracer.BeginMonitor("OrderEvent"); await MessagePoster.PublishAsync("OrderEvent", "offline/v1/new", new UnionOrder { Items = new List <UnionOrderItem> { new UnionOrderItem { ItemType = SkuType.GeneralProduct, SkuName = "女鞋E思Q", SalePrice = 50, Number = 3, Amount = 500, Pay = 100, BaseSkuSid = 878465627947009L } }, Amount = 500, Pay = 500 }); _logger.TraceMonitor(FlowTracer.EndMonitor()); await Task.Delay(1000); } }
/// <summary> /// 结果处理 /// </summary> /// <param name="message">当前消息</param> /// <returns></returns> async Task IMessageMiddleware.OnEnd(IInlineMessage message) { var root = FlowTracer.EndMonitor(); if (root != null) { ScopeRuner.ScopeLogger.TraceMonitor(root); } if (ToolsOption.Instance.EnableMarkPoint && (message.Service != ToolsOption.Instance.MarkPointName || message.Method != "post")) { await MessagePoster.PublishAsync(ToolsOption.Instance.MarkPointName, "post", new TraceLinkMessage { Monitor = root, Trace = GlobalContext.CurrentNoLazy?.TraceInfo, Message = new MessageItem { ID = message.ID, State = message.State, Service = message.Service, Method = message.Method, Argument = message.Argument, Result = message.Result, User = GlobalContext.User?.ToDictionary(), Context = GlobalContext.CurrentNoLazy?.ToDictionary() } }); } }
public async Task Test1() { for (int i = 0; i < 1000; i++) { await MessagePoster.PublishAsync("Markpoint2", "test", new Argument { Value = "Test" }); } //Assert.IsTrue(task.Result.Success, "测试通过"); }
async Task IHostedService.StartAsync(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { await MessagePoster.PublishAsync("tcp", "test", "agebull"); await Task.Delay(10000); } }
async void ILogger.Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { if (ZeroAppOption.Instance.IsClosed || !LogOption.Instance.Enable || logLevel < LogOption.Instance.Level) { return; } try { var item = new LogItem { Time = DateTime.Now, LogLevel = logLevel, LogId = eventId.Id, LoggerName = LoggerName, Message = state?.ToString(), Exception = exception?.ToString(), Service = ZeroAppOption.Instance.LocalApp, Machine = ZeroAppOption.Instance.LocalMachine }; if (ScopeRuner.InScope) { item.UserId = GlobalContext.User?.UserId; var message = GlobalContext.Current?.Message; if (message != null) { item.MessageId = message.ID; item.ApiName = $"{message.Service}/{message.Method}"; if (message.TraceInfo != null) { item.TraceId = message.TraceInfo.TraceId; item.LocalId = message.TraceInfo.LocalId; item.CallId = message.TraceInfo.CallId; } } } await MessagePoster.PublishAsync(LogOption.Instance.Service, "text", item); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex); Console.ResetColor(); } }
/// <summary> /// 结果处理 /// </summary> /// <param name="message">当前消息</param> /// <returns></returns> Task IMessageMiddleware.OnEnd(IInlineMessage message) { return(MessagePoster.PublishAsync(LogOption.Instance.Service, LogOption.Instance.MonitorApi, new TraceLinkMessage { Monitor = FlowTracer.EndMonitor(false), Trace = message.TraceInfo, Message = new MessageItem { ID = message.ID, State = message.State, Service = message.Service, Method = message.Method, Argument = message.Argument, Result = message.Result, User = GlobalContext.User?.ToDictionary(), Context = GlobalContext.CurrentNoLazy?.ToDictionary() } })); }