using System; using System.Collections.Concurrent; using MrWu.RabbitMQ; using Server.Pack; using GameData; namespace Server.MQ { /// /// 消息池 /// public class WaitBeMsgPool { static WaitBeMsgPool() { instace = new WaitBeMsgPool(); } private WaitBeMsgPool() { } private static WaitBeMsgPool instace; /// /// 所有的消息 /// private ConcurrentQueue msgs = new ConcurrentQueue(); /// /// 获取消息 /// /// public static WaitBeMsg GetWaiteBeMsg(Message msg) { WaitBeMsg tmp = null; if (!instace.msgs.TryDequeue(out tmp)) { tmp = new WaitBeMsg(); } tmp.message = msg; tmp.AutoAck = true; //ServerHead head = null; tmp.jsondata = JsonPack.GetPackHead(msg.bodystr, out tmp.head); //tmp.head = head; return tmp; } /// /// 处理消息 /// /// public static void PutWaiteBeMsg(ref WaitBeMsg msg) { if (msg == null) return; msg.Clear(); instace.msgs.Enqueue(msg); msg = null; } } }