All Projects → ShaoHans → OcelotSample

ShaoHans / OcelotSample

Licence: other
Ocelot使用案例,结合IdentityServer4进行鉴权,结合Consul进行服务治理

Programming Languages

C#
18002 projects
HTML
75241 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to OcelotSample

User.api
集成网关、身份认证、Token授权、微服务、.netcore等的基于CQRS的微服务开发框架示例
Stars: ✭ 109 (+87.93%)
Mutual labels:  consul, apigateway
Surging
Surging is a micro-service engine that provides a lightweight, high-performance, modular RPC request pipeline. The service engine supports http, TCP, WS,Grpc, Thrift,Mqtt, UDP, and DNS protocols. It uses ZooKeeper and Consul as a registry, and integrates it. Hash, random, polling, Fair Polling as a load balancing algorithm, built-in service gove…
Stars: ✭ 3,088 (+5224.14%)
Mutual labels:  consul, apigateway
Sitko.Core
Sitko.Core is a set of libraries to help build .NET Core applications fast
Stars: ✭ 46 (-20.69%)
Mutual labels:  consul, identityserver4
honeycomb
本项目用于验证一系列开源项目
Stars: ✭ 13 (-77.59%)
Mutual labels:  consul, apigateway
RentHouseWeb
使用 go+docker+go-micro微服务框架开发的租房网系统,符合RESTful架构风格。
Stars: ✭ 28 (-51.72%)
Mutual labels:  consul
nomad-box
Nomad Box - Simple Terraform-powered setup to Azure of clustered Consul, Nomad and Traefik Load Balancer that runs Docker/GoLang/Java workloads. NOTE: Only suitable in dev environments at the moment until I learn more Terraform, Consul, Nomad, Vault :P
Stars: ✭ 18 (-68.97%)
Mutual labels:  consul
spring-projects
Some spring sample projects
Stars: ✭ 24 (-58.62%)
Mutual labels:  consul
local-hashicorp-stack
Local Hashicorp Stack for DevOps Development without Hypervisor or Cloud
Stars: ✭ 23 (-60.34%)
Mutual labels:  consul
doteasy.rpc
Inspired by microservices, a lightweight framework that looks like a rabbit, based on NET Core 2.0 Standard 2 core library
Stars: ✭ 62 (+6.9%)
Mutual labels:  consul
consulator
Import and synchronize your Consul KV data from JSON and YAML
Stars: ✭ 27 (-53.45%)
Mutual labels:  consul
k8s-deployer
Deploy Kubernetes service and store retrieved information in the Consul K/V store
Stars: ✭ 23 (-60.34%)
Mutual labels:  consul
vault-consul-monitoring
Sample project to explore monitoring Vault and Consul with telegraf/influxdb/grafana
Stars: ✭ 52 (-10.34%)
Mutual labels:  consul
sample-spring-cloud-microservices-future
sample microservices illustrating usage of non netflix spring cloud components spring cloud loadbalancer, spring cloud gateway and spring cloud consul
Stars: ✭ 42 (-27.59%)
Mutual labels:  consul
vault-consul-docker
HashiCorp Vault with Consul backend in Docker
Stars: ✭ 20 (-65.52%)
Mutual labels:  consul
micro-service-practice
OpenStack+Docker+RestAPI+OAuth/HMAC+RabbitMQ/ZMQ+OpenResty/HAProxy/Nginx/APIGateway+Bootstrap/AngularJS+Ansible+K8S/Mesos/Marathon构建/探索微服务最佳实践。
Stars: ✭ 25 (-56.9%)
Mutual labels:  apigateway
skycloud-base
🔥springcloud脚手架,配置中心(apollo/nacos) 注册中心(consul/nacos) 分布式事物(seata) 调用链(skywalking) 日志(ELK)监控(prometheus与grafana) 等,适合学习与快速开发使用
Stars: ✭ 80 (+37.93%)
Mutual labels:  consul
sample-micronaut-microservices
sample micronaut application illustrates using basic microservices patterns like distributed configuration and service discovery with Consul, distributed tracing with Zipkin, inter-service communication with micronaut http client
Stars: ✭ 38 (-34.48%)
Mutual labels:  consul
meshery
Meshery, the cloud native manager
Stars: ✭ 1,587 (+2636.21%)
Mutual labels:  consul
flightpath
XDS to run Envoy as an edge proxy for Consul Connect.
Stars: ✭ 15 (-74.14%)
Mutual labels:  consul
micro-starter
Micro 微服务实践
Stars: ✭ 391 (+574.14%)
Mutual labels:  consul

Ocelot使用案例

Build status

解决方案中各项目介绍

  • APIGatewayByOcelot:该项目的作用是API网关,采用 Ocelot 组件
  • ApiOne:该项目为下游API服务测试项目,需使用 Consul 组件注册自己
  • ApiTwo:该项目为下游API服务测试项目,需使用 Consul 组件注册自己
  • Ids4Center.Mvc:该项目是服务认证授权中心,使用 IdentityServer4 组件
  • AccessApiOne:客户端项目,访问需要授权的API接口

Consul服务治理

  1. 下载地址
  2. 解压下载完成之后的压缩包,通过cmd命令行定位到consul.exe所在的目录,运行命令:consul.exe agent --dev
  3. 通过浏览器访问:http://localhost:8500/ui ,此Consul管理端可以查看注册的服务信息

创建下游API服务项目

  1. 创建两个Asp.net Core WebApi项目
  2. 下载 Consul nuget包
  3. 在appsettings.json文件中配置Consul服务端信息
        /*服务治理第三方组件Consul相关配置参数*/
       "ServiceDiscovery": {
     	"ServiceName": "ApiOne", //本WebApi项目的服务名称,可以随便取名,将显示Consul的管理页面上,届时通过该服务名查找可用的服务站点
     	"Consul": {
     	  "HttpEndpoint": "http://127.0.0.1:8500",
     	  "TcpEndpoint": {
     		"Address": "127.0.0.1",
     		"Port": 8600
     	  }
     	}
       }
    
  4. 编写服务注册代码,向Consul注册本项目提供的API服务,详见 RegisterToConsulExtension.cs 代码

APIGatewayByOcelot网关项目

  1. 下载 Ocelot nuget包,已经包含Consul的服务发现功能
  2. 添加Ocelot.json配置文件,配置参数详见文件

    需要注意的是,如果下游API服务需要授权才能访问,只要添加如下配置参数,并在StartUp类中编写相关代码 "AuthenticationOptions": { "AuthenticationProviderKey": "TestKey", "AllowedScopes": [] }

Ids4Center.Mvc认证授权中心

  1. 下载 IdentityServer4 nuget包
  2. 配置客户端和APIResource参数

AccessApiOne客户端

  1. 下载IdentityModel nuget包
  2. 由于ApiOne应用的API接口是需要授权后才能访问,不能通过浏览器直接访问,所以单独下一个客户端项目访问

运行解决方案

  1. 必须先运行Consul,cmd命令:consul.exe agent --dev
  2. 启动项目ApiOne和ApiTwo,你可以打开项目所在目录通过命令行命令,每个项目都可以运行多个实例,如:打开ApiOne项目根目录,直接运行如下命令

    dotnet run --ip 127.0.0.1 --port 8000
    dotnet run --ip 127.0.0.1 --port 8001
    这样就启动了ApiOne项目的两个实例,能接受ip和port参数是因为自己写的代码才支持这样运行,同理可以允许多个ApiTwo项目的实例

  3. 启动Ids4Center.Mvc项目,该项目的端口写死了12345,不需要改动,因为客户端项目AccessApiOne也是写死了这个端口
  4. 启动APIGatewayByOcelot网关项目,端口默认5000,SSL端口是5001。此时可以通过浏览器访问:https://localhost:5001/two/values 可以看到返回结果, 但访问 https://localhost:5001/one/values 时并未看到任何结果,通过F12查看请求,可以看到服务端返回401(未授权),若要访问该接口,可以启动 客户端AccessApiOne项目查看结果。
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].