Exemplo n.º 1
0
        public override async Task ReplayMessagesAsync(
            IActorContext context,
            string persistenceId,
            long fromSequenceNr,
            long toSequenceNr,
            long max,
            Action <IPersistentRepresentation> recoveryCallback)
        {
            RedisValue[] journals = await Database.SortedSetRangeByScoreAsync(_journalHelper.GetJournalKey(persistenceId), fromSequenceNr, toSequenceNr, skip : 0L, take : max);

            foreach (var journal in journals)
            {
                recoveryCallback(_journalHelper.PersistentFromBytes(journal));
            }
        }
Exemplo n.º 2
0
            private void Query()
            {
                switch (_state)
                {
                case State.Idle:
                    if (_buffer.Count == 0)
                    {
                        // so, we need to fill this buffer
                        _state = State.Querying;

                        // Complete stage if fromSequenceNr is higher than toSequenceNr
                        if (_toSequenceNr < _currentSequenceNr)
                        {
                            CompleteStage();
                        }

                        _redis.GetDatabase(_database).SortedSetRangeByScoreAsync(
                            key: _journalHelper.GetJournalKey(_persistenceId),
                            start: _currentSequenceNr,
                            stop: Math.Min(_currentSequenceNr + _max - 1, _toSequenceNr),
                            order: Order.Ascending).ContinueWith(task =>
                        {
                            if (!task.IsCanceled || task.IsFaulted)
                            {
                                var deserializedEvents = task.Result.Select(e => _journalHelper.PersistentFromBytes(e)).ToList();
                                _callback(deserializedEvents);
                            }
                            else
                            {
                                Log.Error(task.Exception, "Error while querying events by persistence identifier");
                                FailStage(task.Exception);
                            }
                        });
                    }
                    else
                    {
                        // buffer is non empty, let’s deliver buffered data
                        Deliver();
                    }
                    break;

                default:
                    Log.Error($"Unexpected source state when querying: {_state}");
                    FailStage(new IllegalStateException($"Unexpected source state when querying: {_state}"));
                    break;
                }
            }