Example #1
0
        /// <summary>
        /// Internal constructor.
        /// </summary>
        /// <param name="hiveBus">The <see cref="HiveBus"/>.</param>
        /// <param name="name">The channel name (maximum of 250 characters).</param>
        /// <param name="durable">
        /// Optionally specifies that the channel should survive message cluster restarts.
        /// This defaults to <c>false</c>.
        /// </param>
        /// <param name="exclusive">
        /// Optionally specifies that this channel instance will exclusively receive
        /// messages from the queue.  This defaults to <c>false</c>.
        /// </param>
        /// <param name="autoDelete">
        /// Optionally specifies that the channel should be deleted once all consumers have
        /// disconnected.  This defaults to <c>false</c>.
        /// </param>
        /// <param name="messageTTL">
        /// <para>
        /// Optionally specifies the maximum time a message can remain in the channel before
        /// being deleted.  This defaults to <c>null</c> which disables this feature.
        /// </para>
        /// <note>
        /// The maximum possible TTL is about <b>24.855 days</b>.
        /// </note>
        /// </param>
        /// <param name="maxLength">
        /// Optionally specifies the maximum number of messages that can be waiting in the channel
        /// before messages at the front of the channel will be deleted.  This defaults
        /// to unconstrained.
        /// </param>
        /// <param name="maxLengthBytes">
        /// Optionally specifies the maximum total bytes of messages that can be waiting in
        /// the channel before messages at the front of the channel will be deleted.  This
        /// defaults to unconstrained.
        /// </param>
        internal BasicChannel(
            HiveBus hiveBus,
            string name,
            bool durable        = false,
            bool exclusive      = false,
            bool autoDelete     = false,
            TimeSpan?messageTTL = null,
            int?maxLength       = null,
            int?maxLengthBytes  = null)

            : base(hiveBus, name)
        {
            Covenant.Requires <ArgumentNullException>(hiveBus != null);
            Covenant.Requires <ArgumentException>(maxLength == null || maxLength.Value > 0);
            Covenant.Requires <ArgumentException>(maxLengthBytes == null || maxLengthBytes.Value > 0);

            queue = EasyBus.QueueDeclare(
                name: name,
                passive: false,
                durable: durable,
                exclusive: exclusive,
                autoDelete: autoDelete,
                perQueueMessageTtl: HiveBus.TTLToMilliseconds(messageTTL),
                maxLength: maxLength,
                maxLengthBytes: maxLengthBytes);

            // We're going to use the default exchange which automatically
            // routes messages to the queue by name.

            exchange = Exchange.GetDefault();
        }
Example #2
0
        /// <summary>
        /// Internal constructor.
        /// </summary>
        /// <param name="hiveBus">The <see cref="HiveBus"/>.</param>
        /// <param name="name">The channel name.</param>
        /// <param name="durable">
        /// Optionally specifies that the channel should survive message cluster restarts.
        /// This defaults to <c>false</c>.
        /// </param>
        /// <param name="autoDelete">
        /// Optionally specifies that channel should be automatically deleted when the
        /// last consumer is removed.
        /// </param>
        /// <param name="messageTTL">
        /// <para>
        /// Optionally specifies the maximum time a message can remain in the channel before
        /// being deleted.  This defaults to <c>null</c> which disables this feature.
        /// </para>
        /// <note>
        /// The maximum possible TTL is about <b>24.855 days</b>.
        /// </note>
        /// </param>
        /// <param name="maxLength">
        /// Optionally specifies the maximum number of messages that can be waiting in the channel
        /// before messages at the front of the channel will be deleted.  This defaults
        /// to unconstrained.
        /// </param>
        /// <param name="maxLengthBytes">
        /// Optionally specifies the maximum total bytes of messages that can be waiting in
        /// the channel before messages at the front of the channel will be deleted.  This
        /// defaults to unconstrained.
        /// </param>
        /// <param name="publishOnly">
        /// Optionally specifies that the channel instance returned will only be able
        /// to publish messages and not consume them.  Enabling this avoid the creation
        /// of a queue that will unnecessary for this situation.
        /// </param>
        internal BroadcastChannel(
            HiveBus hiveBus,
            string name,
            bool durable        = false,
            bool autoDelete     = false,
            TimeSpan?messageTTL = null,
            int?maxLength       = null,
            int?maxLengthBytes  = null,
            bool publishOnly    = false)

            : base(hiveBus, name)
        {
            Covenant.Requires <ArgumentNullException>(hiveBus != null);
            Covenant.Requires <ArgumentException>(maxLength == null || maxLength.Value > 0);
            Covenant.Requires <ArgumentException>(maxLengthBytes == null || maxLengthBytes.Value > 0);

            this.sourceID    = Guid.NewGuid().ToString("D").ToLowerInvariant();
            this.publishOnly = publishOnly;

            exchange = EasyBus.ExchangeDeclare(
                name: name,
                type: EasyNetQ.Topology.ExchangeType.Fanout,
                passive: false,
                durable: durable,
                autoDelete: autoDelete,
                alternateExchange: null,
                delayed: false);

            queue = EasyBus.QueueDeclare(
                name: $"{name}-{sourceID}",
                passive: false,
                durable: durable,
                exclusive: true,
                autoDelete: true,
                perQueueMessageTtl: HiveBus.TTLToMilliseconds(messageTTL),
                maxLength: maxLength,
                maxLengthBytes: maxLengthBytes);

            EasyBus.Bind(exchange, queue, routingKey: "#");
        }