示例#1
0
        /// <summary>
        /// The subscriber has added the BrokerURL as a property (BrokerUrl).
        /// </summary>
        /// <param name="message"></param>
        public void OnMessageHandler(IMessage message)
        {
            var textMessage = message as ITextMessage;

            if (textMessage == null)
            {
                return;
            }

            var brokerUrl     = textMessage.Properties.GetString("BrokerUrl");
            var parsedMessage = TextMessageUtil.ExtractRecord(textMessage.Text);
            var destination   = textMessage.NMSDestination;
            var topic         = destination.ToString();

            // remove the 'topic://'
            if (destination.IsTopic)
            {
                topic = topic.Substring(8);
            }

            parsedMessage.Add("TopicName", topic);
            parsedMessage.Add("BrokerUrl", brokerUrl);


            _changed(this, new TopicUpdateEvent(parsedMessage));
        }
示例#2
0
        public void TestMessageExtract()
        {
            var testMessage = TextMessageUtil.ExtractRecord(MessageString);

            Assert.AreEqual(4, testMessage.Count);
            Assert.AreEqual(true, testMessage.Keys.Contains("fieldNameOne"));
            Assert.AreEqual(true, testMessage.Keys.Contains("fieldNameTwo"));
            Assert.AreEqual(true, testMessage.Keys.Contains("fieldNameThree"));
            Assert.AreEqual(true, testMessage.Keys.Contains("fieldNameFour"));
            Assert.AreEqual(false, testMessage.Keys.Contains("MSTimestamp"));
            Assert.AreEqual(false, testMessage.Keys.Contains("MSTopicName"));

            Assert.AreEqual(true, testMessage.Values.Contains("fieldValueOne"));
            Assert.AreEqual(true, testMessage.Values.Contains("fieldValueTwo"));
            Assert.AreEqual(true, testMessage.Values.Contains("fieldValueThree"));
            Assert.AreEqual(true, testMessage.Values.Contains("fieldValueFour"));
        }