예제 #1
0
        protected override Task <bool> OnSendAsync(RequestMessage message)
        {
            if (_clientQueues.SendQueues?.Any() != true)
            {
                throw new NullReferenceException("There aren't any senders queues.");
            }
            if (_senderOptions is null)
            {
                throw new NullReferenceException("SenderOptions is null.");
            }

            if (message.Header.ResponseQueue is null)
            {
                var recvQueue = _clientQueues.RecvQueue;
                if (recvQueue != null)
                {
                    message.Header.ResponseQueue            = recvQueue; //new MQConnection(recvQueue.Route, recvQueue.Name) { Parameters = recvQueue.Parameters };
                    message.Header.ResponseExpected         = true;
                    message.Header.ResponseTimeoutInSeconds = _receiverOptions?.TimeoutInSec ?? -1;
                }
                else
                {
                    message.Header.ResponseExpected         = false;
                    message.Header.ResponseTimeoutInSeconds = -1;
                }
            }

            foreach (var sender in _clientQueues.SendQueues)
            {
                var sQueue = MemoryQueueManager.GetQueue(sender.Route, sender.Name);
                sQueue.Enqueue(message.CorrelationId, message);
            }

            return(TaskHelper.CompleteTrue);
        }
예제 #2
0
            protected override async Task OnListenerTaskStartAsync(CancellationToken token)
            {
                _token    = token;
                _receiver = MemoryQueueManager.GetQueue(Connection.Route, Connection.Name);
                while (!_token.IsCancellationRequested)
                {
                    var rcvValue = await _receiver.DequeueAsync(_token).ConfigureAwait(false);

                    if (_token.IsCancellationRequested)
                    {
                        break;
                    }
                    _ = Task.Run(() => EnqueueMessageToProcessAsync(ProcessingTaskAsync, rcvValue));
                }
            }
예제 #3
0
        /// <inheritdoc />
        /// <summary>
        /// On Send message data
        /// </summary>
        /// <param name="message">Response message instance</param>
        /// <param name="e">Event Args</param>
        protected override Task <int> OnSendAsync(ResponseMessage message, RequestReceivedEventArgs e)
        {
            if (e.ResponseQueues?.Any() != true)
            {
                return(TaskHelper.CompleteValueMinus1);
            }
            var response = true;

            foreach (var queue in e.ResponseQueues)
            {
                try
                {
                    var memQueue = MemoryQueueManager.GetQueue(queue.Route, queue.Name);
                    memQueue.Enqueue(message.CorrelationId, message);
                }
                catch (Exception ex)
                {
                    response = false;
                    Core.Log.Write(ex);
                }
            }
            return(response ? TaskHelper.CompleteValuePlus1 : TaskHelper.CompleteValueMinus1);
        }
예제 #4
0
        protected override void OnInit()
        {
            _receiver = null;

            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 = _receiverOptions?.TimeoutInSec ?? 20;

                if (_receiverOptions?.Parameters?.Contains("Clone") == true)
                {
                    _cloneObject = _receiverOptions.Parameters["Clone"].ParseTo(false);
                }

                if (_clientQueues != null)
                {
                    if (_clientQueues.RecvQueue != null)
                    {
                        _receiver = MemoryQueueManager.GetQueue(_clientQueues.RecvQueue.Route, _clientQueues.RecvQueue.Name);
                    }
                    foreach (var sender in _clientQueues.SendQueues)
                    {
                        MemoryQueueManager.GetQueue(sender.Route, sender.Name);
                    }
                }
            }
            Core.Status.AttachObject(this);
        }