Giter Site home page Giter Site logo

spark's Introduction

spark

spark是一个基于netcore的分布式微服务框架。spark有星火的意思,意义为星星之火可以燎原。

demo

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        //添加火花
        services.AddSpark(builder =>
        {
            builder
            //添加认证
            .AddAuthentication(Configuration)
            //添加SmarkSql数据库支持
            .AddSmartSql()
            //添加消息总线
            .AddEventBus(x => x.UseRabbitMQ(Configuration))
            //负载均衡
            .AddLoadBalancer()
            //服务发现
            .AddServiceDiscovery(x => x.UseRemote(Configuration))
            //添加分布式日志
            .AddLog(x => x.UseEventBusLog(Configuration))
            //添加检索引擎
            .AddElasticesearch(Configuration);
        });
        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        // 日志
        loggerFactory.AddSparkLog(app, "Spark.Samples.WebApi");

        app
            .UseGlobalErrorMiddleware()
            .UseHttpMethodMiddleware()
            .UseStatisticsMiddleware()
            .UseAuthentication();

        app.UseMvc();
    }
}

配置中心demo

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration(
                (hostingContext, builder) =>
                {
                    //获取全局变量
                    builder.AddRemoteConfig(
                        options =>
                        {
                            options.App = "TestApp";
                            options.Key = "GlobalConfig";
                            options.Optional = true;
                            options.ReloadOnChange = true;
                            options.Url = Environment.GetEnvironmentVariable("ConfigUrl");
                            options.Interval = 10000;
                        });
                })
            .ConfigureLogging(
                (hostingContext, logging) =>
                {
                    logging.AddConfiguration(hostingContext.Configuration.GetSection("GlobalConfig:Logging"));
                })
            .UseStartup<Startup>();
}

spark's People

Contributors

my6521 avatar zhangkeyuan avatar

Watchers

Lord Lei avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.