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 + "]消费请求失败!"); } } } }
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)); } } } }
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 + "]的订阅型消息的订阅请求!"); } } } }