static void BroadcastEvent2_Received(object sender, BroadcastEventArgs arg) { if (Received2 != null) { Received2(arg.Client, arg.Data); } if (arg.Data != null) { ClonableObject msg = Common.GetMsgClonable <ClonableObject>(arg.Data); if (msg != null) { if (mq.Insert(msg)) { Console.WriteLine("接收到来自客户端[" + arg.Client + "]的消费型消息:" + msg.GetHashCode() + ",并插入队列成功!"); } else { Console.WriteLine("接收到来自客户端[" + arg.Client + "]的消费型消息:" + msg.GetHashCode() + ",但插入队列失败!"); } } else { string clientId = Common.GetString(arg.Data, 0, Encoding.UTF8); if (clientId != null) { Console.WriteLine("接收到来自客户端[" + clientId + "]的消费型消息的消费请求!"); //List<KellPersistence.Data<ClonableObject>> msgs = mq.Query(clientId); //if (mq.Reply(arg, msgs)) // Console.WriteLine("回复客户端[" + clientId + "]消费请求成功!"); //else // Console.WriteLine("回复客户端[" + clientId + "]消费请求失败!"); } } } }
public void SubscribeHanler(object sender, BroadcastEventArgs e) { if (Subscribe != null) { ClonableObject msg = Common.GetMsgClonable <ClonableObject>(e.Data); Subscribe(e.Client, msg); } }
static void BroadcastEvent_Received(object sender, BroadcastEventArgs arg) { if (Received != null) { Received(arg.Client, arg.Data); } if (arg.Data != null) { ClonableObject msg = Common.GetMsgClonable <ClonableObject>(arg.Data); if (msg != null) { ev.Enqueue(msg); Console.WriteLine("接收到来自客户端[" + arg.Client + "]的订阅型消息:" + msg.GetHashCode() + ",并插入队列成功!"); } else { string clientId = Common.GetString(arg.Data, 0, Encoding.UTF8); if (clientId != null) { Console.WriteLine("接收到客户端[" + clientId + "]的订阅型消息的订阅请求!"); } } } }
void send_Subscribe(IPEndPoint client, ClonableObject msg) { IPEndPoint ep = client as IPEndPoint; if (ep != null) { if (msg != null) { Logs.Create("消息[" + msg.GetHashCode() + "]已从消息队列[" + ep.Address + "]中消费掉!"); if (Submited != null) { Submited(this, new ClonableMessageArgs(msg.GetHashCode())); } } else { Logs.Create("无法确定消息是否已从消息队列[" + ep.Address + "]中消费掉,返回的值为空!"); if (Submited != null) { Submited(this, new ClonableMessageArgs(0)); } } } }
public bool Insert(ClonableObject msg) { return(trunk.Insert(new KellPersistence.Data <ClonableObject>(trunk, msg))); }
/// <summary> /// 构造函数 /// </summary> /// <param name="ep"></param> /// <param name="msg"></param> public EndPointWrapClonable(EndPoint ep, ClonableObject msg) { this.ep = ep; this.msg = msg; }