コード例 #1
0
 bool TryGetEventHorizonsConfiguration(ConsumerSubscriptionArguments arguments, out EventHorizonsPerMicroserviceConfiguration eventHorizonsConfiguration, out SubscriptionResponse failureResponse)
 {
     eventHorizonsConfiguration = default;
     failureResponse            = default;
     try
     {
         Log.CheckingIfProducerTenantExists(_logger, arguments.ProducerTenant);
         if (!ProducerTenantExists(arguments.ProducerTenant))
         {
             Log.ProducerTenantIsNotConfigured(_logger, arguments.ProducerTenant);
             failureResponse = new SubscriptionResponse
             {
                 Failure = new ProtobufContracts.Failure
                 {
                     Id     = SubscriptionFailures.MissingConsent.ToProtobuf(),
                     Reason = $"There are no consents configured for Producer Tenant {arguments.ProducerTenant}",
                 }
             };
             return(false);
         }
         eventHorizonsConfiguration = _getEventHorizonsConfiguration(arguments.ProducerTenant).Value;
         return(true);
     }
     catch (CannotParseConfiguration ex)
     {
         Log.NoConsentsConfiguredForProducerTenant(_logger, arguments.ProducerTenant);
         failureResponse = new SubscriptionResponse
         {
             Failure = new ProtobufContracts.Failure
             {
                 Id     = SubscriptionFailures.MissingConsent.ToProtobuf(),
                 Reason = $"There are no consents configured for Producer Tenant {arguments.ProducerTenant}. {ex.Message}",
             }
         };
         return(false);
     }
 }
コード例 #2
0
    bool TryGetConsentFromConfiguration(
        ConsumerSubscriptionArguments arguments,
        EventHorizonsPerMicroserviceConfiguration eventHorizonsConfiguration,
        out ConsentId consentId,
        out SubscriptionResponse failureResponse)
    {
        consentId       = default;
        failureResponse = default;
        Log.CheckingConsents(
            _logger,
            arguments.Partition,
            arguments.PublicStream,
            arguments.ProducerTenant,
            arguments.ConsumerTenant,
            arguments.ConsumerMicroservice);

        if (!eventHorizonsConfiguration.TryGetValue(arguments.ConsumerMicroservice, out var eventHorizonConfiguration))
        {
            failureResponse = CreateNoConsentsConfiguredResponse(
                arguments,
                $"There are no consents configured for Consumer Microservice {arguments.ConsumerMicroservice}");
            return(false);
        }
        foreach (var consent in eventHorizonConfiguration.Consents)
        {
            if (consent.ConsumerTenant == arguments.ConsumerTenant.Value && consent.Stream == arguments.PublicStream.Value && consent.Partition == arguments.Partition.Value)
            {
                consentId = consent.Consent;
                return(true);
            }
        }
        failureResponse = CreateNoConsentsConfiguredResponse(
            arguments,
            $"There are no consents configured for Consumer Tenant {arguments.ConsumerTenant} from Public Stream {arguments.PublicStream} and Partition {arguments.Partition}");
        return(false);
    }