Exemplo n.º 1
0
        private void Ingress(IStreamObserver <TKey, TPayload> observer)
        {
            int messages = 0;

            try
            {
                var serializer = StreamableSerializer.Create <QueuedMessage <StreamMessage <TKey, TPayload> > >(
                    new SerializerSettings()
                {
                    KnownTypes = StreamMessageManager.GeneratedTypes()
                });
                while (true)
                {
                    var message = serializer.Deserialize(this.stream);
                    if (message.Kind != MessageKind.Completed)
                    {
                        observer.OnNext(message.Message);
                        messages++;
                    }
                    if (message.Kind == MessageKind.Completed ||
                        (this.numMessages != 0 && messages == this.numMessages))
                    {
                        observer.OnCompleted();
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                observer.OnError(e);
            }

            this.onSubscriptionCompleted();
        }
Exemplo n.º 2
0
        private void Ingress(IStreamObserver <TKey, TPayload> observer)
        {
            bool done     = false;
            int  messages = 0;

            try
            {
                var serializer = StreamableSerializer.Create <QueuedMessage <StreamMessage <TKey, TPayload> > >(new SerializerSettings());
                while (!done)
                {
                    var message = serializer.Deserialize(this.stream);
                    if (message.Kind == MessageKind.Completed)
                    {
                        done = true;
                    }
                    observer.OnNext(message.Message);
                    messages++;
                    if (this.numMessages != 0 && messages == this.numMessages)
                    {
                        if (message.Kind != MessageKind.Completed)
                        {
                            observer.OnCompleted();
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                observer.OnError(e);
            }
        }