Beispiel #1
0
        /// <inheritdoc />
        /// <summary>
        /// Create a new message queue
        /// </summary>
        /// <param name="queue">Message Queue connection instance</param>
        /// <returns>true if the message queue was created; otherwise, false.</returns>
        public bool Create(MQConnection queue)
        {
            if (Exist(queue))
            {
                return(false);
            }
            var rabbitQueue = new RabbitMQueue(queue);

            if (!rabbitQueue.EnsureConnectionAsync(2000, 100).WaitAndResults())
            {
                return(false);
            }
            rabbitQueue.EnsureQueue();
            rabbitQueue.EnsureExchange();
            rabbitQueue.Close();
            return(true);
        }
Beispiel #2
0
        /// <inheritdoc />
        /// <summary>
        /// Create a new message queue
        /// </summary>
        /// <param name="queue">Message Queue connection instance</param>
        /// <returns>true if the message queue was created; otherwise, false.</returns>
        public bool Create(MQConnection queue)
        {
            if (Exist(queue))
            {
                return(false);
            }
            var rabbitQueue = new RabbitMQueue(queue);

            if (!rabbitQueue.EnsureConnection())
            {
                return(false);
            }
            rabbitQueue.EnsureQueue();
            rabbitQueue.EnsureExchange();
            rabbitQueue.Close();
            return(true);
        }
Beispiel #3
0
        protected override void OnInit()
        {
            OnDispose();
            _senders              = new List <RabbitMQueue>();
            _receiver             = null;
            _receiverStopBuffered = ActionDelegate.Create(RemoveReceiverConsumer).CreateBufferedAction(60000);

            if (Config != null)
            {
                if (Config.ClientQueues != null)
                {
                    _clientQueues = Config.ClientQueues.FirstOf(
                        c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true && c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true,
                        c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true,
                        c => c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true,
                        c => c.EnvironmentName.IsNullOrWhitespace());
                }
                _senderOptions          = Config.RequestOptions?.ClientSenderOptions;
                _receiverOptions        = Config.ResponseOptions?.ClientReceiverOptions;
                _receiverOptionsTimeout = TimeSpan.FromSeconds(_receiverOptions?.TimeoutInSec ?? 20);
                UseSingleResponseQueue  = _receiverOptions?.Parameters?[ParameterKeys.SingleResponseQueue].ParseTo(true) ?? true;

                if (_clientQueues != null)
                {
                    if (_clientQueues.SendQueues?.Any() == true)
                    {
                        foreach (var queue in _clientQueues.SendQueues)
                        {
                            var rabbitQueue = new RabbitMQueue(queue);
                            rabbitQueue.EnsureConnectionAsync(2000, int.MaxValue).WaitAndResults();
                            rabbitQueue.EnsureExchange();
                            _senders.Add(rabbitQueue);
                        }
                    }

                    if (_clientQueues.RecvQueue != null && !SendOnly)
                    {
                        _receiver = new RabbitMQueue(_clientQueues.RecvQueue);
                    }
                }
                if (_senderOptions is null)
                {
                    throw new Exception("Client Sender Options is Null.");
                }

                _priority = (byte)(_senderOptions.MessagePriority == MQMessagePriority.High ? 9 :
                                   _senderOptions.MessagePriority == MQMessagePriority.Low ? 1 : 5);
                _expiration   = (_senderOptions.MessageExpirationInSec * 1000).ToString();
                _deliveryMode = (byte)(_senderOptions.Recoverable ? 2 : 1);

                CreateReceiverConsumerAsync().WaitAsync();
            }

            Core.Status.Attach(collection =>
            {
                if (_senders != null)
                {
                    for (var i = 0; i < _senders.Count; i++)
                    {
                        collection.Add("Sender: {0} ".ApplyFormat(i), _senders[i].Route + " - " + _senders[i].Name);
                    }
                }
                if (_receiver != null)
                {
                    collection.Add("Receiver: {0}", _receiver.Route + " - " + _receiver.Name);
                }
            });
        }