예제 #1
0
        //---------------------------------------------------------------------
        // Static members

        /// <summary>
        /// Loads message queue settings from the application configuration using
        /// the specified key prefix.
        /// </summary>
        /// <param name="keyPrefix">The configuration key prefix.</param>
        /// <returns>A <see cref="MsgQueueSettings" /> instance.</returns>
        /// <remarks>
        /// <para>
        /// This method loads the settings described below from the application
        /// configuration using the <paramref name="keyPrefix" />.
        /// </para>
        /// <div class="tablediv">
        /// <table class="dtTABLE" cellspacing="0" ID="Table1">
        /// <tr valign="top">
        /// <th width="1">Setting</th>
        /// <th width="1">Default</th>
        /// <th width="90%">Description</th>
        /// </tr>
        /// <tr valign="top">
        ///     <td>BaseEP</td>
        ///     <td><see cref="MsgQueue.AbstractBaseEP" /></td>
        ///     <td>
        ///     The message queue service's base endpoint.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>Timeout</td>
        ///     <td>infinite</td>
        ///     <td>
        ///     The maximum time to wait for a response from a queue service before
        ///     terminating a transaction with a <see cref="TimeoutException" />.
        ///     Set <b>infinite</b> to wait indefinitely.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>MessageTTL</td>
        ///     <td><see cref="TimeSpan.Zero" /></td>
        ///     <td>
        ///     The default message expiration time.  This value is used to caclulate
        ///     the expiration time for for messages whose <see cref="QueuedMsg.ExpireTime" />
        ///     property was not explicitly set by the application.  Use <see cref="TimeSpan.Zero" />
        ///     to set the expiration date to the maximum in this case.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>Compress</td>
        ///     <td>BEST</td>
        ///     <td>
        ///     Specifes if serialized message bodies should be compressed before being
        ///     submitted to the queue service.  The possible values are <B>NONE</B>,
        ///     <b>COMPRESS</b>, and <b>BEST</b>.
        ///     </td>
        /// </tr>
        /// </table>
        /// </div>
        /// </remarks>
        public static MsgQueueSettings LoadConfig(string keyPrefix)
        {
            var settings = new MsgQueueSettings();
            var config   = new Config(keyPrefix);

            settings.BaseEP     = config.Get("BaseEP", settings.BaseEP);
            settings.Timeout    = config.Get("Timeout", settings.Timeout);
            settings.MessageTTL = config.Get("MessageTTL", settings.MessageTTL);
            settings.Compress   = config.Get <Compress>("Compress", settings.Compress);

            return(settings);
        }
예제 #2
0
        /// <summary>
        /// Returns the message's headers as a string suitable for
        /// transmitting in a <see cref="MsgQueueCmd" /> or
        /// <see cref="MsgQueueAck" /> message.
        /// </summary>
        /// <param name="settings">The <see cref="MsgQueueSettings" /> settings.</param>
        /// <returns>A <see cref="ArgCollection" /> formatted string.</returns>
        internal string GetMessageHeader(MsgQueueSettings settings)
        {
            var args = new ArgCollection('=', '\t');

            if (expireTime == DateTime.MinValue)
            {
                // If the expiration time was not explicitly set by the application
                // then we're going to set it ourselves.

                if (settings.MessageTTL <= TimeSpan.Zero)
                {
                    expireTime = DateTime.MaxValue;
                }
                else
                {
                    expireTime = DateTime.UtcNow + settings.MessageTTL;
                }
            }

            args.Set("id", id);

            if (sessionID != Guid.Empty)
            {
                args.Set("session-id", sessionID);
            }

            args.Set("target-ep", targetEP.ToString());

            if (responseEP != null)
            {
                args.Set("response-ep", responseEP.ToString());
            }

            args.Set("send-time", sendTime);
            args.Set("expire-time", expireTime);
            args.Set("flags", (int)flags);
            args.Set("priority", (int)priority);

            return(args.ToString());
        }