Esempio n. 1
0
        /// <summary>
        /// 消息处理(异步)
        /// </summary>
        /// <param name="service">服务</param>
        /// <param name="message">消息</param>
        /// <param name="offline">是否离线消息</param>
        /// <param name="original">原始透传对象</param>
        public static void RunOnMessagePush(IService service, IInlineMessage message, bool offline, object original)
        {
            if (!ZeroAppOption.Instance.BeginRequest())
            {
                message.RealState = MessageState.Cancel;
                return;
            }
            message.RealState = MessageState.Recive;
            var process = new MessageProcessor
            {
                Service   = service,
                Message   = message,
                Original  = original,
                IsOffline = offline
            };

            ScopeRuner.RunScope($"{message.Service}/{message.Method}", process.Process, ContextInheritType.Clone);
        }
Esempio n. 2
0
        /// <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, "异常消息重新处理出错");
                }
            }
        }