private async void SubscriptionTriggeredResponse(RedisChannel redisChannel, RedisValue redisValue) { try { string channelString = redisChannel.ToString(); if (channelString.Contains("__keyspace@")) { if (redisValue.ToString() == "set") { string key = channelString.Replace("__keyspace@" + DefaultDatabase + "__:", String.Empty); T currentData = await GetByIdCoreAsync(key); CompleteSubscriptionTrigger(currentData); } else if (redisValue.ToString() == "del") { try { string key = redisChannel.ToString().Replace("__keyspace@" + DefaultDatabase + "__:", String.Empty); DeleteCachedEntity(key); } catch { } } } else { T currentData = System.Text.Json.JsonSerializer.Deserialize <T>(redisValue); CompleteSubscriptionTrigger(currentData); } } catch (Exception ex) { try { string key = redisChannel.ToString().Replace("__keyspace@" + DefaultDatabase + "__:", string.Empty); DeleteCachedEntity(key); ex.Data.Add("Key", key); } catch { } RedisRepositoryErrorManager.LogException(this, ex); } }
private void SubscriptionTriggeredResponse(RedisChannel redisChannel, RedisValue redisValue) { try { if (redisValue.ToString() == "set") { string key = redisChannel.ToString().Replace("__keyspace@" + DefaultDatabase + "__:", String.Empty); var currentData = GetByIdCore(key); if (EnableCaching) { if (!SetCachedEntity(currentData)) { if (PreventSubForAlreadyCachedData) { return; } } } if (SubscriptionTriggered == null) { return; } var receivers = SubscriptionTriggered.GetInvocationList(); foreach (SubscriptionTriggeredEventHandler receiver in receivers) { receiver.BeginInvoke(this, currentData, null, null); } } else if (redisValue.ToString() == "del") { try { string key = redisChannel.ToString().Replace("__keyspace@" + DefaultDatabase + "__:", String.Empty); DeleteCachedEntity(key); } catch { } } } catch (Exception ex) { Logger.Log(ex); } }
private void OnMessageReceived(RedisChannel ch, RedisValue val) { Logger.Trace($"Pubsub message received.{Environment.NewLine} {val}"); var channel = ch.ToString(); string message = val; var msgParts = message.Split(new[] { "::" }, StringSplitOptions.None); if (msgParts.Length < 5) { Logger.Warn($"Invalid pubsub message, Dropping.{Environment.NewLine} {message}"); return; } var nodeName = msgParts[0]; var type = msgParts[1]; //3 and 4 reserved var packet = msgParts[4]; Logger.Trace($"PubSub packet received from node {nodeName}, on channel {channel} message, {message}"); //var isWatchDogMsg = type == nameof(IWatchDogMessage); foreach (var pair in _subscriptions) { if (type == pair.Key) { Robustness.Instance.SafeCall(() => { pair.Value.BeginInvoke(packet, null, null); }); } } }
public void Route(RedisChannel channel, RedisValue msg) { try { // get an object from the payload message var payload = JsonSerializer.DeserializeFromString <JsonObject>(msg.ToString()); // get the friendly name of the event (without the namespace) string evnt = payload["event"].Split('\\').Last(); // get the action corresponding to the event var action = _listeners .Where(chan => { return(ParseChannel(chan.Key) == channel.ToString()); }) .DefaultIfEmpty(_catchall.First()) // get the channel .First() .Value .Where(ev => { return(ev.Key == evnt); }) .DefaultIfEmpty(_catchall.First().Value.First()) .First() .Value; // get the listener // trigger the action and pass in the payload action(msg); } catch (Exception e) { Console.WriteLine(e.Message); } }
public void ListenForMessage(RedisChannel channel, RedisValue value) { Assert.Equal(RedisKey, channel.ToString()); Assert.False(!value.HasValue || value.IsNullOrEmpty); Assert.Equal("INFO test pub/sub message", value.ToString()); ActionRun = true; }
public void ListenForMessage(RedisChannel channel, RedisValue value) { Assert.AreEqual(RedisKey, channel.ToString()); Assert.IsFalse(!value.HasValue || value.IsNullOrEmpty); Assert.AreEqual("INFO test pub/sub message", value.ToString()); ActionRun = true; }
void SubAppendText(RedisChannel channel, string message) { textBlockSub.AppendText(message); string channel_str = channel.IsNullOrEmpty ? "null" : channel.ToString(); textBlockStatusBar.Text = string.Format("channel:{0} message:{1}", channel_str, message); }
private void myChannel1Handler(RedisChannel lsChannel, RedisValue lsValue) { // using delegate function to avoid not in the same thread exception // in WPF, use Dispatcher.Invoke ShowMessage WriteLog = new ShowMessage(ShowLog); Dispatcher.Invoke(WriteLog, "received on channel[" + lsChannel.ToString() + "] - " + lsValue.ToString()); }
void KeyspaceChannelProcessor(RedisChannel channel, RedisValue value, Action <string, string> action) { var key = channel.ToString()?.Split(':'); if (key.Length > 0 && key.Last() != null) { action?.Invoke(key.Last(), $"{value}"); } }
private void SubscriberMessageReceived(RedisChannel redisChannel, RedisValue redisValue) { if (!redisChannel.ToString().EndsWith("expired", StringComparison.InvariantCultureIgnoreCase)) { return; } var key = Encoding.UTF8.GetString(redisValue); LogMethod?.Invoke("Expired", key, null); RemoveMethod?.Invoke(key); }
private void OnKeySpaceNotificationMessage(RedisChannel pattern, RedisValue data) { var prefix = pattern.ToString().Substring(0, 10); switch (prefix) { case "__keyevent": this.ProcessInvalidationMessage(data.ToString()); break; default: //nop break; } }
private void OnRedisSubscription(RedisChannel channel, RedisValue message) { logger.Info("Redis Subscription On Channel " + channel); if (!RedisConnection.IsConnected) { logger.Warn("Redis Connection was lost - attempting to reopen..."); try { RedisConnection = ConnectionMultiplexer.Connect(System.Configuration.ConfigurationManager.ConnectionStrings["DBRedisConnect"].ConnectionString); logger.Warn("Redis Connection re-established"); } catch (Exception ex) { logger.Error("Error creating Redis Connection - " + ex.Message); logger.Error(ex); hub.Clients.Group(ServerID.ToString()).OnServerError("An internal server error occurred"); return; } } try { dynamic json = Newtonsoft.Json.JsonConvert.DeserializeObject(message.ToString()); string channelString = channel.ToString(); if (channelString.Contains(appSettings.RedisKeyCapturePoint)) { hub.Clients.Group(ServerID.ToString()).UpdateCapturePoints(json); } else if (channelString.Contains(appSettings.RedisKeyDepot)) { hub.Clients.Group(ServerID.ToString()).UpdateDepots(json); } else if (channelString.Contains(appSettings.RedisKeySideMission)) { hub.Clients.Group(ServerID.ToString()).UpdateMissions(json); } else if (channelString.Contains(appSettings.RedisKeyChat)) { hub.Clients.Group(ServerID.ToString()).UpdateChat(json); } } catch (Exception ex) { logger.Error("Error invoking SignalR callback - " + ex.Message); logger.Error(ex); hub.Clients.Group(ServerID.ToString()).OnServerError("An internal server error occurred"); } }
private void NewMessageHandler(RedisChannel channel, RedisValue value) { string json = value; var item = JsonConvert.DeserializeObject <EventItem>(json, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); if (item is null) { throw new NullReferenceException("event item is null"); } if (EventHubs.TryGetValue(channel.ToString(), out var hub)) { hub.SpreadEvent(item); } }
private void DoSomeThing(RedisChannel channel, RedisValue message) { DataRow row; row = this.Rows.Find(channel.ToString()); if (row == null) { row = this.NewRow(); row["ContractCode"] = channel.ToString(); try { foreach (String item in ((string)message).Split(',')) { String key; String value; String[] keyValue = item.Split(':'); key = keyValue[0]; value = keyValue[1]; if (this.Columns[key].DataType == typeof(String)) { row[key] = value; } else if (this.Columns[key].DataType == typeof(decimal)) { row[key] = Convert.ToDecimal(value); } } this.Rows.Add(row); } catch (Exception e) { MessageBox.Show(e.Message, "Exception"); } } else { try { foreach (String item in ((string)message).Split(',')) { String key; String value; String[] keyValue = item.Split(':'); key = keyValue[0]; value = keyValue[1]; if (this.Columns[key].DataType == typeof(String)) { row[key] = value; } else if (this.Columns[key].DataType == typeof(decimal)) { row[key] = Convert.ToDecimal(value); } else if (this.Columns[key].DataType == typeof(DateTime)) { row[key] = DateTime.ParseExact(value, "HHmmssfff", CultureInfo.InvariantCulture); } } } catch (Exception e) { MessageBox.Show(e.Message, "Exception"); } } }
protected string GetIdFromChannel(RedisChannel channel) { return(GetIdFromString(channel.ToString())); }