示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            var config = new ServerConfig();

            Configuration.Bind(config);
            var userContext = new UserContext(config.MongoDB);

            var repo = new UserRepository(userContext);

            services.AddSingleton <IUserRepository>(repo);

            var producer = new UserProducer(config.Kafka);

            services.AddSingleton <IUserProducer>(producer);


            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title       = "User API",
                    Version     = "v1",
                    Description = "User API etc",
                });
            });
        }
示例#2
0
        static async Task Main(string[] args)
        {
            var cts = new CancellationTokenSource();

            Console.CancelKeyPress += (_, e) => {
                e.Cancel = true; // prevent the process from terminating.
                cts.Cancel();
            };

            var config = new KafkaConfig();

            Console.WriteLine($"UserProducer producing on {config.UsersTopic}. Enter user names, Ctrl+C to exit.");

            var cache = new SubjectNameSchemaCache();

            cache.Init(config.UsersTopic);

            var userProducer = new UserProducer
                               (
                config: config,
                cts: cts,
                name: "UserProducer",
                topicName: config.UsersTopic,
                cache: cache
                               );

            await userProducer.Produce();
        }