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); }
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); }
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; }
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); }
private V FromValue(byte[] values) { if (valueSerdes != null) { return(values != null?valueSerdes.Deserialize(values, GetSerializationContext(false)) : default);
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())); }
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)); }
private V FromValue(byte[] values) { if (valueSerdes != null) { return(values != null?valueSerdes.Deserialize(values) : default);
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)); }
private Windowed <K> WindowedKey(Windowed <Bytes> bytesKey) { K key = keySerdes.Deserialize(bytesKey.Key.Get); return(new Windowed <K>(key, bytesKey.Window)); }