コード例 #1
0
        private TcpPackage WrapPersistentSubscriptionConfirmationV1(ClientMessage.PersistentSubscriptionConfirmation msg)
        {
            var dto = new TcpClientMessageDto.PersistentSubscriptionConfirmation(msg.LastCommitPosition, msg.SubscriptionId,
                                                                                 msg.LastEventNumber == null ? msg.LastEventNumber : StreamVersionConverter.Downgrade(msg.LastEventNumber.Value));

            return(new TcpPackage(TcpCommand.PersistentSubscriptionConfirmation, msg.CorrelationId, dto.Serialize()));
        }
コード例 #2
0
        WrapPersistentSubscriptionConfirmation(ClientMessage.PersistentSubscriptionConfirmation msg)
        {
            var dto = new TcpClientMessageDto.PersistentSubscriptionConfirmation(msg.LastIndexedPosition,
                                                                                 msg.SubscriptionId, msg.LastEventNumber);

            return(new TcpPackage(TcpCommand.PersistentSubscriptionConfirmation, msg.CorrelationId, dto.Serialize()));
        }
コード例 #3
0
        public void Handle(ClientMessage.ConnectToPersistentSubscription message)
        {
            if (!_started)
            {
                return;
            }
            var streamAccess = _readIndex.CheckStreamAccess(
                message.EventStreamId, StreamAccessType.Read, message.User);

            if (!streamAccess.Granted)
            {
                message.Envelope.ReplyWith(new ClientMessage.SubscriptionDropped(message.CorrelationId,
                                                                                 SubscriptionDropReason.AccessDenied));
                return;
            }

            List <PersistentSubscription> subscribers;

            if (!_subscriptionTopics.TryGetValue(message.EventStreamId, out subscribers))
            {
                message.Envelope.ReplyWith(new ClientMessage.SubscriptionDropped(message.CorrelationId,
                                                                                 SubscriptionDropReason.NotFound));
                return;
            }

            var key = BuildSubscriptionGroupKey(message.EventStreamId, message.SubscriptionId);
            PersistentSubscription subscription;

            if (!_subscriptionsById.TryGetValue(key, out subscription))
            {
                message.Envelope.ReplyWith(new ClientMessage.SubscriptionDropped(message.CorrelationId,
                                                                                 SubscriptionDropReason.NotFound));
                return;
            }

            if (subscription.HasReachedMaxClientCount)
            {
                message.Envelope.ReplyWith(new ClientMessage.SubscriptionDropped(message.CorrelationId,
                                                                                 SubscriptionDropReason.SubscriberMaxCountReached));
                return;
            }

            Log.Debug("New connection to persistent subscription {subscriptionKey} by {connectionId}", key,
                      message.ConnectionId);
            var lastEventNumber   = _readIndex.GetStreamLastEventNumber(message.EventStreamId);
            var lastCommitPos     = _readIndex.LastIndexedPosition;
            var subscribedMessage =
                new ClientMessage.PersistentSubscriptionConfirmation(key, message.CorrelationId, lastCommitPos,
                                                                     lastEventNumber);

            message.Envelope.ReplyWith(subscribedMessage);
            var name = message.User == null ? "anonymous" : message.User.Identity.Name;

            subscription.AddClient(message.CorrelationId, message.ConnectionId, message.ConnectionName, message.Envelope,
                                   message.AllowedInFlightMessages, name, message.From);
        }
コード例 #4
0
        public void when_wrapping_persistent_subscription_confirmation_with_null_last_event_number_should_not_change()
        {
            var msg     = new ClientMessage.PersistentSubscriptionConfirmation("subscription", Guid.NewGuid(), 100, null);
            var package = _dispatcher.WrapMessage(msg, _version);

            Assert.IsNotNull(package, "Package is null");
            Assert.AreEqual(TcpCommand.PersistentSubscriptionConfirmation, package.Value.Command, "TcpCommand");

            var dto = package.Value.Data.Deserialize <TcpClientMessageDto.PersistentSubscriptionConfirmation>();

            Assert.IsNotNull(dto, "DTO is null");
            Assert.IsNull(dto.LastEventNumber, "Last event number");
        }
コード例 #5
0
        public void when_wrapping_persistent_subscription_confirmation_when_stream_deleted_should_not_downgrade_last_event_number_for_v2_clients()
        {
            var msg     = new ClientMessage.PersistentSubscriptionConfirmation("subscription", Guid.NewGuid(), 100, long.MaxValue);
            var package = _dispatcher.WrapMessage(msg, (byte)ClientVersion.V2);

            Assert.IsNotNull(package, "Package is null");
            Assert.AreEqual(TcpCommand.PersistentSubscriptionConfirmation, package.Value.Command, "TcpCommand");

            var dto = package.Value.Data.Deserialize <TcpClientMessageDto.PersistentSubscriptionConfirmation>();

            Assert.IsNotNull(dto, "DTO is null");
            Assert.AreEqual(long.MaxValue, dto.LastEventNumber, "Last event number");
        }
コード例 #6
0
 public void Handle(ClientMessage.PersistentSubscriptionConfirmation message)
 {
     ConfirmSubscription(message.CorrelationId, message.LastCommitPosition, message.LastEventNumber);
 }