Ejemplo n.º 1
0
        /// <inheritdoc/>
        public override async Task Open(OpenTunnel request, IServerStreamWriter <CommittedEventStreamWithContext> responseStream, ServerCallContext context)
        {
            try
            {
                using (var tunnel = new QuantumTunnel(_serializer, responseStream, _logger, context.CancellationToken))
                {
                    var application    = request.Application.To <Dolittle.Applications.Application>();
                    var boundedContext = request.BoundedContext.To <BoundedContext>();
                    var events         = request
                                         .Events
                                         .Select(@event => @event.ToArtifact())
                                         .ToArray();
                    var tenantOffsets = request.Offsets.ToTenantOffsets();

                    var subscription = new EventParticleSubscription(events);

                    _logger.Information($"Opening up a quantum tunnel for bounded context '{boundedContext}' in application '{application}'");

                    var singularity = new Singularity(application, boundedContext, tunnel, subscription);
                    _eventHorizon.GravitateTowards(singularity, tenantOffsets);
                    tunnel.Collapsed += _ => _eventHorizon.Collapse(singularity);

                    await tunnel.Open(request.Offsets.ToTenantOffsets()).ConfigureAwait(false);

                    _logger.Information($"Quantum tunnel collapsed for bounded context '{boundedContext}' in application '{application}'");
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Problems opening tunnel");
            }

            await Task.CompletedTask.ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        AsyncServerStreamingCall <grpc.CommittedEventStreamWithContext> GetOpenTunnel()
        {
            var tunnel = new OpenTunnel
            {
                Application    = _destinationKey.Application.ToProtobuf(),
                BoundedContext = _destinationKey.BoundedContext.ToProtobuf(),
                ClientId       = Guid.NewGuid().ToProtobuf()
            };

            tunnel.Offsets.AddRange(_tenantOffsetRepository.Get(_tenants.All, _destinationKey).Select(_ => _.ToProtobuf()));
            tunnel.Events.AddRange(_events.Select(_ => _.ToProtobuf()));
            return(_client.Open(tunnel));
        }