/* * 由SharpDevelop创建。 * 用户: Administrator * 日期: 2019-01-05 * 时间: 14:08 * * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件 */ using MrWu.Debug; using MrWu.RabbitMQ; using RabbitMQ.Client; using Server.Pack; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using GameData; namespace Server.MQ { /// /// 等待处理的消息 /// public class WaitBeMsg { ///// ///// 查慢的原因用的,日志 ///// //public DateTime logTime; // private ServerHead mhead; /// /// 消息内容 /// public PackHead head; /// /// 包体数据 /// public string jsondata; /// /// 包头+包体 /// public string jsonmessage { get { return message.bodystr; } } /// /// 其他参数 /// public List pms; /// /// 步骤 /// public int step = 0; /// /// 消息 /// public Message message; /// /// 是否处理完自动确认 如果不是自动确认的话,消息需要手动确认,请清理消息内存 /// public bool AutoAck; /// /// 交换机 /// public string exchange { get { return message.exchange; } } /// /// 路由键 /// public string routingkey { get { return message.routingkey; } } /// /// 消息属性 /// public IBasicProperties propertis { get { return message.propertis; } } /// /// 用户数据 /// public IDictionary userData { get { return message.userData; } } /// /// 是否不需要确认 /// public bool noAck { get { return message.noAck; } } /// /// 消息唯一id /// public string id { get { return message.id; } } /// /// 消息投递标签 /// public ulong deliveryTag { get { return message.deliveryTag; } } /// /// 是否被重复接收过 /// public bool redelivered { get { return message.redelivered; } } /// /// 是否确认过 /// public bool isAck { get; private set; } /// /// 是否要继续添加到消息列表中处理 /// public bool isAdd; /// /// 数据 /// public object[] datas { get; private set; } = new object[10]; /// /// 上次的任务 /// public Task task; /// /// 确认消息 /// /// /// public bool Ack(bool mulitple = false) { if (isAck) { Debug.Warning("消息已被确认过,请勿重复确认!"); return false; } isAck = true; return message.Ack(mulitple); } /// /// 是否被拒绝确认 /// /// 是否多条消息 /// 是否重新入列 /// public bool NAck(bool mulitple = false, bool requeue = false) { if (isAck) { Debug.Warning("消息已被确认过,请勿重复确认!"); return false; } isAck = true; return message.NAck(mulitple, requeue); } /// /// 清空数据 /// internal void Clear() { MessagePool.PutMessage(ref message); isAck = false; step = 0; isAdd = false; this.head = null; this.jsondata = null; this.pms = null; this.task = null; int len = datas.Length; for (int i = 0; i < len; i++) { datas[i] = null; } } /// /// /// public WaitBeMsg() { //this.message = msg; //jsondata = JsonPack.GetPackHead(msg.bodystr, out head); } ///// ///// ///// ///// ///// //public WaitBeMsg(BasicGetResult msg, bool ack) { // this.deliverytag = msg.DeliveryTag; // jsonmessage = Encoding.UTF8.GetString(msg.Body); // jsondata = JsonPack.GetPackHead(jsonmessage, out head); // this.exchange = msg.Exchange; // this.routingKey = msg.Exchange; // this.ack = ack; //} ///// ///// ///// ///// ///// ///// ///// ///// //public WaitBeMsg(ulong deliverytag, byte[] body, string exchange, string routingkey, bool ack) { // this.deliverytag = deliverytag; // jsonmessage = Encoding.UTF8.GetString(body); // jsondata = JsonPack.GetPackHead(jsonmessage, out head); // this.exchange = exchange; // this.routingKey = routingkey; // this.ack = ack; //} } }