static void Main(string[] args) { Console.WriteLine("VowelConsCounter has started..."); var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare("text-rank-tasks", ExchangeType.Direct); rabbitMq.ExchangeDeclare("vowel-cons-counter", ExchangeType.Direct); rabbitMq.BindQueueToExchange("text-rank-tasks"); rabbitMq.ConsumeQueue(message => { string redisValue = String.Empty; var databaseId = RedisHelper.Instance.CalculateDatabase(message); RedisHelper.Instance.SetDatabase(databaseId); redisValue = RedisHelper.Instance.Database.StringGet(message); var vowelConsNum = TextRankCalc.Calc(redisValue); rabbitMq.PublishToExchange("vowel-cons-counter", $"{message}|{vowelConsNum.Consonants}|{vowelConsNum.Vowels}"); Console.WriteLine(" [x] Received from redis {0} with key: {1} equals {2}", redisValue, message, $"{vowelConsNum.Consonants}|{vowelConsNum.Vowels}"); }); Console.WriteLine(" Press [enter] to exit."); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("VowelConsRater has started..."); var rabbitMq = new RabbitMq(); string rankPrefix = "rank_"; rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare("vowel-cons-counter", ExchangeType.Direct); rabbitMq.BindQueueToExchange("vowel-cons-counter"); rabbitMq.ConsumeQueue(message => { var info = message.Split('|'); var contextId = info[0]; var volwes = info[1]; var cons = info[2]; var rank = TextRankCalc.Calc(Decimal.Parse(volwes), Decimal.Parse(cons)); var databaseId = RedisHelper.Instance.CalculateDatabase(contextId); RedisHelper.Instance.SetDatabase(databaseId); RedisHelper.Instance.Database.StringSet($"{rankPrefix}{contextId}", $"{rank.ToString()}"); Console.WriteLine(" [x] Received from redis {0} with key: {1} equals {2}", message, rank); }); Console.WriteLine(" Press [enter] to exit."); Console.ReadKey(); }
static void Main() { var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Fanout); rabbitMq.BindQueueToExchange(exchangeName); rabbitMq.ConsumeQueue(message => { Console.WriteLine($"{message}: {Redis.Instance.Database.StringGet(message)}"); }); Console.WriteLine("TextListener has started"); Console.WriteLine("Press [enter] to exit."); Console.ReadLine(); }
static void Main() { var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Fanout); rabbitMq.BindQueueToExchange(exchangeName); rabbitMq.ConsumeQueue(id => { Console.WriteLine($"{id} to text-rank-tasks queue"); rabbitMq.PublishToExchange("text-rank-tasks", id); }); Console.WriteLine("TextRankCalc has started"); Console.WriteLine("Press [enter] to exit."); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("TextRankCalck has started..."); RedisHelper redis = new RedisHelper(); var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare("backend-api", ExchangeType.Fanout); rabbitMq.ExchangeDeclare("text-rank-tasks", ExchangeType.Direct); rabbitMq.BindQueueToExchange("backend-api"); rabbitMq.ConsumeQueue(message => { rabbitMq.PublishToExchange("text-rank-tasks", message); }); Console.WriteLine(" Press [enter] to exit."); Console.ReadKey(); }
static void Main() { var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Fanout); rabbitMq.BindQueueToExchange(exchangeName); rabbitMq.ConsumeQueue(textId => { Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId)); string text = Redis.Instance.Database.StringGet($"{ConstantLibrary.Redis.Prefix.Text}{textId}"); Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Text}{textId}: {text}' from redis database({Redis.Instance.Database.Database})"); Console.WriteLine($"{textId}: {text}"); }); Console.WriteLine("TextListener has started"); Console.WriteLine("Press [enter] to exit."); Console.ReadLine(); }
static void Main() { var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Fanout); rabbitMq.BindQueueToExchange(_listeningExchangeName); rabbitMq.ConsumeQueue(id => { Console.WriteLine($"{id} to {_publishExchangeName} exchange"); rabbitMq.PublishToExchange(_publishExchangeName, id); Console.WriteLine("----------"); }); Console.WriteLine("TextRankCalc has started"); Console.WriteLine("Press [enter] to exit."); Console.ReadLine(); }
static void Main() { LoadStatistics(); var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Fanout); rabbitMq.BindQueueToExchange(_listeningExchangeName); rabbitMq.ConsumeQueue(textIdAndStatus => { Console.WriteLine($"New message from {_listeningExchangeName}: \"{textIdAndStatus}\""); string[] splittedMessage = textIdAndStatus.Split(ConstantLibrary.RabbitMq.Delimiter); string textId = splittedMessage[0]; bool isSucceededText = splittedMessage[1] == ConstantLibrary.RabbitMq.TextSuccessMarker.Status.True; Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId)); double rank = Double.Parse(Redis.Instance.Database.StringGet($"{ConstantLibrary.Redis.Prefix.Rank}{textId}")); Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Rank}{textId}: {rank}' from redis database({Redis.Instance.Database.Database})"); ++_statistics.TotalTextCount; if (isSucceededText) { ++_statistics.HighRankCount; } _statistics.TotalRank += rank; Redis.Instance.SetDatabase(ConstantLibrary.Redis.Statistics.DatabaseId); IncreaseStatisticsVersion(); Redis.Instance.Database.StringSet(ConstantLibrary.Redis.Statistics.TotalTextCount, _statistics.TotalTextCount); Console.WriteLine($"'{ConstantLibrary.Redis.Statistics.TotalTextCount}: {_statistics.TotalTextCount}' to redis database({Redis.Instance.Database.Database})"); Redis.Instance.Database.StringSet(ConstantLibrary.Redis.Statistics.HighRankCount, _statistics.HighRankCount); Console.WriteLine($"'{ConstantLibrary.Redis.Statistics.HighRankCount}: {_statistics.HighRankCount}' to redis database({Redis.Instance.Database.Database})"); Redis.Instance.Database.StringSet(ConstantLibrary.Redis.Statistics.TotalRank, _statistics.TotalRank); Console.WriteLine($"'{ConstantLibrary.Redis.Statistics.TotalRank}: {_statistics.TotalRank}' to redis database({Redis.Instance.Database.Database})"); Console.WriteLine("----------"); }); Console.WriteLine("TextStatistics has started"); Console.WriteLine("Press [enter] to exit."); Console.ReadLine(); }
static void Main() { var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(_queueName); rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Direct); rabbitMq.BindQueueToExchange(_listeningExchangeName); rabbitMq.ConsumeQueue(textId => { Console.WriteLine($"New message from {_listeningExchangeName}: \"{textId}\""); Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId)); string countKey = $"{ConstantLibrary.Redis.Prefix.Count}{textId}"; string countDataString = Redis.Instance.Database.StringGet(countKey); Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Count}{textId}: {countDataString}' from redis database({Redis.Instance.Database.Database})"); Redis.Instance.Database.KeyDelete(countKey); Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Count}{textId}: {countDataString}' deleted from redis database({Redis.Instance.Database.Database})"); string[] countData = countDataString.Split(ConstantLibrary.RabbitMq.Delimiter); int vowelCount; int consonantCount; if (Int32.TryParse(countData[0], out vowelCount) && Int32.TryParse(countData[1], out consonantCount)) { string rank = CalculateRank(vowelCount, consonantCount); Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Rank}{textId}: {rank}' to redis database({Redis.Instance.Database.Database})"); Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Rank}{textId}", rank); Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Status}{textId}: {ConstantLibrary.Redis.Status.Completed}' to redis database({Redis.Instance.Database.Database})"); Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Status}{textId}", ConstantLibrary.Redis.Status.Completed); Console.WriteLine($"{textId} to {_publishExchangeName} exchange"); rabbitMq.PublishToExchange(_publishExchangeName, textId); } Console.WriteLine("----------"); }); Console.WriteLine("VowelConsonantRater has started"); Console.WriteLine("Press [enter] to exit."); Console.ReadLine(); }
static void Main(string[] args) { RedisHelper redis = new RedisHelper(); var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare("backend-api", ExchangeType.Fanout); rabbitMq.BindQueueToExchange("backend-api"); rabbitMq.ConsumeQueue(message => { string redisValue = String.Empty; redisValue = redis.Database.StringGet(message); string rank = TextRankCalc.Calc(redisValue).ToString(); redis.Database.StringSet(message, rank); Console.WriteLine(" [x] Received from redis {0} with key: {1} equals {2}", redisValue, message, rank); }); Console.WriteLine(" Press [enter] to exit."); Console.ReadKey(); }
static void Main() { var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(queueName); rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Direct); rabbitMq.BindQueueToExchange(exchangeName); rabbitMq.ConsumeQueue(textId => { string text = Redis.Instance.Database.StringGet(textId); VowelConsonant vowelConsonant = CalculateVowelConsonant(text); string countId = Guid.NewGuid().ToString(); Console.WriteLine($"'{countId}: {textId}|{vowelConsonant.vowelCount}|{vowelConsonant.consonantCount}' to redis"); Redis.Instance.Database.StringSet(countId, $"{textId}|{vowelConsonant.vowelCount}|{vowelConsonant.consonantCount}"); Console.WriteLine($"{countId} to vowel-cons-counter queue"); rabbitMq.PublishToExchange("vowel-cons-counter", countId); Console.WriteLine("----------"); }); Console.WriteLine("VowelConsonantCounter has started"); Console.WriteLine("Press [enter] to exit."); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Text Listener..."); RedisHelper redishelper = new RedisHelper(); var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare("backend-api", ExchangeType.Fanout); rabbitMq.BindQueueToExchange("backend-api"); rabbitMq.ConsumeQueue(message => { string redisValue = String.Empty; redisValue = redishelper.Database.StringGet(message); Console.WriteLine(" [x] Received from redis {0} with key: {1}", redisValue, message); }); Console.WriteLine(" Press [enter] to exit."); Console.ReadKey(); /* using(var channel = RabbitMQ.RabbitMq.GetModel()) * { * RabbitMQHelper.DeclareExchangeQueue("backend-api", channel); * string queueName = channel.QueueDeclare().QueueName; * * RabbitMQHelper.BindQueueToExchange("backend-api", channel, queueName); * var consumer = RabbitMQHelper.GetConsumer(channel); * consumer.Received += (model, ea) => * { * * }; * * RabbitMQHelper.ConsumeQueue("backend-api", consumer, channel); * * } */ }
static void Main() { LoadStatistics(); var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Fanout); rabbitMq.BindQueueToExchange(_listeningExchangeName); rabbitMq.ConsumeQueue(textId => { Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId)); double rank = Double.Parse(Redis.Instance.Database.StringGet($"{ConstantLibrary.Redis.Prefix.Rank}{textId}")); Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Rank}{textId}: {rank}' from redis database({Redis.Instance.Database.Database})"); ++_statistics.TotalTextCount; if (rank > 0.5) { ++_statistics.HighRankCount; } _statistics.TotalRank += rank; Redis.Instance.SetDatabase(ConstantLibrary.Redis.Statistics.DatabaseId); IncreaseStatisticsVersion(); Redis.Instance.Database.StringSet(ConstantLibrary.Redis.Statistics.TotalTextCount, _statistics.TotalTextCount); Console.WriteLine($"'{ConstantLibrary.Redis.Statistics.TotalTextCount}: {_statistics.TotalTextCount}' to redis database({Redis.Instance.Database.Database})"); Redis.Instance.Database.StringSet(ConstantLibrary.Redis.Statistics.HighRankCount, _statistics.HighRankCount); Console.WriteLine($"'{ConstantLibrary.Redis.Statistics.HighRankCount}: {_statistics.HighRankCount}' to redis database({Redis.Instance.Database.Database})"); Redis.Instance.Database.StringSet(ConstantLibrary.Redis.Statistics.TotalRank, _statistics.TotalRank); Console.WriteLine($"'{ConstantLibrary.Redis.Statistics.TotalRank}: {_statistics.TotalRank}' to redis database({Redis.Instance.Database.Database})"); Console.WriteLine("----------"); }); Console.WriteLine("TextStatistics has started"); Console.WriteLine("Press [enter] to exit."); Console.ReadLine(); }
static void Main() { var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(queueName); rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Direct); rabbitMq.BindQueueToExchange(exchangeName); rabbitMq.ConsumeQueue(textId => { Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId)); string text = Redis.Instance.Database.StringGet($"{ConstantLibrary.Redis.Prefix.Text}{textId}"); Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Text}{textId}: {text}' from redis database({Redis.Instance.Database.Database})"); VowelConsonant vowelConsonant = CalculateVowelConsonant(text); Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Count}{textId}", $"{vowelConsonant.vowelCount}|{vowelConsonant.consonantCount}"); Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Count}{textId}: {vowelConsonant.vowelCount}|{vowelConsonant.consonantCount}' to redis database({Redis.Instance.Database.Database})"); Console.WriteLine($"{textId} to vowel-cons-counter queue"); rabbitMq.PublishToExchange("vowel-cons-counter", textId); Console.WriteLine("----------"); }); Console.WriteLine("VowelConsonantCounter has started"); Console.WriteLine("Press [enter] to exit."); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Text Listener..."); RedisHelper redishelper = RedisHelper.Instance; var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare("backend-api", ExchangeType.Fanout); rabbitMq.BindQueueToExchange("backend-api"); rabbitMq.ConsumeQueue(message => { var databaseId = RedisHelper.Instance.CalculateDatabase(message); RedisHelper.Instance.SetDatabase(databaseId); string redisValue = String.Empty; redisValue = redishelper.Database.StringGet(message); Console.WriteLine(" [x] Received from redis {0} with key: {1}", redisValue, message); }); Console.WriteLine(" Press [enter] to exit."); Console.ReadKey(); }
static void Main() { var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Fanout); rabbitMq.BindQueueToExchange(_listeningExchangeName); rabbitMq.ConsumeQueue(textIdAndStatus => { Console.WriteLine($"New message from {_listeningExchangeName}: \"{textIdAndStatus}\""); string[] splittedMessage = textIdAndStatus.Split(ConstantLibrary.RabbitMq.Delimiter); string textId = splittedMessage[0]; bool doesTextAllowed = splittedMessage[1] == ConstantLibrary.RabbitMq.ProcessingLimiter.Status.True; if (!doesTextAllowed) { Console.WriteLine($"{textId} not allowed"); return; } Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId)); Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Status}{textId}: {ConstantLibrary.Redis.Status.Processing}' to redis database({Redis.Instance.Database.Database})"); Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Status}{textId}", ConstantLibrary.Redis.Status.Processing); // System.Threading.Thread.Sleep(5000); Console.WriteLine($"{textId} to {_publishExchangeName} exchange"); rabbitMq.PublishToExchange(_publishExchangeName, textId); Console.WriteLine("----------"); }); Console.WriteLine("TextRankCalc has started"); Console.WriteLine("Press [enter] to exit."); Console.ReadLine(); }