/// <summary>
        /// OnMessageReceived - beim messageConsumer registrierte Callback-Methode,
        /// wird bei Empfang einer neuen Nachricht vom messageConsumer aufgerufen.
        /// Informiert alle angemeldeten Observer über empfangene ITextMessages.
        /// </summary>
        /// <param name="msg"></param>
        public void OnMessageReceived(IMessage msg)
        {
            if (msg is ITextMessage)
            {
                ITextMessage tm = msg as ITextMessage;
                AddLogMessage("ACTIVEMQ-TextMessage: ID=" + tm.GetType() + "\n" + tm.Text);

                bool publisherContained = false;
                bool mqEventContained   = false;
                foreach (string key in tm.Properties.Keys)
                {
                    AddLogMessage("actKey ist: " + key);
                    if (key == "Publisher")
                    {
                        publisherContained = true;
                    }
                    else if (key == "Action")
                    {
                        mqEventContained = true;
                    }
                }


                if (publisherContained && mqEventContained)
                {
                    object sessionId     = tm.Properties["Publisher"];
                    object mqEvent       = tm.Properties["Action"];
                    long   publisher     = Int64.Parse(sessionId.ToString());
                    string mqEventString = mqEvent.ToString();
                    string itemId        = tm.Text;
                    NotifyObservers(itemId, publisher, mqEventString);
                }
                else
                {
                    AddLogMessage("no keys contained");
                }
            }
            else
            {
                AddLogMessage("\nAnderer Message-Typ: " + msg);
            }
        }
示例#2
0
        // OnMessageReceived - beim messageConsumer registrierte Callback-Methode,
        // wird bei Empfang einer neuen Nachricht vom messageConsumer aufgerufen
        public void OnMessageReceived(IMessage msg)
        {
            if (msg is ITextMessage)
            {
                ITextMessage tm = msg as ITextMessage;
                AddLogMessage("ACTIVEMQ-TextMessage: ID=" + tm.GetType() + "\n" + tm.Text);

                StringBuilder msgbuffer = new StringBuilder();
                msgbuffer.AppendFormat("MapMessage: ID={0}\n", msg.GetType());
                bool publisherContained = false;
                bool mqEventContained   = false;
                foreach (string key in tm.Properties.Keys)
                {
                    AddLogMessage("actKey ist: " + key);
                    msgbuffer.AppendFormat("  - Property '{0}' = {1}\n", key, tm.Properties[key]);
                    if (key == "Publisher")
                    {
                        publisherContained = true;
                    }
                    else if (key == "Action")
                    {
                        mqEventContained = true;
                    }
                }

                AddLogMessage(msgbuffer.ToString());

                if (publisherContained && mqEventContained)
                {
                    object sessionId     = tm.Properties["Publisher"];
                    object mqEvent       = tm.Properties["Action"];
                    long   publisher     = Int64.Parse(sessionId.ToString());
                    string mqEventString = mqEvent.ToString();
                    string itemId        = tm.Text;
                    NotifyObservers(itemId, publisher, mqEventString);
                }
                else
                {
                    Console.WriteLine("no keys contained");
                }
            }
            else if (msg is IMapMessage)
            {
                StringBuilder msgbuffer = new StringBuilder();

                IMapMessage mm = msg as IMapMessage;
                msgbuffer.AppendFormat("MapMessage: ID={0}\n", msg.GetType());
                foreach (string key in mm.Properties.Keys)
                {
                    msgbuffer.AppendFormat("  - Property '{0}' = {1}\n", key, mm.Properties[key]);
                }
                foreach (string key in mm.Body.Keys)
                {
                    msgbuffer.AppendFormat("  - Eintrag '{0}' = {1}\n", key, mm.Body[key]);
                }
                AddLogMessage(msgbuffer.ToString());
            }
            else
            {
                AddLogMessage("\nAnderer Message-Typ: " + msg);
            }
        }