private async Task <Constants.MessageProcessInstruction> ProcessMessage(string routingkeyorqueuename, string consumertag, long firsterrortimestamp, string exchange, string message) { _logger.Info($"Received message by '{consumertag}' | Content: {message}"); _rabbitSenderService.Send(message); return(await Task.FromResult(Constants.MessageProcessInstruction.OK)); }
private async Task <MessageProcessInstruction> ProcessMessage(string routingKeyOrQueueName, string consumerTag, long firstErrorTimestamp, string exchange, string message, string additionalInfo) { var debugMessage = $"Message received by '{consumerTag}'. Exchange: {exchange}. Message: {message}. Additional info: {additionalInfo} "; await Console.Out.WriteLineAsync(debugMessage).ConfigureAwait(false); _logger.LogInformation(debugMessage); if (Expired(firstErrorTimestamp)) { await Console.Out.WriteLineAsync("Message expired.").ConfigureAwait(false); return(new MessageProcessInstruction(Constants.MessageProcessInstruction.IgnoreMessage)); } var details = _consumerService.GetConsumerDetails(); if (details != null) { foreach (var consumerInfo in details) { Console.ForegroundColor = consumerInfo.Id % 2 == 0 ? ConsoleColor.Blue : ConsoleColor.DarkGreen; await Console.Out.WriteLineAsync($"Consumer '{consumerInfo.Name}'; connected to {consumerInfo.ConnectedToHost}:{consumerInfo.ConnectedToPort}; firstErrorTimestamp: {firstErrorTimestamp}; started at {consumerInfo.ConnectionTime:yyyy-MM-dd HH:mm:ss}; {consumerInfo.LastMessageDate:yyyy-MM-dd HH:mm:ss} ").ConfigureAwait(false); Console.ResetColor(); } } switch (message) { case "ok": if (_useSenderServiceKeepConnection) { _senderServiceKeepConnection.Send(message); } else { _senderService.Send(message); } await Console.Out.WriteLineAsync($"Message sent !! ").ConfigureAwait(false); return(new MessageProcessInstruction(Constants.MessageProcessInstruction.OK)); case "ignore": return(new MessageProcessInstruction(Constants.MessageProcessInstruction.IgnoreMessage)); case "requeue": return(new MessageProcessInstruction(Constants.MessageProcessInstruction.IgnoreMessageWithRequeue)); case "delay": return(new MessageProcessInstruction(Constants.MessageProcessInstruction.RequeueMessageWithDelay, $"message delayed {DateTime.Now}")); case "error": throw new ErrorProcessingException("error processing message"); default: return(new MessageProcessInstruction(Constants.MessageProcessInstruction.Unknown)); } }