Ejemplo n.º 1
0
        private async Task SubscribeToGroupManagementChannel()
        {
            var channel = await _bus.SubscribeAsync(_channels.GroupManagement);

            channel.OnMessage(async channelMessage =>
            {
                try
                {
                    var groupMessage = _protocol.ReadGroupCommand((byte[])channelMessage.Message);

                    var connection = _connections[groupMessage.ConnectionId];
                    if (connection == null)
                    {
                        // user not on this server
                        return;
                    }

                    if (groupMessage.Action == GroupAction.Remove)
                    {
                        await RemoveGroupAsyncCore(connection, groupMessage.GroupName);
                    }

                    if (groupMessage.Action == GroupAction.Add)
                    {
                        await AddGroupAsyncCore(connection, groupMessage.GroupName);
                    }

                    // Send an ack to the server that sent the original command.
                    await PublishAsync(_channels.Ack(groupMessage.ServerName), _protocol.WriteAck(groupMessage.Id));
                }
                catch (Exception ex)
                {
                    RedisLog.InternalMessageFailed(_logger, ex);
                }
            });
        }