/// <inheritdoc/> public override async Task Open(Runtime.Grpc.Interaction.OpenTunnel request, IServerStreamWriter <Runtime.Grpc.Interaction.CommittedEventStreamWithContext> responseStream, ServerCallContext context) { try { var tunnel = new QuantumTunnel(_serializer, responseStream, context.CancellationToken, _logger); var application = request.Application.ToConcept <Application>(); var boundedContext = request.BoundedContext.ToConcept <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 += qt => _eventHorizon.Collapse(singularity); await tunnel.Open(request.Offsets.ToTenantOffsets()); _logger.Information($"Quantum tunnel collapsed for bounded context '{boundedContext}' in application '{application}'"); } catch (Exception ex) { _logger.Error(ex, "Problems opening tunnel"); } await Task.CompletedTask; }
AsyncServerStreamingCall <Runtime.Grpc.Interaction.CommittedEventStreamWithContext> GetOpenTunnel() { var tunnel = new Runtime.Grpc.Interaction.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)); }