private void NotifyMessage(Message msg) { _log.Write(LogType.Debug, "MSMQReceiver begin to deserializing message."); HYS.IM.Messaging.Objects.Message m = MSMQHelper.GetMessage(msg); if (m == null || m.Header == null) { _log.Write(LogType.Error, "MSMQReceiver receive and abandon a NULL message or message without header."); return; } else { _log.Write(LogType.Debug, "MSMQReceiver receive message id=" + m.Header.ID.ToString()); } NotifyMessageReceived(m); }
public override bool SendMessage(HYS.IM.Messaging.Objects.Message message) { if (message == null || message.Header == null) { _log.Write(LogType.Error, "MSMQSender cannot send NULL message or message without header."); return(false); } string msgIDInfo = "MSMQSender send message id=" + message.Header.ID.ToString(); _log.Write(LogType.Debug, msgIDInfo + " serializing."); string xmlString = message.ToXMLString(); lock (queue) // 20130204 Send() is not thread safe according to msdn. { using (MessageQueueTransaction trans = new MessageQueueTransaction()) { try { _log.Write(LogType.Debug, msgIDInfo + " begin."); trans.Begin(); queue.Send(xmlString, MSMQHelper.GetMessageLabel(message), trans); trans.Commit(); _log.Write(LogType.Debug, msgIDInfo + " end."); return(true); } catch (Exception err) { trans.Abort(); //throw err; _log.Write(LogType.Error, "MSMQSender send message failed."); _log.Write(err); return(false); } } } }