private bool receiver_OnMessageReceived(PullReceiverBase receiver, Message request, out Message response) { DumpHelper.DumpResponserReceivingMessage(_log, request); if (OnPreProcessing != null) { if (!OnPreProcessing(ref request)) { _log.Write(LogType.Warning, string.Format("The pre-processing handler rejected the requesting message (ID: {0}) from coming in.", (request != null) ? request.Header.ID.ToString() : "(null)")); response = null; return(false); } } bool res = _responser.ProcessMessage(receiver.Channel, request, out response); DumpHelper.DumpResponserSendingMessage(_log, response); if (OnPostProcessing != null) { if (!OnPostProcessing(request, ref response)) { _log.Write(LogType.Warning, string.Format("The post-processing handler rejected the responsing message (ID: {0}) from going out.", (response != null) ? response.Header.ID.ToString() : "(null)")); return(false); } } return(res); }
private bool requester_OnMessageRequest(IPullRoute route, Message request, out Message response) { DumpHelper.DumpRequesterSendingMessage(_log, request); if (OnPreProcessing != null) { if (!OnPreProcessing(ref request)) { _log.Write(LogType.Warning, string.Format("The pre-processing handler rejected the requesting message (ID: {0}) from going out.", (request != null) ? request.Header.ID.ToString() : "(null)")); response = null; return(false); } } response = null; bool res = false; if (route != null) { PullSenderBase s = GetPullSender(route); if (s != null) { res = s.SendMessage(request, out response); } } else { foreach (PullSenderBase s in _channels) { res = s.SendMessage(request, out response); if (res) { break; } } } if (!res) { return(res); } DumpHelper.DumpRequesterReceivingMessage(_log, response); if (OnPostProcessing != null) { if (!OnPostProcessing(request, ref response)) { _log.Write(LogType.Warning, string.Format("The post-processing handler rejected the responsing message (ID: {0}) from coming in.", (response != null) ? response.Header.ID.ToString() : "(null)")); return(false); } } return(true); }
private void receiver_OnMessageReceived(PushReceiverBase receiver, Message message) { DumpHelper.DumpSubscriberMessage(_log, message); if (OnProcessing != null) { if (!OnProcessing(ref message)) { _log.Write(LogType.Warning, string.Format("The processing handler rejected the subscribed message (ID: {0}) from coming in.", (message != null) ? message.Header.ID.ToString() : "(null)")); return; } } _subscriber.ReceiveMessage(receiver.Channel, message); }
//private bool Match(string subscriberName, SubscriptionRule desc, Message message) //{ // if (message == null) return false; // if (desc == null || desc.MessageTypeList.Count < 1) // { // _log.Write("[PushSenderAgent] No message type criteria in subscription rule of " + subscriberName + ", route all messages."); // return true; // } // MessageType mt = message.Header.Type; // foreach (MessageType t in desc.MessageTypeList) // { // if (mt.EqualsTo(t)) // { // _log.Write("[PushSenderAgent] Message type " + mt.ToString() + " matched the subscription rule of " + subscriberName + ", route the message."); // return true; // } // } // _log.Write("[PushSenderAgent] Message type " + mt.ToString() + " does not matched the subscription rule of " + subscriberName + ", block the message."); // return false; //} private bool publisher_OnMessagePublish(Message message) { DumpHelper.DumpPublisherMessage(_log, message); if (OnProcessing != null) { if (!OnProcessing(ref message)) { _log.Write(LogType.Warning, string.Format("The processing handler rejected the publishing message (ID: {0}) from going out.", (message != null) ? message.Header.ID.ToString() : "(null)")); return(false); } } if (_channels.Count < 1) { if (_observer != null) { _observer.PublishingMessage(PublishResultType.NoChannel, message, null); } // When there is no subscriber, we define to return true to upper application. // According to publish/subscribe model, publisher "send and forget", // publisher need to ensure send is success. // Therefore if there is subscriber and send failed, we return false. // If there is no subscriber, do nothing is success, so we return true. return(true); } else { bool atLessOneSent = false; foreach (PushSenderBase s in _channels) { if (Match(s.Channel.ReceiverEntityName, s.Channel.Subscription, message)) { if (s.SendMessage(message)) { atLessOneSent = true; // If no channel matched, it also means failure. if (_observer != null) { _observer.PublishingMessage(PublishResultType.SendSucceeded, message, s.Channel); } } else { if (_observer != null) { _observer.PublishingMessage(PublishResultType.SendFailed, message, s.Channel); } //return false; // Any channel failed means failure. } } else { if (_observer != null) { _observer.PublishingMessage(PublishResultType.NotMatched, message, s.Channel); } } } return(atLessOneSent); } }