Consul+Ocelot+.Net Core Api+IdentityServer4(四)

ASP.NET Core微服务框架Ocelot+Consul+IdentityServer4实战演练 一、背景介绍 API网关的流行源于最近几年移动应用与企业间接口对接的兴起,使得原来单一的PC客户端,变化到PC客户端、各种浏览器、手机移动端及智能终端等。同时系统之间大部分都不是单独运行,经常会涉及与其他系统对接、共享数据的需求。随着微服务架构概念的提出,API网关成为了微服务架构的一个标配组件。随着业务快速发展,面向手机移动应用业务越来越多,为了减少客户端与服务的耦合,节约后端微服务的开发成... 阅读详情

服务项目建立

  1. 新建一个Asp.net Core Web 空项目,取名为Ids4
  2. 引入 IdentityServer4.AspNetIdentity Nuget包
  3. 引入 Consul Nuget包

修改配置文件

修改配置文件 appsettings.json

{
  "ids4Config": {
    "ApiScopes": [
      {
        "Name": "Gateway",
        "DisplayName": "OcelotGateway"
      }
    ],
    "ApiResources": [
      {
        "Name": "idsApi",
        "DisplayName": "idsApiName",
        "Scopes": [ "Gateway" ]
      }
    ],
    "Clients": [
      {
        "ClientId": "Ocelot",
        "ClientSecrets": [ "123456" ],
        "AllowedGrantTypes": "ClientCredentials",
        "AllowedScopes": [ "Gateway" ]
      }
    ]
  },
  "urls": "http://localhost:6003", //当前服务的网址,根据项目属性中配置的进行修改
  "consul_urls": "http://localhost:8500", //Consul服务的地址
  "service_id": "1", //当前服务的ID
  "service_name": "ids4" //当前服务的名称
}

读取IdentityServer4配置信息

  1. 新建一个类,命名 ApiConfig
namespace Ids4.Config
{
    public class ApiConfig
    {
        public string Name { get; set; }

        public string DisplayName { get; set; }
    }
}
  1. 新建一个类,命名 ClientConfig
namespace Ids4.Config
{
    public class ClientConfig
    {
        public string ClientId { get; set; }

        public List<string> ClientSecrets { get; set; }

        public string AllowedGrantTypes { get; set; }

        public List<string> AllowedScopes { get; set; }
    }
}
  1. 新建一个类,命名 Id4ServerConfig
namespace Ids4.Config
{
    public class Id4ServerConfig
    {
        /// <summary>
        /// 获得Api资源信息
        /// </summary>
        /// <param name="section"></param>
        /// <returns></returns>
        public static IEnumerable<ApiResource> GetApiResources(IConfigurationSection section)
        {
            List<ApiResource> resource = new List<ApiResource>();
            if (section != null)
            {
                List<ApiConfig> configs = new List<ApiConfig>();
                section.Bind("ApiResources", configs);
                foreach (var config in configs)
                {
                    resource.Add(new ApiResource(config.Name, config.DisplayName)
                    {
                        Scopes = { config.Name }
                    });
                }
            }
            return resource;
        }

        public static IEnumerable<ApiScope> GetApiScopes(IConfigurationSection section)
        {
            List<ApiScope> resource = new List<ApiScope>();
            if (section != null)
            {
                List<ApiConfig> configs = new List<ApiConfig>();
                section.Bind("ApiScopes", configs);
                foreach(var config in configs)
                {
                    resource.Add(new ApiScope(config.Name, config.DisplayName));
                }
            }
            return resource;
        }

        /// <summary>
        /// 获得客户端信息
        /// </summary>
        /// <param name="section"></param>
        /// <returns></returns>
        public static IEnumerable<Client> GetClients(IConfigurationSection section)
        {
            List<Client> clients = new List<Client>();
            if (section != null)
            {
                List<ClientConfig> configs = new List<ClientConfig>();
                section.Bind("Clients", configs);
                foreach(var config in configs)
                {
                    Client client = new Client();
                    client.ClientId = config.ClientId;
                    List<Secret> secrets = new List<Secret>();
                    foreach(var secret in config.ClientSecrets)
                    {
                        secrets.Add(new Secret(secret.Sha256()));
                    }
                    client.ClientSecrets = secrets;
                    GrantTypes grantTypes = new GrantTypes();
                    var allowedGrantTypes = grantTypes.GetType().GetProperty(config.AllowedGrantTypes);
                    client.AllowedGrantTypes = allowedGrantTypes == null ? GrantTypes.ClientCredentials :
                        (ICollection<string>)allowedGrantTypes.GetValue(grantTypes, null);
                    client.AllowedScopes = config.AllowedScopes;
                    clients.Add(client);
                }
            }
            return clients;
        }
    }
}

修改Startup.cs类,启动IdentityServer4及向Consul注册

修改ConfigureServices方法

public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();
    services.AddConnections();
    var section = _configuration.GetSection("ids4Config");
    services.AddIdentityServer()
        //设备临时签名凭据
        .AddDeveloperSigningCredential()
        //从配置文件中获得Api资源
        .AddInMemoryApiResources(Id4ServerConfig.GetApiResources(section))
        //从配置文件中获得Client集合
        .AddInMemoryClients(Id4ServerConfig.GetClients(section))
        .AddInMemoryApiScopes(Id4ServerConfig.GetApiScopes(section));
}

修改Configure方法

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseRouting();

    app.UseIdentityServer();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllers();
    });

    //向Consul服务注册
    PublicHelper.RegSerToConsul(_configuration);
}

PublicHelper类和ApiA、ApiB项目中的PublicHelper一样

添加健康检查接口 HealthController

namespace Ids4.Contoller
{
    [Route("api/[controller]")]
    [ApiController]
    public class HealthController : ControllerBase
    {
        public string Get() => "ok";
    }
}

修改【Ocelot项目】中的相关配置文件

  1. 引入 IdentityServer4 Nuget包
  2. 引入 IdentityServer4.AccessTokenValidation Nuget包
  3. 修改【OcelotConfig.json】
{
      "DownstreamPathTemplate": "/api/{url}", //下游地址模板,转发模板
      "DownstreamScheme": "http", //下游转发协议
      "UpstreamPathTemplate": "/ApiA/{url}", //上游匹配模板
      "UpstreamHttpMethod": [ "Get", "Post" ], //上游匹配协议
      "UseServiceDiscovery": true, //是否进行服务发现
      "ServiceName": "ApiA", //服务名称
      "LoadBalancerOptions": {
        "Type": "RoundRobin" //负载均衡,转徇
      },
      //身份验证
      "AuthenticationOptions": {
        "AuthenticationProviderKey": "OcelotProviderKey",
        "AllowScopes": []
      }
    }
  1. 修改【Startup.cs】

public void ConfigureServices(IServiceCollection services)
{
    string authKey = "OcelotProviderKey";
    services.AddAuthentication("Bearer")
        .AddJwtBearer(authKey, op => {
            op.Authority = "http://localhost: 6003"; // 授权认证的地址(Ids4服务地址)
                op.Audience = "idsApi";//ApiResources的name(Ids4服务)
                op.RequireHttpsMetadata = false;
            op.SaveToken = true;
            op.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
            {
                ValidateAudience = false
            };
        });
    services.AddOcelot().AddConsul();
}

至此,所有配置已完成

启动相关项目测试

  1. 同时启动【OcelotService】、【ApiA】、【ApiB】、【Ids4】四个项目

  2. 通过 http://localhost:6000/ApiA/UserInfo 查询 ApiA 中的接口,可以看到 401错误
    401

  3. 通过 http://localhost:6000/connect/token 查询token
    token

  4. 把查询 的token放到Header中(使用Bearer),如下图
    Bearer token

  5. 再次访问 http://localhost:6000/ApiA/UserInfo,成功获得,如下图
    UserInfo

至此,所有配置完成,验证结果OK

ASP.NET Core微服务架构之Ocelot从基础入门到实战 一、课程介绍 微服务(Microservices Architecture)是一种架构风格,一个大型复杂软件应用由一个或多个微服务组成。系统中的各个微服务可被独立部署,各个微服务之间是松耦合的。每个微服务仅关注于完成一件任务并很好地完成该任务。在所有情况下,每个任务代表着一个小的业务能力。 随着.NET Core的关注度持续上升, 微服务及云原生应用开发上采用.NET Core也越来越多,... 阅读详情

相关推荐

微服务》》NetCore Consul动态伸缩+Ocelot 网关 缓存 自定义缓存 + 限流、熔断、超时 等服务治理 + ids4鉴权

【代码】NetCore Consul动态伸缩+Ocelot 网关。

Kaizen的博客 759

Consul+Ocelot+.Net Core Api+IdentityServer4(三)

Ocelot+.NET Core Api

redmethod的博客 364

dotnet-NETCoreOcelotIdentityServer4Consul基础架构实现

.NET Core Ocelot IdentityServer4 Consul 基础架构实现

.NET Core + Ocelot + IdentityServer4 + Consul 基础架构实现

先决条件 关于 Ocelot 针对使用 .NET 开发微服务架构或者面向服务架构提供一个统一访问系统的组件。 参考 本文将使用 Ocelot 构建统一入口的 Gateway。 关于 IdentityServer4 IdentityServer4 是一个 OpenID Connect 和 OAuth 2.0 框架用于 ASP.NET Core 。IdentityServer4 在你的应用程序...

weixin_30908103的博客 889

python课程教学大纲-《Python语言基础》课程教学大纲

《Python语言基础》课程教学大纲课程名称:Python语言基础课程类别:专业选修课适用专业:电子信息工程考核方式:考查总学时、学分:32学时1.5学分其中讲授16学时,实验10学时,其他6学时一、课程性质、教学目标使学生在全面了解Python技术历史、现状与发展趋势的基础上,系统掌握Python基本概念、编程思想以及程序设计技术,具备熟练的Python编程技能和面向对象软件设计技术思想,完成本...

weixin_37988176的博客 3720

从零开始:如何用Python手绘波特图并分析电路稳定性

本文详细介绍了如何使用Python绘制波特图并分析电路稳定性,涵盖从基础理论到实际应用的完整流程。通过NumPy和Matplotlib实现频域分析,包括RC低通滤波器和RLC带通滤波器的案例,以及相位裕度计算等高级技巧,为电子工程师提供了一套高效的电路分析解决方案。

hhh00的博客 371

微服务网关从零搭建——(三)Ocelot网关 + identity4

增加验证服务 1.创建名为AuthService 的core 空项目 2.修改startup文件 using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using ConsulRegisterHelper; using Microsof...

weixin_30702413的博客 238

Unity游戏开发客户端Lua基础

Unity游戏开发客户端面经之 lua 篇

Sea3752的博客 1万+

如何使用 ABAP 代码调度一个 ABAP 程序,让其以后台作业的方式运行

笔者之前的教程,介绍了如何使用 SM36 一系列事务码,将一个 ABAP 程序,调度成以后台作业方式运行的详细步骤。 38. 如何让 ABAP 报表在后台作业的模式下运行 大家如果照着上述文章的步骤走一遍,会发现这些手动执行的步骤还是有些繁琐的。 有没有可能让这一切都自动化起来,即通过 ABAP 代码去完成呢?当然可以。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1944

【STK】手把手教你利用STK进行导弹和反导仿真04 - STK/MMT模块03 导弹飞行工具应用案例

飞行设置的工具栏就在附加窗口的中间,首先点击左边的General,修改这个项目的名字。然后在下拉的System中选择导弹的类型,这里我们选择远程。(4)输出数据文件到STK,任务窗口里选择Export Manager项,飞行数据输出到STK。项目可以命名为Test;(1)首先建立新项目,点击Flight菜单中的New Flight选项,见下图。首先看世界地图中间的红圈,是一个导弹形状的图标,这个图标表示的是导弹的发射点。选择下面的Export Manager,依次勾选红框的选项。我们拖动这个导弹的图标,

weixin_44184852的博客 1631

NET Core + Ocelot + IdentityServer4 + Consul

NET Core + Ocelot + IdentityServer4 + Consul 原文:NET Core + Ocelot + IdentityServer4 + Consul.NET Core + Ocelot + IdentityServer4 + Consul 基础架构实现 先决条件 关于 Ocelot 针对使...

weixin_30879833的博客 203

在 SAP BTP 中通过 MTA 自动创建 Service Broker 的原理与实战

本文探讨了如何在SAP BTP的Cloud Foundry环境中通过MTA部署自动创建和注册Service Broker。传统手动注册方式存在依赖管理员、环境一致性差等问题。通过MTA部署可实现自动化Broker注册,利用占位符生成安全凭证,并确保平台端与应用端认证一致。文章详细解析了关键配置参数,包括create-service-broker标志、Broker名称、认证凭据和访问URL的设置方法。这种基础设施即代码(IaC)方式能提升DevOps实践水平,使服务注册成为应用部署流水线的有机组成部分。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 200

集成.NET Core+Swagger+Consul+Polly+Ocelot+IdentityServer4+Exceptionless+Apollo的入门级微服务开发框架

Github源代码地址 https://github.com/PeyShine/Demo.MicroServer Apollo配置中心 Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境、不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限、流程治理等特性,适用于微服务配置管理场景。 由于各个项目配置都需要读取基础的配置信息,这边在内网的Centos(101)上部署了Apollo的环境,并为项目添加了一些基础配置信息,配置如图 Consul C.

Peyshine 1265

游戏开发中的CV:实时动作捕捉与虚拟交互

游戏开发中的CV:实时动作捕捉与虚拟交互​ ,人工智能,计算机视觉,大模型,AI,在当今游戏产业中,玩家对游戏体验的要求日益提高,追求更加真实、沉浸的交互感受。计算机视觉(Computer Vision,CV)技术的飞速发展,为游戏开发带来了革命性的突破,其中实时动作捕捉与虚拟交互技术更是成为提升游戏品质的核心驱动力。

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 16万+

SerDes系列之如何选择AC耦合电容

交流耦合电容用于隔离PCB互连时的直流分量(Common-mode voltage),同时传递交流分量(Voltage swing),其作用类似于一个高通滤波器,但是,如果电容容值选取不当,使用过程中会产生信号质量问题,典型的应用场景:当包含相同的长串1或0的NRZ数据应用于该高通滤波器时,会发生低频电压跌落,导致低频模式相关抖动(PDJ)。

一只豌豆象的博客 2351

.NET CORE 微服务架构--网关篇(Ocelot)

Ocelot是一个用.NET Core实现并且开源的API网关,它功能强大,包括了:路由、请求聚合、服务发现、认证、鉴权、限流熔断、并内置了负载均衡器与Service Fabric、Butterfly Tracing集成。这些功能只都只需要简单的配置即可完成,下面我们会对这些功能的配置一一进行说明。 介绍 简单的来说Ocelot是一堆的asp.net coremiddleware组成的一个管道。当它拿到请求之后会用一个request builder来构造一个HttpRequestMessage发到下游.

落花流水 6862

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

【转】.NET Core + Ocelot + IdentityServer4 + Consul 基础架构实现

作者:Zhang_Xiang 原文地址:.NET Core + Ocelot + IdentityServer4 + Consul 基础架构实现 先决条件 关于 Ocelot 针对使用 .NET 开发微服务架构或者面向服务架构提供一个统一访问系统的组件。参考 本文将使用 Ocelot 构建统一入口的 Gateway。 关于 IdentityServer4 ...

weixin_30687587的博客 175

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

.NET Core + Ocelot + IdentityServer4 + Consul 基础架构实现 ...

.NET Core + Ocelot + IdentityServer4 + Consul 基础架构实现 先决条件 关于 Ocelot 针对使用 .NET 开发微服务架构或者面向服务架构提供一个统一访问系统的组件。参考 本文将使用 Ocelot 构建统一入口的 Gateway。 关于 IdentityServer4 IdentityServ...

测试0901-1 399

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

[Hei-Ocelot-Gateway ].Net Core Api网关Ocelot的开箱即用版本

写在前面很多neter都有在用Ocelot做Api网关,但是Ocelot又不像kong或者其他网关一样,开箱即用。它需要你单独开一个web项目来部署,这样很多同学都在做重复的事了。这里...

dotNET跨平台 467

Consul+Ocelot+.Net Core Api+IdentityServer4(二)

Ocelot 配置

redmethod的博客 355

如何快速上手Ocelot:.NET API网关完整安装与使用指南

Ocelot是一个专为ASP.NET设计的开源API网关,支持.NET 6.0、7.0和8.0框架。它能够帮助开发者轻松实现路由、负载均衡、认证授权等功能,是构建微服务架构的理想选择。本文将带你快速掌握Ocelot的安装配置与基础使用方法。 ## 🚀 准备工作:环境要求 在开始前,请确保你的开发环境满足以下条件: - .NET 6.0/7.0/8.0 SDK - ASP.NET Core运行

gitblog_00490的博客 464

(1)ASP.NET Core3.1 Ocelot介绍

1.简介 Ocelot原本设计仅为与.NET Core一起使用的,它是一个.NET API网关,作为面向使用.NET运行微型服务/面向服务的体系结构需要统一的系统入口点,即当客户端(Web站点,手机APP)等访问Web API的时候,Ocelot作为统一的入口点会根据请求地址分发到对应的API站点去(寻址)。而Ocelot还集成很多功能,例路由,认证,授权,限速等等功能点,Ocelot官网还建议认证这块最好跟身份验证(IdentityServer4)一起使用,承载令牌轻松集成。具体详情大家可以去官网(ht.

ElegantHedgehog的博客 218
上一篇: Consul+Ocelot+.Net Core Api+IdentityServer4(三)
下一篇: JavaScript Date类型扩展
redmethod
博客等级 码龄14年 1粉丝 12原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值