Пример #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 TestMessageCreateSimple()
        {
            var messageString = TextMessageUtil.CreateMessage("TestTopic", "fieldNameOne", "fieldValueOne");

            Assert.AreEqual(true, messageString.Contains("MSTimestamp"));
            Assert.AreEqual(true, messageString.Contains("MSTopicName"));
            Assert.AreEqual(true, messageString.Contains("TestTopic"));
            Assert.AreEqual(true, messageString.Contains("fieldNameOne"));
            Assert.AreEqual(true, messageString.Contains("fieldValueOne"));
        }
Пример #3
0
        public void TestHandleMessage()
        {
            var handler         = new TopicHandler(ReceivedMessage);
            var testTextMessage = new MockTextMessage("Test.Topic");
            var testMessage     = TextMessageUtil.CreateMessage("Test.Topic", "FieldName", "FieldValue");

            testTextMessage.Text = testMessage;
            testTextMessage.Properties.SetString("BrokerUrl", "tcp://localhost:60606");

            handler.OnMessageHandler(testTextMessage);
        }
Пример #4
0
        protected static string PublishTestMessage(Broker broker, string testTopic, IDictionary <string, string> message)
        {
            var session     = broker.Connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
            var producer    = session.CreateProducer(session.GetTopic(testTopic));
            var messageBody = TextMessageUtil.CreateMessage(testTopic, message);
            var textMessage = producer.CreateTextMessage(messageBody);

            producer.Send(textMessage);

            return(textMessage.NMSMessageId);
        }
Пример #5
0
        public void TestMessageCreate()
        {
            IDictionary <string, string> testMessage = new SortedDictionary <string, string> {
                { "fieldNameOne", "fieldValueOne" },
                { "fieldNameTwo", "fieldValueTwo" },
                { "fieldNameThree", "fieldValueThree" },
                { "fieldNameFour", "fieldValueFour" }
            };

            var messageString = TextMessageUtil.CreateMessage(testMessage);

            Assert.AreEqual(MessageString, messageString.Substring(0, 113));
            Assert.AreEqual(true, messageString.Contains("MSTimestamp"));
        }
Пример #6
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"));
        }