コード例 #1
0
        /// <summary>
        /// Invoked by an <see cref="Spring.Objects.Factory.IObjectFactory"/>
        /// after it has injected all of an object's dependencies.
        /// </summary>
        /// <remarks>
        /// Ensure that the DefaultMessageQueueObjectName property is set, creates
        /// a default implementation of the <see cref="IMessageQueueFactory"/> interface
        /// (<see cref="DefaultMessageQueueFactory"/>) that retrieves instances on a per-thread
        /// basis, and registers in the Spring container a default implementation of
        /// <see cref="IMessageConverter"/> (<see cref="XmlMessageConverter"/>) with a
        /// simple System.String as its TargetType.  <see cref="QueueUtils.RegisterDefaultMessageConverter"/>
        /// </remarks>
        public void AfterPropertiesSet()
        {
            if (MessageQueueFactory == null)
            {
                AssertUtils.ArgumentNotNull(applicationContext, "MessageQueueTemplate requires the ApplicationContext property to be set if the MessageQueueFactory property is not set for automatic create of the DefaultMessageQueueFactory");

                DefaultMessageQueueFactory mqf = new DefaultMessageQueueFactory();
                mqf.ApplicationContext = applicationContext;
                messageQueueFactory    = mqf;
            }
            if (messageConverterObjectName == null)
            {
                messageConverterObjectName = QueueUtils.RegisterDefaultMessageConverter(applicationContext);
            }
            //If it has not been set by the user explicitly, then initialize.
            CreateDefaultMetadataCache();
        }
コード例 #2
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);
            }
        }