设为首页 加入收藏

TOP

微服务(入门学习五):identityServer4+ocelot+consul实现简单客户端模式(二)
2019-09-17 18:23:45 】 浏览:31
Tags:服务 入门 学习 identityServer4 ocelot consul 实现 简单 客户端 模式
Period": "1m",
// 统计时间段:1s, 5m, 1h, 1d // "PeriodTimespan": 15, // 多少秒之后客户端可以重试 // "Limit": 5 // 在统计时间段内允许的最大请求数量 //},//负载均衡: //RoundRobin轮流发送; //LeastConnection – 将请求发往最空闲的那个服务器 //NoLoadBalance – 总是发往第一个请求或者是服务发现 "LoadBalancerOptions": { "Type": "RoundRobin" }, //上游地址配置 "UpstreamPathTemplate": "/test/{everything}", //上游支持的请求类型 "UpstreamHttpMethod": [ "GET", "POST" ], "AuthenticationOptions": { "AuthenticationProviderKey": "TestKey", "AllowedScopes": [] } }, { "DownstreamPathTemplate": "/api/Token", "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { "Host": "127.0.0.1", "Port": 3322 } ], "UpstreamPathTemplate": "/GetToken", "UpstreamHttpMethod": [ "Get" ] } ], "GlobalConfiguration": { "BaseUrl": "https://localhost:8596", //consul服务器地址和ip "ServiceDiscoveryProvider": { "Host": "localhost", "Port": 8500 } } }

3.4 修改program文件,添加访问地址,以及ocelot的配置文件

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

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

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
            .UseUrls("http://localhost:8596")
            .ConfigureAppConfiguration(conf =>
            {
                conf.AddJsonFile("ocelot.json", optional: false, reloadOnChange: true);
            })
           .UseStartup<Startup>();
    }
}

 

 

测试

1.首先开启consul服务

 

 

 2.接下来把服务注册到consul当中,启动ConsulServer

 

 

 

3.启动IdentityServer4Test和ocelotServerTest服务

 

 

 

4.通过postMan获取token(正式开发中不会如此使用)

 

 

 5.根据获取的token去请求Consulserver当中的数据,可正常返回数据

 

 

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Split命令 下一篇稀疏贴图 SparseTexture

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目