コード例 #1
0
 /// <inheritdoc />
 public ulong GetOffset(EventHorizonKey eventHorizon)
 {
     using (var es = _database.GetContext())
     {
         return(es.GeodesicsOffsets.SingleOrDefault(_ => _.Id == eventHorizon.AsId())?.Value ?? 0);
     }
 }
コード例 #2
0
        /// <summary>
        /// Builds a <see cref="FilterDefinition{BsonDocument}" /> corresponding to the <see cref="EventHorizonKey" /> supplied
        /// </summary>
        /// <param name="key">An <see cref="EventHorizonKey" /></param>
        /// <returns>A <see cref="FilterDefinition{BsonDocument}" /> corresponding to the <see cref="EventHorizonKey" /></returns>
        public static FilterDefinition <BsonDocument> ToFilter(this EventHorizonKey key)
        {
            var builder = Builders <BsonDocument> .Filter;
            var filter  = builder.Eq(Constants.ID, key.AsId());

            return(filter);
        }
コード例 #3
0
        /// <inheritdoc />
        public void SetOffset(EventHorizonKey key, ulong offset)
        {
            var offsetBson = key.ToOffsetBson(offset);

            _offsets.ReplaceOne(key.ToFilter(), offsetBson, new UpdateOptions {
                IsUpsert = true
            });
        }
コード例 #4
0
 /// <inheritdoc />
 public void SetOffset(EventHorizonKey key, ulong offset)
 {
     _connection.AppendToStreamAsync(
         GetStreamForEventHorizonKey(key),
         ExpectedVersion.Any,
         CreateEventHorizonOffsetEvent(key, offset)
         ).Wait();
 }
コード例 #5
0
 /// <summary>
 /// Transforms the <see cref="EventHorizonKey"/> and offset to <see cref="BsonDocument"/>
 /// </summary>
 /// <param name="key"></param>
 /// <param name="offset"></param>
 /// <returns></returns>
 public static BsonDocument ToOffsetBson(this EventHorizonKey key, ulong offset)
 {
     return(new BsonDocument(new Dictionary <string, object>
     {
         { Constants.ID, key.AsId() },
         { Constants.OFFSET, offset }
     }));
 }
コード例 #6
0
        /// <inheritdoc />
        public ulong GetOffset(EventHorizonKey key)
        {
            var result = _connection.ReadEventAsync(GetStreamForEventHorizonKey(key), StreamPosition.End, true).Result;

            if (result.Event.HasValue)
            {
                return(_serializer.FromJsonBytes <ulong>(result.Event.Value.Event.Data));
            }
            return(0);
        }
コード例 #7
0
 EventData CreateEventHorizonOffsetEvent(EventHorizonKey key, ulong offset)
 {
     return(new EventData(
                Guid.NewGuid(),
                "EventHorizonOffset",
                true,
                _serializer.ToJsonBytes(offset),
                Array.Empty <byte>()
                ));
 }
コード例 #8
0
        /// <inheritdoc />
        public ulong GetOffset(EventHorizonKey key)
        {
            var offset = _offsets.Find(key.ToFilter()).SingleOrDefault();

            if (offset == null)
            {
                return(0);
            }

            return(offset[Constants.OFFSET].ToUlong());
        }
コード例 #9
0
 /// <inheritdoc />
 public void SetOffset(EventHorizonKey key, ulong offset)
 {
     using (var es = _database.GetContext())
     {
         //TODO: this can be optimized so that the update is the thing we expect most and the insert is the edge case
         var commandText = "INSERT OR REPLACE INTO GeodesicsOffsets (Id, Value) VALUES (@Id,@Value);";
         var id          = new SqliteParameter("@Id", key.AsId());
         var value       = new SqliteParameter("@Value", offset);
         es.Database.ExecuteSqlCommand(commandText, id, value);
     }
 }
コード例 #10
0
        async Task SetAsync(EventHorizonKey eventHorizon, ulong offset)
        {
            var o = Offset.From(eventHorizon, offset, _config.BasePartitionKey);

            try
            {
                var result = await _config.Client.UpsertDocumentAsync(_config.OffsetsUri, o, new RequestOptions { PartitionKey = new PartitionKey(_config.BasePartitionKey) });

                _logger.Debug(ResponseMetadata.FromOffset("Setting Geodesics Offset", result)?.ToString());
            }
            catch (DocumentClientException ex)
            {
                throw new EventStorePersistenceError("Error", ex);
            }
        }
コード例 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="QuantumTunnelConnection"/> class.
        /// </summary>
        /// <param name="horizonKey">The key for the connection.</param>
        /// <param name="destinationKey">The key for the destination.</param>
        /// <param name="address">Url for the <see cref="IEventHorizon"/> we're connecting to.</param>
        /// <param name="events"><see cref="IEnumerable{Artifact}">Events</see> to connect for.</param>
        /// <param name="getGeodesics">A <see cref="FactoryFor{IGeodesics}"/> to provide the correctly scoped geodesics instance for path offsetting.</param>
        /// <param name="getEventStore">A factory to provide the correctly scoped <see cref="IEventStore"/> to persist incoming events to.</param>
        /// <param name="eventProcessingHub"><see cref="IScopedEventProcessingHub"/> for processing incoming events.</param>
        /// <param name="serializer"><see cref="ISerializer"/> to use for deserializing content of commits.</param>
        /// <param name="logger"><see cref="ILogger"/> for logging purposes.</param>
        /// <param name="executionContextManager"><see cref="IExecutionContextManager"/> so we can set the correct context for the processing of the Events.</param>
        /// <param name="tenants"><see cref="ITenants"/> the tenants that we need to be aware of from the other bounded contexts.</param>
        /// <param name="tenantOffsetRepository"><see creF="ITenantOffsetRepository"/> to use for tracking offsets per tenant.</param>
        public QuantumTunnelConnection(
            EventHorizonKey horizonKey,
            EventHorizonKey destinationKey,
            string address,
            IEnumerable <Dolittle.Artifacts.Artifact> events,
            FactoryFor <IGeodesics> getGeodesics,
            FactoryFor <IEventStore> getEventStore,
            IScopedEventProcessingHub eventProcessingHub,
            ISerializer serializer,
            ILogger logger,
            IExecutionContextManager executionContextManager,
            ITenants tenants,
            ITenantOffsetRepository tenantOffsetRepository)
        {
            _address                    = address;
            _events                     = events;
            _logger                     = logger;
            _horizonKey                 = horizonKey;
            _destinationKey             = destinationKey;
            _getGeodesics               = getGeodesics;
            _serializer                 = serializer;
            _getEventStore              = getEventStore;
            _eventProcessingHub         = eventProcessingHub;
            _channel                    = new Channel(_address, ChannelCredentials.Insecure);
            _client                     = new QuantumTunnelService.QuantumTunnelServiceClient(_channel);
            _runCancellationTokenSource = new CancellationTokenSource();
            _runCancellationToken       = _runCancellationTokenSource.Token;
            _executionContextManager    = executionContextManager;
            _processor                  = new ParticleStreamProcessor(getEventStore, getGeodesics, _destinationKey, eventProcessingHub, _executionContextManager, logger);
            _tenantOffsetRepository     = tenantOffsetRepository;
            _tenants                    = tenants;

            AppDomain.CurrentDomain.ProcessExit   += ProcessExit;
            AssemblyLoadContext.Default.Unloading += AssemblyLoadContextUnloading;
            Task.Run(() => Run(), _runCancellationToken);
            Console.CancelKeyPress += (s, e) => Close();
        }
コード例 #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="key"></param>
 /// <param name="offset"></param>
 /// <returns></returns>
 public static GeodesicsOffset From(EventHorizonKey key, ulong offset)
 {
     return(new GeodesicsOffset {
         Id = key.AsId(), Value = offset
     });
 }
コード例 #13
0
 /// <inheritdoc />
 public void SetOffset(EventHorizonKey key, ulong offset)
 {
     SetAsync(key, offset).GetAwaiter().GetResult();
 }
コード例 #14
0
        /// <inheritdoc />
        public ulong GetOffset(EventHorizonKey key)
        {
            ulong offset;

            return(_lastProcessed.TryGetValue(key, out offset) ? offset : 0);
        }
コード例 #15
0
 /// <inheritdoc />
 public void SetOffset(EventHorizonKey key, ulong offset)
 {
     _lastProcessed.AddOrUpdate(key, offset, (id, v) => offset);
 }
コード例 #16
0
 Offset GetOffsetDoc(EventHorizonKey key)
 {
     return(_config.Client.CreateDocumentQuery <Offset>(_config.OffsetsUri, GetFeedOptions())
            .Where(_ => _.Id == key.AsId()).Take(1).AsEnumerable().SingleOrDefault());
 }
コード例 #17
0
 string GetStreamForEventHorizonKey(EventHorizonKey key)
 {
     return($"{_streamPrefix}-geodesics-{key}");
 }
コード例 #18
0
 public ulong GetOffset(EventHorizonKey key)
 {
     return(0);
 }
コード例 #19
0
 public void SetOffset(EventHorizonKey key, ulong offset)
 {
 }
コード例 #20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="key"></param>
 /// <param name="offset"></param>
 /// <param name="partitionKey"></param>
 /// <returns></returns>
 public static Offset From(EventHorizonKey key, ulong offset, string partitionKey)
 {
     return(new Offset {
         Id = key.AsId(), Value = offset, PartitionKey = partitionKey
     });
 }
コード例 #21
0
 /// <summary>
 /// Gets the id representation of the <see cref="EventHorizonKey"/>
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static string AsId(this EventHorizonKey key)
 {
     return(key.Application.Value.ToString() + "-" + key.BoundedContext.Value.ToString());
 }
コード例 #22
0
        /// <inheritdoc />
        public ulong GetOffset(EventHorizonKey eventHorizon)
        {
            var offset = GetOffsetDoc(eventHorizon);

            return(offset?.Value ?? 0);
        }