private void EmitEventsToStream(string streamId, EmittedEventEnvelope[] emittedEvents)
        {
            if (string.IsNullOrEmpty(streamId))
                throw new ArgumentNullException("streamId");
            EmittedStream stream;
            if (!_emittedStreams.TryGetValue(streamId, out stream))
            {
                var streamMetadata = emittedEvents.Length > 0 ? emittedEvents[0].StreamMetadata : null;

                var writeQueueId = _maximumAllowedWritesInFlight == AllowedWritesInFlight.Unbounded 
                    ? (Guid?)null 
                    :_writeQueueIds[_emittedStreams.Count % _maximumAllowedWritesInFlight];

                IEmittedStreamsWriter writer;
                if (writeQueueId == null)
                    writer = new EmittedStreamsWriter(_ioDispatcher);
                else
                    writer = new QueuedEmittedStreamsWriter(_ioDispatcher, writeQueueId.Value);

                var writerConfiguration = new EmittedStream.WriterConfiguration(
                    writer, streamMetadata, _runAs, maxWriteBatchLength: _maxWriteBatchLength, logger: _logger);

                stream = new EmittedStream(streamId, writerConfiguration, _projectionVersion, _positionTagger, _from, _publisher, _ioDispatcher, this);

                if (_started)
                    stream.Start();
                _emittedStreams.Add(streamId, stream);
            }
            stream.EmitEvents(emittedEvents.Select(v => v.Event).ToArray());
        }
Beispiel #2
0
        private void EmitEventsToStream(string streamId, EmittedEventEnvelope[] emittedEvents)
        {
            if (streamId == null)
            {
                throw new ArgumentNullException("streamId");
            }
            EmittedStream stream;

            if (!_emittedStreams.TryGetValue(streamId, out stream))
            {
                var streamMetadata = emittedEvents.Length > 0 ? emittedEvents[0].StreamMetadata : null;

                var writerConfiguration = new EmittedStream.WriterConfiguration(
                    streamMetadata, _runAs, maxWriteBatchLength: _maxWriteBatchLength, logger: _logger);

                stream = new EmittedStream(
                    streamId, writerConfiguration, _projectionVersion, _positionTagger, _from, _ioDispatcher, this);

                if (_started)
                {
                    stream.Start();
                }
                _emittedStreams.Add(streamId, stream);
            }
            stream.EmitEvents(emittedEvents.Select(v => v.Event).ToArray());
        }