コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // "https://payday-calculation-engine.apps.cac.preview.pcf.manulife.com/api/calculationengine/"
            KafkaConfigSettings kafkaConfigSettings = KafkaConfigureServices.InitializeKafka(services, Configuration);

            services.AddSingleton <IHostedService, PayDayConnector>();

            services.AddDiscoveryClient(Configuration);
            services.AddSingleton <DiscoveryHttpMessageHandler>();

            services.AddHttpClient("payday-calc-engine", c =>
            {
                c.BaseAddress = new Uri(kafkaConfigSettings.CalculationEngineEndpoint);
            })
            .AddHttpMessageHandler <DiscoveryHttpMessageHandler>()
            .AddTypedClient <IMessageHandler <ICalculationEngineService>, CalculationEngineService>();

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Kafka Listener Manager", Version = "v1"
                });
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
コード例 #2
0
        public void KafkaConfuguration_GetControllerTopicName()
        {
            var configSettings = new KafkaConfigSettings()
            {
                SaslKerberosPrincipal = "blah", GroupId = "group", ControllerTopicName = "test"
            };
            var objectUnderTest = new KafkaConfiguration(configSettings);

            Assert.True(objectUnderTest.ControllerTopicName == "test");
        }
コード例 #3
0
        public void KafkaConfuguration_GetLocalConsumerConfig()
        {
            var configSettings = new KafkaConfigSettings()
            {
                SaslKerberosPrincipal = "blah", GroupId = "group", ApiVersionRequest = false, IncludeSasl = false
            };
            var objectUnderTest = new KafkaConfiguration(configSettings);
            var config          = objectUnderTest.ConsumerConfig;

            Assert.Null(config.SaslKerberosPrincipal);
        }
コード例 #4
0
        public void KafkaConfuguration_GetParticipantAllocationsTopicName()
        {
            var configSettings = new KafkaConfigSettings()
            {
                SaslKerberosPrincipal = "blah", GroupId = "group", ParticipantAllocationsTopicName = "test"
            };
            var objectUnderTest = new KafkaConfiguration(configSettings);
            var config          = objectUnderTest.ProducerConfig;

            Assert.True(objectUnderTest.ParticipantAllocationsTopicName == "test");
        }
        public KafkaSettingsFactory(
            IReadOnlyDictionary <IMessageFlow, string> messageFlows2CoonectionStringsMap,
            IEnvironmentSettings environmentSettings,
            Offset offset)
        {
            _offset = offset;

            const string KafkaTargetTopicToken = "targetTopic";
            const string KafkaPollTimeoutToken = "pollTimeout";
            const string KafkaInfoTimeoutToken = "infoTimeout";

            _flows2ConsumerSettingsMap = new Dictionary <IMessageFlow, KafkaConfigSettings>();
            foreach (var entry in messageFlows2CoonectionStringsMap)
            {
                var messageFlow      = entry.Key;
                var connectionString = entry.Value;

                var kafkaConfig = new KafkaConfigSettings();

                var configuredKafkaSettings = JsonConvert.DeserializeObject <Dictionary <string, object> >(connectionString);
                if (!configuredKafkaSettings.TryGetValue(KafkaTargetTopicToken, out var rawtargetTopic))
                {
                    throw new InvalidOperationException($"Kafka config is invalid for message flow {messageFlow.GetType().Name}. Required parameter \"{KafkaTargetTopicToken}\" was not found. ConnectionString: {connectionString}");
                }

                kafkaConfig.Topic       = (string)rawtargetTopic;
                kafkaConfig.PoolTimeout = !configuredKafkaSettings.TryGetValue(KafkaPollTimeoutToken, out object rawPollTimeout)
                                              ? TimeSpan.FromSeconds(5)
                                              : TimeSpan.Parse((string)rawPollTimeout);
                kafkaConfig.InfoTimeout = !configuredKafkaSettings.TryGetValue(KafkaInfoTimeoutToken, out object rawInfoTimeout)
                                              ? TimeSpan.FromSeconds(5)
                                              : TimeSpan.Parse((string)rawInfoTimeout);
                var explicitlyProcessedTokens = new[] { KafkaTargetTopicToken, KafkaPollTimeoutToken, KafkaInfoTimeoutToken };
                var kafkaClientSpecific       = configuredKafkaSettings.Where(e => !explicitlyProcessedTokens.Contains(e.Key))
                                                .ToDictionary(x => x.Key, x => x.Value);

                kafkaClientSpecific["group.id"] = messageFlow.Id.ToString() + '-' + environmentSettings.EnvironmentName;

                foreach (var defaultSetting in _defaultKafkaClientSpecificSettings)
                {
                    if (kafkaClientSpecific.ContainsKey(defaultSetting.Key))
                    {
                        continue;
                    }

                    kafkaClientSpecific.Add(defaultSetting.Key, defaultSetting.Value);
                }

                kafkaConfig.KafkaClientSpecific = kafkaClientSpecific;

                _flows2ConsumerSettingsMap.Add(messageFlow, kafkaConfig);
            }
        }
コード例 #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            KafkaConfigSettings kafkaConfigSettings = KafkaConfigureServices.InitializeKafka(services, Configuration);

            services.AddSingleton <IHostedService, PayDayConnector>();
            services.AddSingleton <IRPSDBProcessManager, RPSDBProcessManager>();
            services.AddSingleton <IMessageHandler <IOutputManager>, OutputManager>();
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Generate Output", Version = "v1"
                });
            });
        }
コード例 #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            KafkaConfigSettings kafkaConfigSettings = KafkaConfigureServices.InitializeKafka(services, Configuration);

            services.AddSingleton <ICalculationEngineService, CalculationEngineService>();
            services.AddSingleton <IMessagePublisher, MessagePublisher>();
            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Calculation Engine", Version = "v1"
                });
            });

            services.AddDiscoveryClient(Configuration);
        }
コード例 #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            KafkaConfigSettings kafkaConfigSettings = KafkaConfigureServices.InitializeKafka(services, Configuration);

            services.AddSingleton <IAggregationManager, AggregationManager>();
            services.AddSingleton <IMessageHandler <IMetaManager>, MetaManager>();
            services.AddSingleton <IMessageHandler <IAllocationManager>, AllocationManager>();
            //PayDayConnector as Hosted Service that runs when the app is started.
            services.AddSingleton <IHostedService, PayDayConnector>();
            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Aggregator API", Version = "v1"
                });
            });
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
コード例 #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            KafkaConfigSettings kafkaConfigSettings = KafkaConfigureServices.InitializeKafka(services, Configuration);

            services.AddSingleton <IFileProcessorService, FileProcessorService>();
            services.AddSingleton <IFileManager, FileManager>();
            services.AddSingleton <IMessageManager, MessageManager>();
            services.AddSingleton <IMessagePublisher, MessagePublisher>();
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "File Processor", Version = "v1"
                });
            });
        }