コード例 #1
0
ファイル: GetEventStoreClient.cs プロジェクト: VCuzmin/nbb
        public async Task <List <IEvent> > GetEventsFromStreamAsync(string stream, int?startFromVersion, CancellationToken cancellationToken = default)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();

            var result      = new List <IEvent>();
            var gregsEvents = new List <ResolvedEvent>();

            using (var connection = await GetConnectionAsync())
            {
                StreamEventsSlice currentSlice;
                long nextSliceStart = StreamPosition.Start;
                do
                {
                    currentSlice = await connection.ReadStreamEventsForwardAsync(stream, nextSliceStart, 200, false);

                    nextSliceStart = currentSlice.NextEventNumber;

                    gregsEvents.AddRange(currentSlice.Events);
                } while (!currentSlice.IsEndOfStream);
            }

            foreach (var resolvedEvent in gregsEvents)
            {
                var metadata  = _serDes.Deserialize <EventMetadata>(resolvedEvent.Event.Metadata);
                var eventType = metadata.GetEventType();
                var @event    = _serDes.Deserialize(resolvedEvent.Event.Data, eventType) as IEvent;
                result.Add(@event);
            }

            stopWatch.Stop();
            _logger.LogDebug("GetEventStoreClient.GetEventsFromStreamAsync for {Stream} took {ElapsedMilliseconds} ms", stream, stopWatch.ElapsedMilliseconds);

            return(result);
        }
コード例 #2
0
ファイル: SqlStreamStore.cs プロジェクト: VCuzmin/nbb
        public async Task <List <IEvent> > GetEventsFromStreamAsync(string stream, int?startFromVersion, CancellationToken cancellationToken = default)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();

            const int _PAGE_SIZE = 10;

            var page = await _streamStore.ReadAllForwards(Position.Start, _PAGE_SIZE, cancellationToken : cancellationToken);

            var messages = new List <StreamMessage>(page.Messages);

            while (!page.IsEnd) //should not take more than 20 iterations.
            {
                page = await page.ReadNext(cancellationToken);

                messages.AddRange(page.Messages);
            }

            var result = new List <IEvent>();

            foreach (var sm in messages)
            {
                var metadata  = _serDes.Deserialize <EventMetadata>(sm.JsonMetadata);
                var eventType = metadata.GetEventType();
                var data      = await sm.GetJsonData(cancellationToken);

                var @event = _serDes.Deserialize(data, eventType) as IEvent;
                result.Add(@event);
            }

            stopWatch.Stop();
            _logger.LogDebug("SqlStreamStore.GetEventsFromStreamAsync for {Stream} took {ElapsedMilliseconds} ms", stream, stopWatch.ElapsedMilliseconds);

            return(result);
        }
コード例 #3
0
        public void Unpack(IReader reader)
        {
            if (!D2OHelper.TryParseHeader(reader))
            {
                throw new InvalidOperationException("d2o file is corrupted");
            }

            _skipValuePositions(reader);

            var classDefCount = reader.ReadValue <int>();
            var unpacked      = new List <D2OClassDefinition>(classDefCount);

            for (var i = 0; i < classDefCount; i++)
            {
                unpacked.Add(
                    _serdes.Deserialize <D2OClassDefinition>(reader));
            }

            Unpacked = unpacked;
        }
コード例 #4
0
        public void Subscribe<TMessage>(Action<TMessage> handler) where TMessage : class
        {
            var factory = new ConnectionFactory() { HostName = RABBITMQ_HOST };
            connection = factory.CreateConnection();
            channel = connection.CreateModel();
            channel.ExchangeDeclare(exchange: EXCHANGE_NAME, type: "direct");
            var queueName = channel.QueueDeclare().QueueName;
            channel.QueueBind(queue: queueName,
                              exchange: EXCHANGE_NAME,
                              routingKey: ROUTING_KEY);


            var consumer = new EventingBasicConsumer(channel);
            consumer.Received += (model, ea) =>
            {
                var msg = serdes.Deserialize<TMessage>(ea.Body);
                handler(msg);
                channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
            };
            channel.BasicConsume(queue: queueName,
                                 autoAck: false,    //true,
                                 consumer: consumer);
        }
コード例 #5
0
 private V FromValue(byte[] values)
 {
     if (valueSerdes != null)
     {
         return(values != null?valueSerdes.Deserialize(values, GetSerializationContext(false)) : default);
コード例 #6
0
 public static K ExtractStoreKey <K>(byte[] binaryKey, ISerDes <K> keySerdes)
 {
     binaryKey = binaryKey ?? new byte[0];
     byte[] bytes = binaryKey.AsSpan(0, binaryKey.Length - TIMESTAMP_SIZE - SEQNUM_SIZE).ToArray();
     return(keySerdes.Deserialize(bytes, new Confluent.Kafka.SerializationContext()));
 }
コード例 #7
0
        public static Windowed <K> FromStoreKey <K>(Windowed <Bytes> windowedKey, ISerDes <K> keySerdes, String topic)
        {
            K key = keySerdes.Deserialize(windowedKey.Key.Get, new Confluent.Kafka.SerializationContext(Confluent.Kafka.MessageComponentType.Key, topic));

            return(new Windowed <K>(key, windowedKey.Window));
        }
コード例 #8
0
 private V FromValue(byte[] values)
 {
     if (valueSerdes != null)
     {
         return(values != null?valueSerdes.Deserialize(values) : default);
コード例 #9
0
        private Windowed <K> WindowedKey(Windowed <Bytes> bytesKey)
        {
            K key = keySerdes.Deserialize(bytesKey.Key.Get, new Confluent.Kafka.SerializationContext());

            return(new Windowed <K>(key, bytesKey.Window));
        }
コード例 #10
0
        private Windowed <K> WindowedKey(Windowed <Bytes> bytesKey)
        {
            K key = keySerdes.Deserialize(bytesKey.Key.Get);

            return(new Windowed <K>(key, bytesKey.Window));
        }