public void Run() { _subscription = _connection.SubscribeAsync(Const.RankProcess, "rank_calculator", (sender, args) => { var id = Encoding.UTF8.GetString(args.Message.Data); var textKey = Const.TextTitleKey + id; if (!_redisStorage.IsKeyExist(textKey)) { _logger.LogWarning("Text key {textKey} doesn't exists", textKey); return; } var text = _redisStorage.Load(textKey); var rankKey = Const.RankTitleKey + id; var rank = CalculateRank(text).ToString(); _redisStorage.Store(rankKey, rank); string message = $"Event: RankCalculated, context id: {id}, rank: {rank}"; _connection.Publish(Const.BrokerRank, Encoding.UTF8.GetBytes(message)); }); _subscription.Start(); Console.WriteLine("Press Enter to exit (RankCalculator)"); Console.ReadLine(); _subscription.Unsubscribe(); _connection.Drain(); _connection.Close(); }
public void Run() { var subscription = _connection.SubscribeAsync(Const.BrokerRank, "rank_calculator", (sender, args) => { var id = Encoding.UTF8.GetString(args.Message.Data); var textKey = Const.TextTitleKey + id; if (!_redisStorage.IsKeyExist(textKey)) { _logger.LogWarning("Text key {textKey} doesn't exists", textKey); return; } var text = _redisStorage.Load(textKey); var rankKey = Const.RankTitleKey + id; var rank = CalculateRank(text).ToString(); _logger.LogDebug("Rank {rank} with key {rankKey} by text id {id}", rank, rankKey, id); _redisStorage.Store(rankKey, rank); }); subscription.Start(); Console.WriteLine("Press Enter to exit"); Console.ReadLine(); subscription.Unsubscribe(); _connection.Drain(); _connection.Close(); }
public void OnGet(string id) { _logger.LogDebug(id); var rankKey = Const.RankTitleKey + id; Similarity = Convert.ToDouble(_redisStorage.Load(Const.SimilarityTitleKey + id)); if (_redisStorage.IsKeyExist(rankKey)) { Rank = Convert.ToDouble(_redisStorage.Load(rankKey)); } else { _logger.LogWarning("RankKey {rankKey} doesn't exists", rankKey); } }
public void OnGet(string id) { var shard = _redisStorage.LoadShard(id); _logger.LogDebug($"{shard} : {id} - SummaryGet"); var rankKey = Const.RankTitleKey + id; Similarity = Convert.ToDouble(_redisStorage.Load(Const.SimilarityTitleKey + id, shard)); for (int retryCount = 0; retryCount < 100; retryCount++) { Thread.Sleep(10); if (_redisStorage.IsKeyExist(rankKey, shard)) { Rank = Convert.ToDouble(_redisStorage.Load(rankKey, shard)); return; } } _logger.LogWarning($"RankKey {rankKey} doesn't exists in [{shard}]"); }