示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime)
        {
            app.UseAuthentication();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();

            app.UseCors("default");
            app.UseMvc();

            var confRegisterConsul = ConfigHelper.ReadConfigByName("IsRegisterConsul", "");
            var IsRegisterConsul   = false;

            Boolean.TryParse(confRegisterConsul, out IsRegisterConsul);

            //注册服务
            if (IsRegisterConsul)
            {
                ServiceContract serviceEntity = new ServiceContract
                {
                    IP          = Configuration["Service:Ip"],
                    Port        = Convert.ToInt32(Configuration["Service:Port"]),
                    ServiceName = Configuration["Service:Name"],
                    ConsulIP    = Configuration["Consul:IP"],
                    ConsulPort  = Convert.ToInt32(Configuration["Consul:Port"])
                };
                ConsulCommon.RegisterConsul(app, lifetime, serviceEntity);
            }

            string      KafkaUploadTopic = ConfigHelper.ReadConfigByName("KafkaUploadTopic");
            string      KafkaMsgTopic    = ConfigHelper.ReadConfigByName("KafkaMsgTopic");
            UploadLogic uploadLogic      = new UploadLogic();


            //总署订阅消息
            KafKaLogic.GetInstance().Pull((KafKaContract, topic) =>
            {
                if (topic == KafkaUploadTopic)       //总署订阅消息
                {
                    Task.Run(() =>
                    {
                        uploadLogic.PullUploadMsg(KafKaContract);
                    });
                }
                else if (topic == KafkaMsgTopic)      //隶属关订阅消息
                {
                    Task.Run(() =>
                    {
                        uploadLogic.PullMsg(KafKaContract);
                    });
                }
            });

            var model = new UploadContract();

            model.InsertTime = DateTime.Now;

            var str = SerializeHelper.serializeToString(model);

            LogHelper.logInfo(str);
            //定时任务
            QuartzLogic quartz = new QuartzLogic();
            var         cron   = ConfigHelper.ReadConfigByName("QuartzTime");

            quartz.ExecuteByCron <MyJobLogic>(cron);
        }