Пример #1
0
        public void NmsCorrelationIdIgnoredIfIncorrectType()
        {
            IMessage message = MessageBuilder.WithPayload("test").SetHeader(NmsHeaders.CORRELATION_ID, 123).Build();
            DefaultNmsHeaderMapper mapper = new DefaultNmsHeaderMapper();

            Apache.NMS.IMessage nmsMessage = new StubTextMessage();
            mapper.FromHeaders(message.Headers, nmsMessage);
            Assert.That(nmsMessage.NMSCorrelationID, Is.Null);
        }
Пример #2
0
        public void NmsReplyToIgnoredIfIncorrectType()
        {
            IMessage message =
                MessageBuilder.WithPayload("test").SetHeader(NmsHeaders.REPLY_TO, "not-a-destination").Build();
            DefaultNmsHeaderMapper mapper = new DefaultNmsHeaderMapper();

            Apache.NMS.IMessage nmsMessage = new StubTextMessage();
            mapper.FromHeaders(message.Headers, nmsMessage);
            Assert.That(nmsMessage.NMSReplyTo, Is.Null);
        }
Пример #3
0
        public void NmsTypeMappedFromHeader()
        {
            string   nmsType = "testing";
            IMessage message = MessageBuilder.WithPayload("test").SetHeader(NmsHeaders.TYPE, nmsType).Build();
            DefaultNmsHeaderMapper mapper = new DefaultNmsHeaderMapper();

            Apache.NMS.IMessage nmsMessage = new StubTextMessage();
            mapper.FromHeaders(message.Headers, nmsMessage);
            Assert.That(nmsMessage.NMSType, Is.Not.Null);
            Assert.That(nmsType, Is.EqualTo(nmsMessage.NMSType));
        }
Пример #4
0
        public void JmsReplyToMappedFromHeader()
        {
            Apache.NMS.IDestination replyTo = new Apache.NMS.ActiveMQ.Commands.ActiveMQQueue();
            IMessage message = MessageBuilder.WithPayload("test").SetHeader(NmsHeaders.REPLY_TO, replyTo).Build();
            DefaultNmsHeaderMapper mapper = new DefaultNmsHeaderMapper();

            Apache.NMS.IMessage nmsMessage = new StubTextMessage();
            mapper.FromHeaders(message.Headers, nmsMessage);
            Assert.That(nmsMessage.NMSReplyTo, Is.Not.Null);
            Assert.That(replyTo, Is.SameAs(nmsMessage.NMSReplyTo));
        }
Пример #5
0
        public void NmsCorrelationIdMappedFromHeader()
        {
            string   nmsCorrelationId = "ABC-123";
            IMessage message          =
                MessageBuilder.WithPayload("test").SetHeader(NmsHeaders.CORRELATION_ID, nmsCorrelationId).Build();
            DefaultNmsHeaderMapper mapper = new DefaultNmsHeaderMapper();

            Apache.NMS.IMessage nmsMessage = new StubTextMessage();
            mapper.FromHeaders(message.Headers, nmsMessage);
            Assert.That(nmsMessage.NMSCorrelationID, Is.Not.Null);
            Assert.That(nmsCorrelationId, Is.EqualTo(nmsMessage.NMSCorrelationID));
        }
Пример #6
0
        public void UserDefinedPropertyMappedFromHeader()
        {
            IMessage message = MessageBuilder.WithPayload("test").SetHeader("foo", 123).Build();
            DefaultNmsHeaderMapper mapper = new DefaultNmsHeaderMapper();

            Apache.NMS.IMessage nmsMessage = new StubTextMessage();
            mapper.FromHeaders(message.Headers, nmsMessage);
            object value = nmsMessage.Properties["foo"];

            Assert.That(value, Is.Not.Null);
            Assert.That(typeof(int), Is.EqualTo(value.GetType()));
            Assert.That(123, Is.EqualTo(value));
        }
        protected override void HandleRequestMessage(IMessage message, ReplyMessageHolder replyMessageHolder)
        {
            if (!initialized)
            {
                AfterPropertiesSet();
            }
            IMessage requestMessage = MessageBuilder.FromMessage(message).Build();

            try
            {
                Apache.NMS.IMessage nmsReply = SendAndReceive(requestMessage);
            }
            catch (NMSException ex)
            {
                throw new MessageHandlingException(requestMessage, ex);
            }
        }
        private Apache.NMS.IMessage SendAndReceive(IMessage requestMessage)
        {
            IConnection      connection      = CreateConnection();
            ISession         session         = null;
            IMessageProducer messageProducer = null;
            IMessageConsumer messageConsumer = null;
            IDestination     replyTo         = null;

            try
            {
                session = CreateSession(connection);
                Apache.NMS.IMessage jmsRequest = this.messageConverter.ToMessage(requestMessage, session);
                messageProducer = session.CreateProducer(this.GetRequestDestination(session));
                messageProducer.DeliveryMode = deliveryMode;
                messageProducer.Priority     = priority;
                messageProducer.TimeToLive   = timeToLive;
                replyTo = GetReplyDestination(session);
                jmsRequest.NMSReplyTo = replyTo;
                connection.Start();
                messageProducer.Send(jmsRequest);
                if (replyTo is ITemporaryQueue || replyTo is ITemporaryTopic)
                {
                    messageConsumer = session.CreateConsumer(replyTo);
                }
                else
                {
                    String messageId       = jmsRequest.NMSMessageId.Replace("'", "''");
                    String messageSelector = "NMSCorrelationID = '" + messageId + "'";
                    messageConsumer = session.CreateConsumer(replyTo, messageSelector);
                }
                return((TimeSpan.Compare(receiveTimeout, TimeSpan.FromMilliseconds(0)) == 1)
                           ? messageConsumer.Receive(receiveTimeout)
                           : messageConsumer.Receive());
            }
            finally
            {
                NmsUtils.CloseMessageProducer(messageProducer);
                NmsUtils.CloseMessageConsumer(messageConsumer);
                this.DeleteDestinationIfTemporary(session, replyTo);
                NmsUtils.CloseSession(session);

                ConnectionFactoryUtils.ReleaseConnection(connection, this.connectionFactory, true);
            }
        }
Пример #9
0
        public void IllegalArgumentExceptionIsNotFatal()
        {
            IMessage message = MessageBuilder.WithPayload("test")
                               .SetHeader("foo", 123)
                               .SetHeader("bad", 456)
                               .SetHeader("bar", 789)
                               .Build();
            DefaultNmsHeaderMapper mapper     = new DefaultNmsHeaderMapper();
            StubTextMessage        nmsMessage = new StubTextMessage();

            nmsMessage.Properties = new BadPrimitiveMap();
            mapper.FromHeaders(message.Headers, nmsMessage);
            int foo = nmsMessage.Properties.GetInt("foo");

            Assert.That(foo, Is.EqualTo(123));
            int bar = nmsMessage.Properties.GetInt("bar");

            Assert.That(bar, Is.EqualTo(789));
            Assert.That(nmsMessage.Properties.Contains("bad"), Is.False);
        }
        private Apache.NMS.IMessage SendAndReceive(IMessage requestMessage)
        {
            IConnection connection = CreateConnection();
            ISession session = null;
            IMessageProducer messageProducer = null;
            IMessageConsumer messageConsumer = null;
            IDestination replyTo = null;
            try
            {
                session = CreateSession(connection);
                Apache.NMS.IMessage jmsRequest = this.messageConverter.ToMessage(requestMessage, session);
                messageProducer = session.CreateProducer(this.GetRequestDestination(session));
                messageProducer.DeliveryMode = deliveryMode;
                messageProducer.Priority = priority;
                messageProducer.TimeToLive = timeToLive;
                replyTo = GetReplyDestination(session);
                jmsRequest.NMSReplyTo = replyTo;
                connection.Start();
                messageProducer.Send(jmsRequest);
                if (replyTo is ITemporaryQueue || replyTo is ITemporaryTopic)
                {
                    messageConsumer = session.CreateConsumer(replyTo);
                }
                else
                {
                    String messageId = jmsRequest.NMSMessageId.Replace("'", "''");
                    String messageSelector = "NMSCorrelationID = '" + messageId + "'";
                    messageConsumer = session.CreateConsumer(replyTo, messageSelector);
                }
                return (TimeSpan.Compare(receiveTimeout, TimeSpan.FromMilliseconds(0)) == 1)
                           ? messageConsumer.Receive(receiveTimeout)
                           : messageConsumer.Receive();
            }
            finally
            {
                NmsUtils.CloseMessageProducer(messageProducer);
                NmsUtils.CloseMessageConsumer(messageConsumer);
                this.DeleteDestinationIfTemporary(session, replyTo);
                NmsUtils.CloseSession(session);

                ConnectionFactoryUtils.ReleaseConnection(connection, this.connectionFactory, true);
            }
        }
 protected override void HandleRequestMessage(IMessage message, ReplyMessageHolder replyMessageHolder)
 {
     if (!initialized)
     {
         AfterPropertiesSet();
     }
     IMessage requestMessage = MessageBuilder.FromMessage(message).Build();
     try
     {
         Apache.NMS.IMessage nmsReply = SendAndReceive(requestMessage);
     }
     catch (NMSException ex)
     {
         throw new MessageHandlingException(requestMessage, ex);
     }
 }