private Task SubscribeToGroup(string groupChannel, GroupData group) { RedisLog.Subscribing(_logger, groupChannel); return(_bus.SubscribeAsync(groupChannel, async(c, data) => { try { var invocation = _protocol.ReadInvocation(data); var tasks = new List <Task>(); foreach (var groupConnection in group.Connections) { if (invocation.ExcludedIds?.Contains(groupConnection.ConnectionId) == true) { continue; } tasks.Add(groupConnection.WriteAsync(invocation.Message).AsTask()); } await Task.WhenAll(tasks); } catch (Exception ex) { RedisLog.FailedWritingMessage(_logger, ex); } })); }
private void SubscribeToAll() { RedisLog.Subscribing(_logger, _channels.All); _bus.Subscribe(_channels.All, async(c, data) => { try { RedisLog.ReceivedFromChannel(_logger, _channels.All); var invocation = _protocol.ReadInvocation(data); var tasks = new List <Task>(_connections.Count); foreach (var connection in _connections) { if (invocation.ExcludedIds == null || !invocation.ExcludedIds.Contains(connection.ConnectionId)) { tasks.Add(connection.WriteAsync(invocation.Message).AsTask()); } } await Task.WhenAll(tasks); } catch (Exception ex) { RedisLog.FailedWritingMessage(_logger, ex); } }); }
private Task SubscribeToUser(HubConnectionContext connection) { var userChannel = _channels.User(connection.UserIdentifier); return(_users.AddSubscriptionAsync(userChannel, connection, (channelName, subscriptions) => { RedisLog.Subscribing(_logger, channelName); return _bus.SubscribeAsync(channelName, async(c, data) => { try { var invocation = _protocol.ReadInvocation((byte[])data); var tasks = new List <Task>(); foreach (var userConnection in subscriptions) { tasks.Add(userConnection.WriteAsync(invocation.Message).AsTask()); } await Task.WhenAll(tasks); } catch (Exception ex) { RedisLog.FailedWritingMessage(_logger, ex); } }); })); }
private Task SubscribeToConnection(HubConnectionContext connection) { var connectionChannel = _channels.Connection(connection.ConnectionId); RedisLog.Subscribing(_logger, connectionChannel); return(_bus.SubscribeAsync(connectionChannel, async(c, data) => { var invocation = _protocol.ReadInvocation((byte[])data); await connection.WriteAsync(invocation.Message); })); }