コード例 #1
0
 public void Send(MessageContainer message)
 {
     var fn = Guid.NewGuid().ToString("N") + ".json";
     using (var sw = new StreamWriter(fn, false, Encoding.UTF8))
     {
         sw.Write(JsonConvert.SerializeObject(message));
     }
 }
コード例 #2
0
ファイル: MessageBus.cs プロジェクト: eyusky/nginn-messagebus
        void _transport_OnMessageToUnknownDestination(MessageContainer message, IMessageTransport transport)
        {
            string dest = message.To;

            log.Debug("Message to remote destination {0}", dest);
            Uri               uri = new Uri(dest);
            string            sn  = string.Format("MessageTransport_{0}", uri.Scheme);
            IMessageTransport mt  = ServiceLocator.GetInstance <IMessageTransport>(sn);

            if (mt == null)
            {
                throw new Exception("No message transport configured for destination " + dest);
            }
            mt.Send(message);
        }
コード例 #3
0
 void httpTransport_OnMessageArrived(MessageContainer message, IMessageTransport transport)
 {
     if (message.RetryCount > 0)
     { //we don't check if already received if message is sent for the first time
         if (ReceivedMessageRegistry.HasBeenReceived(message.UniqueId))
         {
             log.Warn("Message {0} has already been received. Ignoring", message.UniqueId);
             return;
         }
     }
     log.Info("Forwarding incoming http message {0} (from {1}) to {2}", message, message.From, _bus.Endpoint);
     message.To = _bus.Endpoint;
     _bus.Send(message);
     ReceivedMessageRegistry.RegisterReceived(message.UniqueId);
 }
コード例 #4
0
 void httpTransport_OnMessageArrived(MessageContainer message, IMessageTransport transport)
 {
     if (message.RetryCount > 0)
     { //we don't check if already received if message is sent for the first time
         if (ReceivedMessageRegistry.HasBeenReceived(message.UniqueId))
         {
             log.Warn("Message {0} has already been received. Ignoring", message.UniqueId);
             return;
         }
     }
     log.Info("Forwarding incoming http message {0} (from {1}) to {2}", message, message.From, _bus.Endpoint);
     message.To = _bus.Endpoint;
     _bus.Send(message);
     ReceivedMessageRegistry.RegisterReceived(message.UniqueId);
 }
コード例 #5
0
 public void Send(MessageContainer message)
 {
     try
     {
         WebClient    wc = new WebClient();
         StringWriter sw = new StringWriter();
         message.From = this.Endpoint;
         _ser.Serialize(sw, message);
         string ret = wc.UploadString(message.To, sw.ToString());
     }
     catch (Exception ex)
     {
         log.Error("Error sending message {0}: {1}", message, ex);
         throw;
     }
 }
コード例 #6
0
 public void Send(MessageContainer message)
 {
     try
     {
         WebClient wc = new WebClient();
         StringWriter sw = new StringWriter();
         message.From = this.Endpoint;
         _ser.Serialize(sw, message);
         string ret = wc.UploadString(message.To, sw.ToString());
     }
     catch (Exception ex)
     {
         log.Error("Error sending message {0}: {1}", message, ex);
         throw;
     }
 }
コード例 #7
0
        public object Clone()
        {
            MessageContainer mc = new MessageContainer();

            mc.From = this.From;
            mc.To   = this.To;
            if (Cc != null)
            {
                mc.Cc = new List <string>(this.Cc);
            }
            if (this.Headers != null)
            {
                mc.Headers = new Dictionary <string, string>(this.Headers);
            }
            mc.Body    = this.Body;
            mc.BodyStr = this.BodyStr;
            return(mc);
        }
コード例 #8
0
        public MessagePreprocessResult HandleIncomingMessage(MessageContainer message, IMessageTransport transport)
        {
            log.Info("Preprocessing message: {0}", message.BodyStr);
            var m = typeRe.Match(message.BodyStr);
            if (!m.Success)
            {
                log.Warn("Did not match message type. Ignoring the message!");
                return MessagePreprocessResult.CancelFurtherProcessing;
            }
            string mtype = m.Groups[1].Captures[0].Value;
            int idx = mtype.IndexOf(',');
            if (idx > 0) mtype = mtype.Substring(0, idx);
            log.Info("Message type is {0}", mtype);
            if (mtype.StartsWith("NGinnBPM.MessageBus.Messages"))
            {
                log.Info("It's a control message so we process it as usual");
                return MessagePreprocessResult.ContinueProcessing;
            }
            List<MessageContainer> messages = new List<MessageContainer>();
            //now get destination endpoints from the subscribers database
            //and prepare a message clone for each destination
            List<string> destinations = new List<string>();
            foreach (string typeName in new string[] { mtype, "System.Object" })
            {
                foreach (string destination in SubscriptionManager.GetTargetEndpoints(typeName))
                {
                    if (!destinations.Contains(destination)) destinations.Add(destination);
                }
            }
            foreach (string destination in destinations)
            {
                var msg = message.Clone() as MessageContainer;
                msg.To = destination; //set destination. We don't update msg.From so the original endpoint is unchanged
                messages.Add(msg);
            }

            if (messages.Count > 0)
            {
                //send messages to their destinations
                transport.SendBatch(messages, MessageBusContext.ReceivingConnection);
                log.Info("Sent message to {0} destinations", messages.Count);
            }
            return MessagePreprocessResult.CancelFurtherProcessing;
        }
コード例 #9
0
ファイル: MessageBus.cs プロジェクト: eyusky/nginn-messagebus
        void _transport_OnMessageArrived(MessageContainer message, IMessageTransport transport)
        {
            Debug.Assert(message.BodyStr != null && message.Body == null);
            List <IPreprocessMessages> callbacks = null;
            MessagePreprocessResult    disp      = PreprocessIncomingMessage(message, transport, out callbacks);

            if (disp == MessagePreprocessResult.CancelFurtherProcessing)
            {
                return;
            }
            Exception e2 = null;

            try
            {
                DeserializeMessage(message);
                Debug.Assert(message.Body != null);
                DispatchIncomingMessage(message);
            }
            catch (Exception ex)
            {
                e2 = ex;
                throw;
            }
            finally
            {
                if (callbacks != null)
                {
                    callbacks.Reverse();
                    callbacks.ForEach(x => {
                        try
                        {
                            x.AfterMessageProcessed(message, this, this._transport, e2);
                        }
                        catch (Exception e3)
                        {
                            log.Warn("Callback error: {0}", e3);
                        }
                    });
                }
            }
        }
コード例 #10
0
        public string Serialize(MessageContainer mc)
        {
            if (string.IsNullOrEmpty(mc.BodyStr))
            {
                if (mc.Body != null)
                {
                    var sw = new StringWriter();
                    _ser.Serialize(sw, mc.Body);
                    if (!EmbedMessageTypeInBody)
                    {
                        mc.SetHeader(MessageContainer.HDR_MessageType, TypeToString(mc.Body.GetType()));
                    }
                    mc.BodyStr = sw.ToString();
                    mc.Body    = null;
                }
            }
            var sw2 = new StringWriter();

            _ser.Serialize(sw2, mc);
            return(sw2.ToString());
        }
コード例 #11
0
        public string Serialize(MessageContainer mc)
        {
            if (string.IsNullOrEmpty(mc.BodyStr))
            {
                if (mc.Body != null)
                {

                    var sw = new StringWriter();
                    _ser.Serialize(sw, mc.Body);
                    if (!EmbedMessageTypeInBody)
                    {
                        mc.SetHeader(MessageContainer.HDR_MessageType, TypeToString(mc.Body.GetType()));
                    }
                    mc.BodyStr = sw.ToString();
                    mc.Body = null;
                }
            }
            var sw2 = new StringWriter();
            _ser.Serialize(sw2, mc);
            return sw2.ToString();
        }
コード例 #12
0
ファイル: MessageBus.cs プロジェクト: eyusky/nginn-messagebus
        public void Send(string destination, object[] msgs)
        {
            foreach (var msg in msgs)
            {
                Dispatcher.DispatchMessageToOutgoingMessageHandlers(msg, this);
            }
            if (destination == null)
            {
                destination = Endpoint;
            }
            List <MessageContainer> lst = new List <MessageContainer>();

            foreach (object obj in msgs)
            {
                MessageContainer mc = new MessageContainer();
                mc.From     = MessageTransport.Endpoint;
                mc.To       = destination;
                mc.UniqueId = CreateNewMessageUniqueId();
                mc.Body     = obj;
                lst.Add(mc);
            }
            SendMessages(lst, null);
        }
コード例 #13
0
        internal void HandleIncomingMessage(TextReader input)
        {
            MessageContainer mc = null;

            try
            {
                JsonReader jsr = new JsonTextReader(input);
                mc = _ser.Deserialize <MessageContainer>(jsr);
                if (mc.To == null || mc.To.Length == 0)
                {
                    mc.To = Endpoint;
                }
                if (OnMessageArrived != null)
                {
                    OnMessageArrived(mc, this);
                }
            }
            catch (Exception ex)
            {
                log.Error("Error handling incoming message: {0}", ex);
                throw;
            }
        }
コード例 #14
0
ファイル: MessageBus.cs プロジェクト: eyusky/nginn-messagebus
        protected virtual MessagePreprocessResult PreprocessIncomingMessage(MessageContainer mc, IMessageTransport t, out List <IPreprocessMessages> callbacks)
        {
            List <IPreprocessMessages> callb = null;

            callbacks = callb;
            //todo: allow for ordering of message preprocessors
            foreach (IPreprocessMessages pm in this.ServiceLocator.GetAllInstances <IPreprocessMessages>())
            {
                ServiceLocator.ReleaseInstance(pm);
                var res = pm.HandleIncomingMessage(mc, this, t);
                if (callb == null)
                {
                    callb = new List <IPreprocessMessages>();
                }
                callb.Add(pm);
                if (res != MessagePreprocessResult.ContinueProcessing)
                {
                    return(res);
                }
            }
            callbacks = callb;
            return(MessagePreprocessResult.ContinueProcessing);
        }
コード例 #15
0
ファイル: MessageBus.cs プロジェクト: eyusky/nginn-messagebus
 /// <summary>
 /// This method dispatches the message directly to their handlers (local only)
 /// without persisting it in database and in a non-transactional way.
 /// Effectively bypasses NGinn MessageBus, just forwards the message to handler components
 /// </summary>
 /// <param name="mc"></param>
 internal void DispatchLocalNonPersistentMessage(MessageContainer mc, DeliveryMode mode)
 {
     if (mc.To != Endpoint)
     {
         throw new Exception("Local only please");
     }
     if (mc.From != Endpoint)
     {
         throw new Exception("Local only please");
     }
     if (mc.DeliverAt > DateTime.Now)
     {
         throw new Exception("Delivery date unsupported");
     }
     if (mc.Cc != null)
     {
         foreach (string s in mc.Cc)
         {
             if (s != Endpoint)
             {
                 throw new Exception("Non-local endpoint on cc");
             }
         }
     }
     if (mode == DeliveryMode.LocalAsync)
     {
         System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(delegate(object v)
         {
             DispatchLocal(mc, mode);
         }));
     }
     else
     {
         DispatchLocal(mc, mode);
     }
 }
コード例 #16
0
ファイル: MessageBus.cs プロジェクト: eyusky/nginn-messagebus
        public void Publish()
        {
            mc.To = mbus.Endpoint;
            if (_deliveryMode != DeliveryMode.DurableAsync)
            {
                foreach (object body in _bodies)
                {
                    mc.Body = body;
                    mbus.DispatchLocalNonPersistentMessage(mc, _deliveryMode);
                }
            }
            else
            {
                List <MessageContainer> l = new List <MessageContainer>();
                foreach (object body in _bodies)
                {
                    MessageContainer mc2 = mc.Clone() as MessageContainer;
                    mc2.Body = body;
                    l.Add(mc2);
                }

                mbus.NotifyAndDistributeMessages(l, _dbTran);
            }
        }
コード例 #17
0
 public void Send(MessageContainer message)
 {
     if (string.IsNullOrEmpty(message.BodyStr)) throw new Exception("BodyStr");
     var db = OpenDatabase(_connStringAlias);
     db.GetCollection(_collectionName).Insert(Wrap(message));
     _waiter.Set();
 }
コード例 #18
0
 protected virtual void DeserializeMessage(MessageContainer mc)
 {
     Debug.Assert(mc.Body == null);
     mc.Body = this.MessageSerializer.Deserialize(new StringReader(mc.BodyStr));
 }
コード例 #19
0
 internal CurMsg(MessageContainer mc)
 {
     Message = mc;
     DeliveryMode = DeliveryMode.DurableAsync;
 }
コード例 #20
0
 /// <summary>
 /// Alternative version that selects & updates the row in a single query.
 /// However, the testing has shown that it's actually slower than the original, two-query, version
 /// I'm leaving it here to remember that this has already been tried and failed.
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="retryTime"></param>
 /// <returns></returns>
 private MessageContainer SelectNextMessageForProcessing2008(IDbConnection conn, out DateTime? retryTime)
 {
     var mc = new MessageContainer();
     retryTime = null;
     using (var cmd = conn.CreateCommand())
     {
         cmd.CommandText = string.Format(@"UPDATE TOP(1) {0} with(readpast)
             SET subqueue = 'X', last_processed = getdate()
             OUTPUT
              inserted.id, inserted.from_endpoint, inserted.to_endpoint, inserted.retry_count, inserted.retry_time, inserted.correlation_id, inserted.msg_text, inserted.msg_headers, inserted.unique_id
             WHERE
             id in (select top(1) id from {0} with(readpast) where subqueue = 'I' order by retry_time)", _queueTable);
         using (var dr = cmd.ExecuteReader())
         {
             if (!dr.Read()) return null;
             mc.From = Convert.ToString(dr["from_endpoint"]);
             mc.To = Convert.ToString(dr["to_endpoint"]);
             mc.HeadersString = Convert.ToString(dr["msg_headers"]);
             mc.SetHeader(MessageContainer.HDR_RetryCount, Convert.ToInt32(dr["retry_count"]).ToString()); ;
             mc.CorrelationId = Convert.ToString(dr["correlation_id"]);
             mc.BusMessageId = Convert.ToString(dr["id"]);
             mc.UniqueId = Convert.ToString(dr["unique_id"]);
             retryTime = Convert.ToDateTime(dr["retry_time"]);
             mc.BodyStr = dr.GetString(dr.GetOrdinal("msg_text"));
         }
     }
     return mc;
 }
コード例 #21
0
 public void Send(MessageContainer message)
 {
     List<MessageContainer> lst = new List<MessageContainer>();
     lst.Add(message);
     SendBatch(lst, null);
 }
コード例 #22
0
 public void Send(string destination, object[] msgs)
 {
     foreach (var msg in msgs)
     {
         Dispatcher.DispatchMessageToOutgoingMessageHandlers(msg, this);
     }
     if (destination == null)
         destination = Endpoint;
     List<MessageContainer> lst = new List<MessageContainer>();
     foreach (object obj in msgs)
     {
         MessageContainer mc = new MessageContainer();
         mc.From = MessageTransport.Endpoint;
         mc.To = destination;
         mc.UniqueId = CreateNewMessageUniqueId();
         mc.Body = obj;
         lst.Add(mc);
     }
     SendMessages(lst, null);
 }
コード例 #23
0
 internal CurMsgInfo(MessageContainer mc)
 {
     Message = mc;
 }
コード例 #24
0
 private void DispatchLocal(MessageContainer mc, DeliveryMode dm)
 {
     var pm = _currentMessage;
     var mb = MessageBusContext.CurrentMessageBus;
     try
     {
         _currentMessage = new CurMsg(mc);
         MessageBusContext.CurrentMessageBus = this;
         _currentMessage.DeliveryMode = dm;
         Dispatcher.DispatchMessage(mc.Body, this);
     }
     catch (Exception ex)
     {
         log.Warn("Error async processing message {0}: {1}", mc.BusMessageId, ex.ToString());
         if (dm != DeliveryMode.LocalAsync)
         {
             throw;
         }
     }
     finally
     {
         _currentMessage = pm;
         MessageBusContext.CurrentMessageBus = mb;
     }
 }
コード例 #25
0
 private void Notify(object[] msgs, DeliveryMode mode)
 {
     foreach (var msg in msgs)
     {
         Dispatcher.DispatchMessageToOutgoingMessageHandlers(msg, this);
     }
     List<MessageContainer> lst = new List<MessageContainer>();
     foreach (Object obj in msgs)
     {
         MessageContainer mc = new MessageContainer();
         mc.From = Endpoint;
         mc.To = Endpoint;
         mc.Body = obj;
         mc.UniqueId = CreateNewMessageUniqueId();
         lst.Add(mc);
     }
     if (mode == DeliveryMode.DurableAsync)
     {
         NotifyAndDistributeMessages(lst, null);
     }
     else
     {
         lst.ForEach(mc => this.DispatchLocalNonPersistentMessage(mc, mode));
     }
 }
コード例 #26
0
        public static void TestQueueOps()
        {
            AccessOraDb(null, con => {
                            var qt ="mq_test2";
                            var qops = SqlHelper.GetQueueOps(SqlHelper.GetDialect(con.GetType()));
                            qops.CleanupProcessedMessages(con, qt, null);
                            qops.MoveScheduledMessagesToInputQueue(con, qt);

                            var mc = new MessageContainer {
                                Body = "ala ma kota",
                                From = "sql://oradb/mq_test2",
                                To = "sql://oradb/mq_test2",
                                Label = "lbl",
                                BodyStr = "a tu takki kot",
                                HeadersString = null
                            };
                            var msgs = new Dictionary<string, ICollection<MessageContainer>> {
                                {"mq_test2", new List<MessageContainer>{mc }}
                            };
                            qops.InsertMessageBatchToLocalDatabaseQueues(con, msgs);

                            DateTime? rt;
                            bool more;
                            mc = qops.SelectAndLockNextInputMessage(con, qt, () => new string[] {}, out rt, out more);
                            log.Info("MC: {0}", mc == null ? " - nul - " : mc.BusMessageId);
            });
        }
コード例 #27
0
 void _transport_OnMessageArrived(MessageContainer message, IMessageTransport transport)
 {
     Debug.Assert(message.BodyStr != null && message.Body == null);
     List<IPreprocessMessages> callbacks = null;
     MessagePreprocessResult disp = PreprocessIncomingMessage(message, transport, out callbacks);
     if (disp == MessagePreprocessResult.CancelFurtherProcessing)
     {
         return;
     }
     Exception e2 = null;
     try
     {
         DeserializeMessage(message);
         Debug.Assert(message.Body != null);
         DispatchIncomingMessage(message);
     }
     catch (Exception ex)
     {
         e2 = ex;
         throw;
     }
     finally
     {
         if (callbacks != null)
         {
             callbacks.Reverse();
             callbacks.ForEach(x => {
                 try
                 {
                     x.AfterMessageProcessed(message, this, this._transport, e2);
                 }
                 catch (Exception e3)
                 {
                     log.Warn("Callback error: {0}", e3);
                 }
             });
         }
     }
 }
コード例 #28
0
ファイル: MessageBus.cs プロジェクト: eyusky/nginn-messagebus
 protected virtual void DeserializeMessage(MessageContainer mc)
 {
     Debug.Assert(mc.Body == null);
     mc.Body = this.MessageSerializer.Deserialize(new StringReader(mc.BodyStr));
 }
コード例 #29
0
 public NewMessageFluent(MessageBus bus)
 {
     mbus = bus;
     mc = new MessageContainer();
     mc.From = mbus.Endpoint;
 }
コード例 #30
0
        protected MessageContainer Unwrap(MongoMessageWrapper m)
        {
            var mc = new MessageContainer();
            mc.Headers = new Dictionary<string, string>();
            if (m.Headers != null)
            {
                foreach (string s in m.Headers.Keys)
                {
                    mc.SetHeader(s, m.Headers[s]);
                }
            }

            mc.BodyStr = m.Payload;
            mc.BusMessageId = m._id.ToString();
            mc.RetryCount = m.RetryCount;
            mc.From = m.From;
            mc.To = m.To;

            return mc;
        }
コード例 #31
0
        protected MongoMessageWrapper Wrap(MessageContainer mc)
        {
            var mw = new MongoMessageWrapper
            {
                From = string.IsNullOrEmpty(mc.From) ? this.Endpoint : mc.From,
                To = mc.To,
                InsertTime = DateTime.Now,
                RetryCount = 0,
                RetryTime = mc.DeliverAt,
                SubQueue = "I",
                Payload = mc.BodyStr
            };
            var hl = MongoMessageWrapper.GetSkipHeaderNames();
            if (mc.Headers != null && mc.Headers.Any(x => !hl.Contains(x.Key)))
            {
                mw.Headers = new Dictionary<string, string>();
                foreach (string k in mc.Headers.Keys)
                {
                    if (!hl.Contains(k)) mw.Headers[k] = mc.Headers[k];
                }
            }

            return mw;
        }
コード例 #32
0
ファイル: MessageBus.cs プロジェクト: eyusky/nginn-messagebus
 public NewMessageFluent(MessageBus bus)
 {
     mbus    = bus;
     mc      = new MessageContainer();
     mc.From = mbus.Endpoint;
 }
コード例 #33
0
 /// <summary>
 /// This method dispatches the message directly to their handlers (local only)
 /// without persisting it in database and in a non-transactional way.
 /// Effectively bypasses NGinn MessageBus, just forwards the message to handler components
 /// </summary>
 /// <param name="mc"></param>
 internal void DispatchLocalNonPersistentMessage(MessageContainer mc, DeliveryMode mode)
 {
     if (mc.To != Endpoint) throw new Exception("Local only please");
     if (mc.From != Endpoint) throw new Exception("Local only please");
     if (mc.DeliverAt > DateTime.Now) throw new Exception("Delivery date unsupported");
     if (mc.Cc != null)
     {
         foreach (string s in mc.Cc) if (s != Endpoint) throw new Exception("Non-local endpoint on cc");
     }
     if (mode == DeliveryMode.LocalAsync)
     {
         System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(delegate(object v)
         {
             DispatchLocal(mc, mode);
         }));
     }
     else
     {
         DispatchLocal(mc, mode);
     }
 }
コード例 #34
0
 protected virtual MessagePreprocessResult PreprocessIncomingMessage(MessageContainer mc, IMessageTransport t, out List<IPreprocessMessages> callbacks)
 {
     List<IPreprocessMessages> callb = null;
     callbacks = callb;
     //todo: allow for ordering of message preprocessors
     foreach (IPreprocessMessages pm in this.ServiceLocator.GetAllInstances<IPreprocessMessages>())
     {
         ServiceLocator.ReleaseInstance(pm);
         var res = pm.HandleIncomingMessage(mc, this, t);
         if (callb == null) callb = new List<IPreprocessMessages>();
         callb.Add(pm);
         if (res != MessagePreprocessResult.ContinueProcessing) return res;
     }
     callbacks = callb;
     return MessagePreprocessResult.ContinueProcessing;
 }
コード例 #35
0
 /// <summary>
 /// Forwards message to a remote endpoint
 /// </summary>
 /// <param name="mc"></param>
 protected virtual void ForwardMessageToRemoteEndpoint(MessageContainer mc)
 {
     if (mc.To.StartsWith("sql://"))
     {
         string alias, table;
         if (!SqlUtil.ParseSqlEndpoint(mc.To, out alias, out table))
             throw new Exception("Invalid target endpoint: " + mc.To);
         List<MessageContainer> l = new List<MessageContainer>();
         l.Add(mc);
         var d = new Dictionary<string, ICollection<MessageContainer>>();
         d[table] = l;
         var cs = GetConnectionString(alias);
         if (cs == null) throw new Exception("Unknown connection string alias: " + alias);
         InsertMessageBatchToLocalDatabaseQueues(cs, d);
     }
     else
     {
         if (OnMessageToUnknownDestination != null)
         {
             OnMessageToUnknownDestination(mc, this);
         }
         else throw new Exception("Don't know how to send message to destination: " + mc.To);
     }
 }
コード例 #36
0
ファイル: MessageBus.cs プロジェクト: eyusky/nginn-messagebus
 internal CurMsg(MessageContainer mc)
 {
     Message      = mc;
     DeliveryMode = DeliveryMode.DurableAsync;
 }
コード例 #37
0
 internal CurMsgInfo(MessageContainer mc)
 {
     Message = mc;
 }
コード例 #38
0
 /// <summary>
 /// Deliver the message to handlers
 /// </summary>
 /// <param name="mc"></param>
 protected virtual void DispatchIncomingMessage(MessageContainer mc)
 {
     log.Debug("MB {2} Dispatching incoming message {0}/{1}/{3}", mc.To, mc.BusMessageId, this.Endpoint, mc.Body.GetType().Name);
     try
     {
         MessageBusContext.CurrentMessageBus = this;
         _currentMessage = new CurMsg(mc);
         if (UseTransactionScope && Transaction.Current == null)
         {
             TransactionOptions to = new TransactionOptions();
             to.IsolationLevel = IsolationLevel.ReadCommitted;
             to.Timeout = TimeSpan.FromSeconds(30);
             TransactionScopeOption tso = MessageHandlerTransactionScopeOption;
             using (TransactionScope ts = new TransactionScope(tso, to))
             {
                 Dispatcher.DispatchMessage(mc.Body, this);
                 ts.Complete();
             }
         }
         else
         {
             Dispatcher.DispatchMessage(mc.Body, this);
         }
     }
     finally
     {
         _currentMessage = null;
         MessageBusContext.CurrentMessageBus = null;
     }
 }
コード例 #39
0
 public object Clone()
 {
     MessageContainer mc = new MessageContainer();
     mc.From = this.From;
     mc.To = this.To;
     if (Cc != null)
         mc.Cc = new List<string>(this.Cc);
     if (this.Headers != null) mc.Headers = new Dictionary<string, string>(this.Headers);
     mc.Body = this.Body;
     mc.BodyStr = this.BodyStr;
     return mc;
 }
コード例 #40
0
 void _transport_OnMessageToUnknownDestination(MessageContainer message, IMessageTransport transport)
 {
     string dest = message.To;
     log.Debug("Message to remote destination {0}", dest);
     Uri uri = new Uri(dest);
     string sn = string.Format("MessageTransport_{0}", uri.Scheme);
     IMessageTransport mt = ServiceLocator.GetInstance<IMessageTransport>(sn);
     if (mt == null) throw new Exception("No message transport configured for destination " + dest);
     mt.Send(message);
 }