public void InitialzeMessageQueueMetadata()
        {
            MessageQueueMetadataCache cache = new MessageQueueMetadataCache(applicationContext);

            Assert.AreEqual(0, cache.Count);
            cache.Initialize();
            Assert.IsTrue(cache.Initalized);
            Assert.AreEqual(4, cache.Count);
            MessageQueueMetadata md = cache.Get(@".\Private$\testqueue");

            cache.Remove(@".\Private$\testqueue");
            Assert.AreEqual(3, cache.Count);
            Assert.IsNull(cache.Get(@".\Private$\testqueue"));

            string[] paths = new string[]
            {
                @".\Private$\testtxqueue",
                @"FormatName:Direct=TCP:192.168.1.105\Private$\testtxqueue",
                @"FormatName:Direct=TCP:192.168.1.105\Private$\testqueue"
            };

            Assert.That(paths, Is.EquivalentTo(cache.Paths));
            paths = new string[] { @".\Private$\testtxqueue", @"FormatName:Direct=TCP:192.168.1.105\Private$\testtxqueue" };
            cache.RemoveAll(paths);
            Assert.AreEqual(1, cache.Count);
            cache.Clear();
            Assert.AreEqual(0, cache.Count);
        }
        public void InitialzeMessageQueueMetadata()
        {
            MessageQueueMetadataCache cache = new MessageQueueMetadataCache(applicationContext);
            Assert.AreEqual(0, cache.Count);
            cache.Initialize();
            Assert.IsTrue(cache.Initalized);
            Assert.AreEqual(4, cache.Count);
            MessageQueueMetadata md = cache.Get(@".\Private$\testqueue");
            cache.Remove(@".\Private$\testqueue");
            Assert.AreEqual(3, cache.Count);
            Assert.IsNull(cache.Get(@".\Private$\testqueue"));

            string[] paths = new string[]
                            {
                                @".\Private$\testtxqueue",
                                @"FormatName:Direct=TCP:192.168.1.105\Private$\testtxqueue",
                                @"FormatName:Direct=TCP:192.168.1.105\Private$\testqueue"
                            };

            Assert.That(paths, Is.EquivalentTo(cache.Paths));
            paths = new string[] {@".\Private$\testtxqueue", @"FormatName:Direct=TCP:192.168.1.105\Private$\testtxqueue"};
            cache.RemoveAll(paths);
            Assert.AreEqual(1, cache.Count);
            cache.Clear();
            Assert.AreEqual(0, cache.Count);
        }
Beispiel #3
0
        /// <summary>
        /// Send the message queue selecting the appropriate transactional delivery options.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If the message queue is transactional and there is an ambient MessageQueueTransaction
        /// in thread local storage (put there via the use of Spring's MessageQueueTransactionManager
        /// or TransactionalMessageListenerContainer), the message will be sent transactionally using the
        /// MessageQueueTransaction object in thread local storage. This lets you group together multiple
        /// messaging operations within the same transaction without having to explicitly pass around the
        /// MessageQueueTransaction object.
        /// </para>
        /// <para>
        /// If the message queue is transactional but there is no ambient MessageQueueTransaction,
        /// then a single message transaction is created on each messaging operation.
        /// (MessageQueueTransactionType = Single).
        /// </para>
        /// <para>
        /// If there is an ambient System.Transactions transaction then that transaction will
        /// be used (MessageQueueTransactionType = Automatic).
        /// </para>
        /// <para>
        /// If the queue is not transactional, then a non-transactional send
        /// (MessageQueueTransactionType = None) is used.
        /// </para>
        /// </remarks>
        /// <param name="mq">The mq.</param>
        /// <param name="msg">The MSG.</param>
        protected virtual void DoSendMessageQueue(MessageQueue mq, Message msg)
        {
            MessageQueueTransaction transactionToUse = QueueUtils.GetMessageQueueTransaction(null);

            if (metadataCache != null)
            {
                MessageQueueMetadata mqMetadata = metadataCache.Get(mq.Path);
                if (mqMetadata != null)
                {
                    if (mqMetadata.RemoteQueue)
                    {
                        if (mqMetadata.RemoteQueueIsTransactional)
                        {
                            // DefaultMessageQueue transaction is externally managed.
                            DoSendMessageTransaction(mq, transactionToUse, msg);
                            return;
                        }
                        DoSendMessageQueueNonTransactional(mq, transactionToUse, msg);
                        return;
                    }
                }
            }
            else
            {
                if (LOG.IsWarnEnabled)
                {
                    LOG.Warn("MetadataCache has not been initialized.  Set the MetadataCache explicitly in standalone usage and/or " +
                             "configure the MessageQueueTemplate in an ApplicationContext.  If deployed in an ApplicationContext by default " +
                             "the MetadataCache will automaticaly populated.");
                }
            }
            // Handle assuming these are local queues.

            if (mq.Transactional)
            {
                // DefaultMessageQueue transaction is externally managed.
                DoSendMessageTransaction(mq, transactionToUse, msg);
            }
            else
            {
                DoSendMessageQueueNonTransactional(mq, transactionToUse, msg);
            }
        }