.net core微服务之网关 - 六指狂魔肉球猫
source link: https://www.cnblogs.com/AsprosL/p/18020704
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
.net core微服务之网关
随笔- 18 文章- 1 评论- 32 阅读-
58892
一:apisix
doc:https://apisix.apache.org/zh/docs/apisix/getting-started/README/
github:https://github.com/apache/apisix
二:Kong
github:https://github.com/Kong/kong
三:Ocelot
github:https://github.com/ThreeMammals/Ocelot
四:janus
github:https://github.com/motiv-labs/janus
前置条件:docker,yaml
microservice.yaml
View Code
目前使用docker启动apisix,需要依赖etcd,
etcd: container_name: etcd hostname: etcd image: bitnami/etcd volumes: - ./etcd/data:/bitnami/etcd environment: ETCD_ENABLE_V2: "true" ALLOW_NONE_AUTHENTICATION: "yes" ETCD_ADVERTISE_CLIENT_URLS: "http://etcd:2379" #https://github.com/apache/apisix-dashboard/issues/2756 需要更换为host域名不能使用0.0.0.0 ETCD_LISTEN_CLIENT_URLS: "http://0.0.0.0:2379" ports: - "2379:2379/tcp" networks: caseor_bridge: ipv4_address: 172.0.10.8 apisix: container_name: apisix hostname: apisix image: apache/apisix volumes: - ./apisix/log:/usr/local/apisix/logs - ./apisix/conf/config.yaml:/usr/local/apisix/conf/config.yaml:ro depends_on: - etcd ports: - "9088:9088/tcp" - "9180:9180/tcp" - "127.0.0.1:9090:9090/tcp" networks: caseor_bridge: ipv4_address: 172.0.10.9 apisix-dashboard: container_name: apisix-dashboard image: apache/apisix-dashboard depends_on: - etcd ports: - "9188:9188" volumes: - ./apisix/conf/dashboard.yaml:/usr/local/apisix-dashboard/conf/conf.yaml networks: caseor_bridge: ipv4_address: 172.0.10.10
使用apisix dashboard的时候 会出现一个bug,需要在启动etcd的时候设置ETCD_ADVERTISE_CLIENT_URLS为host域名 而不能使用0.0.0.0
apisix的config yaml
View Code
dashboard的config yaml
View Code
在文件夹下启动
docker-compose -f microservice.yaml up
本地打开 http://localhost:9188 使用admin ,admin 登录
配置路由信息
这里使用的是nacos作为服务发现,具体查看nacos配置
启动以8083端口的服务
dotnet run --urls=http://*:8083
打开浏览器调试下接口
接下来使用网关请求
再启动以8084端口的服务
nacos中出现了两个实例
继续使用网关请求
在log中的access.log 可以查看到网关请求到不同端口的服务
几个注意点:
1.etcd的ETCD_ADVERTISE_CLIENT_URLS 需要更换为host域名不能使用0.0.0.0
2.apisix的nacos配置在 config.yaml中的discovery
尽量使用host名称
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK