// 发布消息 public virtual void PublishMessageEvent(ILogicWork logic, ILogicEntity entity) { if (!LogicFactory.ParseToCommunication.ContainsKey(entity.FindKey)) { WriteError(string.Format("逻辑:{0} 消息队列发布失败,未找到实体需要发布的解析实体:{1}", logic != null ? logic.GetType().Name : "null", entity.FindKey)); return; } // 取池 var communicationEntity = CommunicateFactory.GetOrCreateEntity(entity.FindKey); try { // 反解析 LogicFactory.ParseToCommunication[entity.FindKey].Convert(communicationEntity, entity); } catch (Exception ex) { WriteError(string.Format("逻辑:{0} 逻辑数据[{1}] 反解失败,异常:{2}", logic != null ? logic.GetType().Name : "null", entity.FindKey, ex)); // 还池,使用者还池 //CommunicateFactory.GivebackEntity(communicationEntity); return; } if (!PushQueueDic.ContainsKey(entity.FindKey)) { WriteError(string.Format("逻辑:{0} 消息队列发布失败,未找到实体需要发布的消息队列:{1}", logic != null ? logic.GetType().Name : "null", entity.FindKey)); return; } try { // 推送数据 PushQueueDic[entity.FindKey].Push(communicationEntity); } catch (Exception ex)// 传入参数由调用使用者归还 { WriteError(ex, string.Format("逻辑:{0} 消息{1}发布失败", logic != null ? logic.GetType().Name : "null", entity.FindKey)); } if (PublishMessageCount == long.MaxValue) { WriteInfo(string.Format("数据发送计数器达到最大值,计数器清空")); PublishMessageCount = 0; } // 计数器计数 System.Threading.Interlocked.Increment(ref PublishMessageCount); }
/// <summary> /// 执行对应逻辑指令 /// </summary> /// <param name="logic">逻辑操作</param> /// <param name="entity">通信实体</param> /// <param name="logicEntity">逻辑实体</param> protected virtual void Dowork(ILogicWork logic, ICommunicationEntity entity, ILogicEntity logicEntity) { logic.Dowork(entity, logicEntity); }