/// <summary> /// Get Messages In Queue /// </summary> /// <param name="state"></param> private async void ProcessMessagesInQueue(object state) { _counter++; ResponseModel <List <MessageQueue> > messages = await _messageProcessor.ProcessMessages(_appConfig.InboundSemaphoreKey, _connectionStrings); Console.WriteLine("total messages processed " + messages.Entity.Count.ToString() + " sent at " + DateTime.Now); }
/// <summary> /// Receive Messages /// </summary> /// <param name="queueName"></param> /// <param name="subject"></param> public async Task ReceiveMessages(string queueName, Subject <MessageQueue> subject, IMessageQueueProcessing _messageProcessor) { Console.WriteLine("Receiving Messages at " + DateTime.Now); if (_running == true) { return; } _running = true; var response = _channel.QueueDeclarePassive(queueName); _channel.QueueDeclare(queue: queueName, durable: true, exclusive: false, autoDelete: false, arguments: null); _subscription = new Subscription(_channel, queueName, false); foreach (BasicDeliverEventArgs e in _subscription) { string message = Encoding.UTF8.GetString(e.Body); MessageQueue messageQueue = JsonConvert.DeserializeObject <MessageQueue>(message); messageQueue.MessageGuid = Guid.NewGuid(); if (messageQueue.QueueName == string.Empty || messageQueue.QueueName == null) { messageQueue.QueueName = _originatingQueueName; } Console.WriteLine("Receiving Message id " + messageQueue.TransactionQueueId); ResponseModel <MessageQueue> responseMessage = await _messageProcessor.CommitInboundMessage(messageQueue, _connectionStrings); if (responseMessage.ReturnStatus == true) { if (_sendToLoggingQueue == true) { responseMessage = SendReceivedMessageToLoggingQueue(messageQueue); } if (responseMessage.ReturnStatus == true) { Console.WriteLine($"Message Committed: {messageQueue.TransactionQueueId}"); _subscription.Ack(e); } await _messageProcessor.ProcessMessages(_inboundSemaphoreKey, _connectionStrings); } } }
/// <summary> /// Get Messages In Queue /// </summary> /// <param name="state"></param> private async void GetMessagesInQueue(object state) { if (_running == true) { return; } _running = true; Console.WriteLine("Receiving Messages at " + DateTime.Now); Subscription subscription = _messageQueueConfigurations[0].GetSubscription(); foreach (BasicDeliverEventArgs e in subscription) { string message = Encoding.UTF8.GetString(e.Body); MessageQueue messageQueue = JsonConvert.DeserializeObject <MessageQueue>(message); if (messageQueue.QueueName == string.Empty || messageQueue.QueueName == null) { string originatingQueue = _messageQueueConfigurations[0].GetOriginatingQueueName(); if (originatingQueue != MessageQueueEndpoints.LoggingQueue) { messageQueue.QueueName = originatingQueue; } } Console.WriteLine("Receiving Message id " + messageQueue.TransactionQueueId); ResponseModel <MessageQueue> responseMessage = await _messageProcessor.CommitInboundMessage(messageQueue, _connectionStrings); if (responseMessage.ReturnStatus == true) { if (_appConfig.SendToLoggingQueue == true && messageQueue.TransactionCode != TransactionQueueTypes.Acknowledgement) { responseMessage = _messageQueueConfigurations[0].SendReceivedMessageToLoggingQueue(messageQueue, MessageQueueExchanges.Logging); } if (responseMessage.ReturnStatus == true) { Console.WriteLine($"Message Committed: {messageQueue.TransactionQueueId}"); subscription.Ack(e); } await _messageProcessor.ProcessMessages(_appConfig.InboundSemaphoreKey, _connectionStrings); } } }