コード例 #1
0
ファイル: Connection.cs プロジェクト: shinedownn/SignalR
        private void ProcessResults(MessageResult result)
        {
            result.Messages.Enumerate(message => message.IsCommand || message.IsAck,
                                      message =>
            {
                if (message.IsAck)
                {
                    _ackHandler.TriggerAck(message.CommandId);
                }
                else
                {
                    var command = _serializer.Parse <Command>(message.Value);
                    ProcessCommand(command);

                    // Only send the ack if this command is waiting for it
                    if (message.WaitForAck)
                    {
                        // If we're on the same box and there's a pending ack for this command then
                        // just trip it
                        if (!_ackHandler.TriggerAck(message.CommandId))
                        {
                            _bus.Ack(_connectionId, message.Key, message.CommandId).Catch();
                        }
                    }
                }
            });
        }
コード例 #2
0
        private async Task WriteMessage(IServiceConnectionContainer connection, AppMessage appMessage)
        {
            var message = appMessage.Message;

            switch (message)
            {
            // For group related messages, make sure messages are written to the same partition
            case JoinGroupMessage joinGroupMessage:
                try
                {
                    await connection.WriteAsync(joinGroupMessage.GroupName, joinGroupMessage);
                }
                finally
                {
                    _ackHandler.TriggerAck(appMessage.RawMessage.CommandId);
                }
                break;

            case LeaveGroupMessage leaveGroupMessage:
                try
                {
                    await connection.WriteAsync(leaveGroupMessage.GroupName, leaveGroupMessage);
                }
                finally
                {
                    _ackHandler.TriggerAck(appMessage.RawMessage.CommandId);
                }
                break;

            case GroupBroadcastDataMessage groupBroadcastMessage:
                await connection.WriteAsync(groupBroadcastMessage.GroupName, groupBroadcastMessage);

                break;

            case ConnectionDataMessage connectionDataMessage:
                if (_clientConnectionManager.TryGetServiceConnection(connectionDataMessage.ConnectionId, out var serviceConnection))
                {
                    // If the client connection is connected to local server connection, send back directly from the established server connection
                    await serviceConnection.WriteAsync(message);
                }
                else
                {
                    await connection.WriteAsync(message);
                }
                break;

            default:
                await connection.WriteAsync(message);

                break;
            }
        }
コード例 #3
0
        private async Task WriteMessage(IServiceConnectionContainer connection, AppMessage appMessage)
        {
            var message = appMessage.Message;

            switch (message)
            {
            // For group related messages, make sure messages are written to the same partition
            case JoinGroupMessage joinGroupMessage:
                try
                {
                    await connection.WriteAsync(joinGroupMessage.GroupName, joinGroupMessage);
                }
                finally
                {
                    _ackHandler.TriggerAck(appMessage.RawMessage.CommandId);
                }
                break;

            case LeaveGroupMessage leaveGroupMessage:
                await connection.WriteAsync(leaveGroupMessage.GroupName, leaveGroupMessage);

                break;

            case GroupBroadcastDataMessage groupBroadcastMessage:
                await connection.WriteAsync(groupBroadcastMessage.GroupName, groupBroadcastMessage);

                break;

            default:
                await connection.WriteAsync(message);

                break;
            }
        }
コード例 #4
0
        private async Task WriteMessage(IServiceConnectionContainer connection, AppMessage appMessage)
        {
            var message = appMessage.Message;

            try
            {
                switch (message)
                {
                // For group related messages, make sure messages are written to the same partition
                case JoinGroupWithAckMessage joinGroupMessage:
                    try
                    {
                        await connection.WriteAckableMessageAsync(joinGroupMessage);
                    }
                    finally
                    {
                        _ackHandler.TriggerAck(appMessage.RawMessage.CommandId);
                    }
                    break;

                case LeaveGroupWithAckMessage leaveGroupMessage:
                    try
                    {
                        await connection.WriteAckableMessageAsync(leaveGroupMessage);
                    }
                    finally
                    {
                        _ackHandler.TriggerAck(appMessage.RawMessage.CommandId);
                    }
                    break;

                case ConnectionDataMessage connectionDataMessage:
                    var connectionId = connectionDataMessage.ConnectionId;
                    if (_clientConnectionManager.TryGetClientConnection(connectionId, out var conn))
                    {
                        // If the client connection is connected to local server connection,
                        // send back directly from the established server connection
                        await conn.WriteMessageAsync(connectionDataMessage);
                    }
                    else
                    {
                        await connection.WriteAsync(message);
                    }
                    break;

                default:
                    await connection.WriteAsync(message);

                    break;
                }

                if (message is IMessageWithTracingId msg && msg.TracingId != null)
                {
                    MessageLog.SucceededToSendMessage(_logger, msg);
                }
            }
            catch (Exception ex)
            {
                if (message is IMessageWithTracingId msg && msg.TracingId != null)
                {
                    MessageLog.FailedToSendMessage(_logger, msg, ex);
                }
                throw;
            }
        }