예제 #1
0
        public PublisherSubscriberFixture()
        {
            var env = Environment.GetEnvironmentVariable("KAFKA_DIFF_ENV");

            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile(
                path: string.IsNullOrWhiteSpace(env)
                        ? "settings.json"
                        : $"settings.{env}.json",
                optional: false)
                          .AddEnvironmentVariables();

            var configuration = builder.Build();

            var settings = new Settings();

            configuration.Bind(settings);

            PublisherAutofacModule.KafkaServer  = settings.KafkaServer;
            SubscriberAutofacModule.KafkaServer = settings.KafkaServer;

            var publisherContainerBuilder = new ContainerBuilder();

            publisherContainerBuilder.RegisterModule <PublisherAutofacModule>();
            publisherContainerBuilder.RegisterType <SubmitController>().SingleInstance();
            var publisherContainer = publisherContainerBuilder.Build();

            _submitController = publisherContainer.Resolve <SubmitController>();

            var subscriberContainerBuilder = new ContainerBuilder();

            subscriberContainerBuilder.RegisterModule <SubscriberAutofacModule>();
            subscriberContainerBuilder.RegisterType <DiffController>().SingleInstance();
            var subscriberContainer = subscriberContainerBuilder.Build();

            _diffController = subscriberContainer.Resolve <DiffController>();
            _diffController.StartWorker();
        }