static void Main(string[] args) { string rankString = "rank_"; RedisHelper redishelper = RedisHelper.Instance; var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Fanout); rabbitMq.BindQueueToExchange(_listeningExchangeName); rabbitMq.ConsumeQueue(message => { Console.WriteLine($"New message from {_listeningExchangeName}: \"{message}\""); var info = message.Split('|'); var textId = info[0]; var rank = Double.Parse(info[1]); redishelper.SetDatabase(redishelper.CalculateDatabase(textId)); Console.WriteLine($"'{rankString}{textId}: {rank}'"); var stringToPublish = $"{textId}|" + (rank > _successLowerBound ? "True" : "False"); Console.WriteLine($"{stringToPublish} to {_publishExchangeName} exchange"); rabbitMq.PublishToExchange(_publishExchangeName, stringToPublish); Console.WriteLine("----------"); }); Console.WriteLine($"TextSuccessMarker has started. Success lower bound is {_successLowerBound}"); Console.WriteLine("Press [enter] to exit."); Console.ReadLine(); }
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.ExchangeDeclare("text-rank-calc", ExchangeType.Fanout); 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()}"); rabbitMq.PublishToExchange("text-rank-calc", $"{contextId}|{rank}"); 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(string[] args) { Console.WriteLine("VowelConsCounter has started..."); RedisHelper redis = new RedisHelper(); 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; redisValue = redis.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() { var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare(_listeningExchangeName, ExchangeType.Fanout); rabbitMq.BindQueueToExchange(_listeningExchangeName); rabbitMq.ConsumeQueue(textId => { Console.WriteLine($"New message from {_listeningExchangeName}: \"{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})"); var stringToPublish = $"{textId}{ConstantLibrary.RabbitMq.Delimiter}" + (rank > _successLowerBound ? ConstantLibrary.RabbitMq.TextSuccessMarker.Status.True : ConstantLibrary.RabbitMq.TextSuccessMarker.Status.False); Console.WriteLine($"{stringToPublish} to {_publishExchangeName} exchange"); rabbitMq.PublishToExchange(_publishExchangeName, stringToPublish); Console.WriteLine("----------"); }); Console.WriteLine($"TextSuccessMarker has started. Success lower bound is {_successLowerBound}"); 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 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); Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Count}{textId}: {vowelConsonant.vowelCount}|{vowelConsonant.consonantCount}' to redis database({Redis.Instance.Database.Database})"); Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Count}{textId}", $"{vowelConsonant.vowelCount}|{vowelConsonant.consonantCount}"); Console.WriteLine($"{textId} to {_publishExchangeName} exchange"); rabbitMq.PublishToExchange(_publishExchangeName, textId); Console.WriteLine("----------"); }); Console.WriteLine("VowelConsonantCounter has started"); Console.WriteLine("Press [enter] to exit."); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("TextRankCalck has started..."); RedisHelper redis = RedisHelper.Instance; var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare("processing-limiter", ExchangeType.Fanout); rabbitMq.ExchangeDeclare("text-rank-tasks", ExchangeType.Direct); rabbitMq.BindQueueToExchange("processing-limiter"); rabbitMq.ConsumeQueue(message => { Console.WriteLine($"Acepted message {message}"); string[] splittedMessage = message.Split('|'); string textId = splittedMessage[0]; bool doesTextAllowed = splittedMessage[1] == "True"; if (!doesTextAllowed) { Console.WriteLine($"{message} not allowed"); return; } RedisHelper.Instance.SetDatabase(RedisHelper.Instance.CalculateDatabase(textId)); if (RedisHelper.Instance.Database.StringGet($"status_{textId}") != Status.Accepted) { Console.WriteLine($"'status_{textId}: {Status.Processing}' to redis database({RedisHelper.Instance.Database.Database})"); RedisHelper.Instance.Database.StringSet($"status_{textId}", Status.Processing); } rabbitMq.PublishToExchange("text-rank-tasks", textId); }); Console.WriteLine(" Press [enter] to exit."); Console.ReadKey(); }
static void Main(string[] args) { string statusOfText = "status_"; RedisHelper redishelper = RedisHelper.Instance; var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare("backend-api", ExchangeType.Fanout); rabbitMq.BindQueueToExchange("backend-api"); rabbitMq.ConsumeQueue(message => { Console.WriteLine($"New message from text-rank-calc: \"{message}\""); redishelper.SetDatabase(redishelper.CalculateDatabase(message)); bool status = _succeededTextCount < _limit; if (status) { ++_succeededTextCount; Console.WriteLine($"'{statusOfText}{message}: {Status.Accepted}', redishelper.Database: {redishelper.Database.Database}"); redishelper.Database.StringSet($"{statusOfText}{message}", Status.Accepted); } else { Console.WriteLine($"'{statusOfText}{message}: {Status.Rejected}'redishelper.Database: {redishelper.Database.Database}"); redishelper.Database.StringSet($"{statusOfText}{message}", Status.Rejected); } var stringToPublish = $"{message}|" + (status ? "True" : "False"); Console.WriteLine($"{stringToPublish} to 'processing-limiter' exchange"); rabbitMq.PublishToExchange("processing-limiter", stringToPublish); }); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare("text-success-marker", ExchangeType.Fanout); rabbitMq.BindQueueToExchange("text-success-marker"); rabbitMq.ConsumeQueue(message => { Console.WriteLine($"New message from 'text-success-marker': \"{message}\""); string[] data = message.Split('|'); bool isTextSucceeded = data[1] == "True"; if (!isTextSucceeded) { Console.WriteLine("Succeeded text count reset"); _succeededTextCount -= 1; } Console.WriteLine("----------"); }); Console.WriteLine("TextProcessingLimiter has started"); Console.WriteLine("Press [enter] to exit."); Console.ReadLine(); }
static void Main() { var rabbitMq = new RabbitMq(); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare(_textListeningExchangeName, ExchangeType.Fanout); rabbitMq.BindQueueToExchange(_textListeningExchangeName); rabbitMq.ConsumeQueue(textId => { Console.WriteLine($"New message from {_textListeningExchangeName}: \"{textId}\""); Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId)); bool status = _succeededTextCount < _limit; if (status) { ++_succeededTextCount; Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Status}{textId}: {ConstantLibrary.Redis.Status.Accepted}' to redis database({Redis.Instance.Database.Database})"); Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Status}{textId}", ConstantLibrary.Redis.Status.Accepted); } else { Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Status}{textId}: {ConstantLibrary.Redis.Status.Rejected}' to redis database({Redis.Instance.Database.Database})"); Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Status}{textId}", ConstantLibrary.Redis.Status.Rejected); } var stringToPublish = $"{textId}{ConstantLibrary.RabbitMq.Delimiter}" + (status ? ConstantLibrary.RabbitMq.ProcessingLimiter.Status.True : ConstantLibrary.RabbitMq.ProcessingLimiter.Status.False); Console.WriteLine($"{stringToPublish} to {_publishExchangeName} exchange"); rabbitMq.PublishToExchange(_publishExchangeName, stringToPublish); Console.WriteLine("----------"); }); rabbitMq.QueueDeclare(); rabbitMq.ExchangeDeclare(_textMarkersListeningExchangeName, ExchangeType.Fanout); rabbitMq.BindQueueToExchange(_textMarkersListeningExchangeName); rabbitMq.ConsumeQueue(textIdMarker => { Console.WriteLine($"New message from {_textMarkersListeningExchangeName}: \"{textIdMarker}\""); string[] data = textIdMarker.Split(ConstantLibrary.RabbitMq.Delimiter); bool isTextSucceeded = data[1] == ConstantLibrary.RabbitMq.TextSuccessMarker.Status.True; if (!isTextSucceeded) { Console.WriteLine("Succeeded text count reset"); _succeededTextCount = 0; } Console.WriteLine("----------"); }); Console.WriteLine("TextProcessingLimiter has started"); Console.WriteLine("Press [enter] to exit."); Console.ReadLine(); }
public string Post([FromBody] DataDto value) { string id = Guid.NewGuid().ToString(); Redis.Instance.Database.StringSet(id, value.Data); const string exchangeName = "backend-api"; _rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Fanout); _rabbitMq.PublishToExchange(exchangeName, id); return(id); }
public string Post([FromBody] DataDto value) { string textId = Guid.NewGuid().ToString(); Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId)); Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Text}{textId}", value.Data); Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Text}{textId}: {value.Data}' to redis database({Redis.Instance.Database.Database})"); const string exchangeName = "backend-api"; _rabbitMq.ExchangeDeclare(exchangeName, ExchangeType.Fanout); _rabbitMq.PublishToExchange(exchangeName, textId); return(textId); }
public string Post([FromBody] DataDto value) { string textId = Guid.NewGuid().ToString(); Redis.Instance.SetDatabase(Redis.Instance.CalculateDatabase(textId)); Console.WriteLine($"'{ConstantLibrary.Redis.Prefix.Text}{textId}: {value.Data}' to redis database({Redis.Instance.Database.Database})"); Redis.Instance.Database.StringSet($"{ConstantLibrary.Redis.Prefix.Text}{textId}", value.Data); Console.WriteLine($"{textId} to {_publishExchangeName} exchange"); _rabbitMq.PublishToExchange(_publishExchangeName, textId); return(textId); }
public string Post([FromBody] DataTransferDto dataTransfer) { if (dataTransfer == null) { return(null); } var id = Guid.NewGuid().ToString(); _redisHelper.Database.StringSet(id, dataTransfer.Data); var rabbitMq = new RabbitMq(); rabbitMq.ExchangeDeclare("backend-api", ExchangeType.Fanout); rabbitMq.PublishToExchange("backend-api", id); return(id); }
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(_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(); }
public string Post([FromBody] DataTransferDto dataTransfer) { if (dataTransfer == null) { return(null); } var id = Guid.NewGuid().ToString(); var databaseId = _redisHelper.CalculateDatabase(id); Console.WriteLine($" [x] For {id} database : {databaseId}"); _redisHelper.SetDatabase(databaseId); _redisHelper.Database.StringSet(id, dataTransfer.Data); var rabbitMq = new RabbitMq(); rabbitMq.ExchangeDeclare("backend-api", ExchangeType.Fanout); rabbitMq.PublishToExchange("backend-api", id); return(id); }
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() { 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() { 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(); }