经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » 编程经验 » 查看文章
ABP微服务系列学习-使用Tye启动微服务
来源:cnblogs  作者:饭勺oO  时间:2023/3/3 8:53:26  对本文有异议

Tye是微软开源的一款开发人员工具, 能够用于简化微服务以及分布式应用程序的开发、测试以及部署过程。
Tye 的首要目标是简化微服务的开发,具体方式包括仅用一行命令执行多项服务、在容器中使用依赖项目,以及使用简单的方法探索其他服务的地址。

安装tye

首先我们安装tye,使用dotnet cli命令。

  1. dotnet tool install -g Microsoft.Tye --version "0.11.0-alpha.22111.1"

安装完后即可使用tye命令

配置tye

首先我们使用tye init命令初始化tye.yaml配置文件
结构大致入下:

  1. name: funshow
  2. services:
  3. - name:
  4. project:
  5. - name:
  6. project:

我们需要在配置文件中添加我们的服务,包括绑定端口,环境变量等。
这里完整的配置文件如下:

  1. name: FunShow
  2. services:
  3. - name: auth-server
  4. project: apps/auth-server/src/FunShow.AuthServer/FunShow.AuthServer.csproj
  5. bindings:
  6. - protocol: https
  7. port: 44322
  8. env:
  9. - Kestrel__Certificates__Default__Path=../../../../etc/dev-cert/localhost.pfx
  10. - Kestrel__Certificates__Default__Password=e8202f07-66e5-4619-be07-72ba76fde97f
  11. - name: administration-service
  12. project: services/administration/src/FunShow.AdministrationService.HttpApi.Host/FunShow.AdministrationService.HttpApi.Host.csproj
  13. bindings:
  14. - protocol: https
  15. port: 44367
  16. env:
  17. - Kestrel__Certificates__Default__Path=../../../../etc/dev-cert/localhost.pfx
  18. - Kestrel__Certificates__Default__Password=e8202f07-66e5-4619-be07-72ba76fde97f
  19. - name: identity-service
  20. project: services/identity/src/FunShow.IdentityService.HttpApi.Host/FunShow.IdentityService.HttpApi.Host.csproj
  21. bindings:
  22. - protocol: https
  23. port: 44388
  24. env:
  25. - Kestrel__Certificates__Default__Path=../../../../etc/dev-cert/localhost.pfx
  26. - Kestrel__Certificates__Default__Password=e8202f07-66e5-4619-be07-72ba76fde97f
  27. - name: logging-service
  28. project: services/logging/src/FunShow.LoggingService.HttpApi.Host/FunShow.LoggingService.HttpApi.Host.csproj
  29. bindings:
  30. - protocol: https
  31. port: 45124
  32. env:
  33. - Kestrel__Certificates__Default__Path=../../../../etc/dev-cert/localhost.pfx
  34. - Kestrel__Certificates__Default__Password=e8202f07-66e5-4619-be07-72ba76fde97f
  35. - name: web-gateway
  36. project: gateways/web/src/FunShow.WebGateway/FunShow.WebGateway.csproj
  37. bindings:
  38. - protocol: https
  39. port: 44325
  40. env:
  41. - Kestrel__Certificates__Default__Path=../../../../etc/dev-cert/localhost.pfx
  42. - Kestrel__Certificates__Default__Password=e8202f07-66e5-4619-be07-72ba76fde97f

bindings表示我们绑定https以及端口号。
env里面配置了我们的本地开发HTTPS证书。

创建本地证书

上面配置里面我们有加载本地证书,那么怎么创建证书呢,在tye仓库中也有说明
https://github.com/dotnet/tye/blob/main/docs/tutorials/hello-tye/00_run_locally.md#generate-the-certificate
仓库中是在linux环境,但是在windows环境中localhost.conf是一样的

  1. [req]
  2. default_bits = 2048
  3. default_keyfile = localhost.key
  4. distinguished_name = req_distinguished_name
  5. req_extensions = req_ext
  6. x509_extensions = v3_ca
  7. [req_distinguished_name]
  8. commonName = Common Name (e.g. server FQDN or YOUR name)
  9. commonName_default = localhost
  10. commonName_max = 64
  11. [req_ext]
  12. subjectAltName = @alt_names
  13. [v3_ca]
  14. subjectAltName = @alt_names
  15. basicConstraints = critical, CA:false
  16. keyUsage = keyCertSign, cRLSign, digitalSignature,keyEncipherment
  17. [alt_names]
  18. DNS.1 = localhost
  19. DNS.2 = 127.0.0.1

创建etc/dev-cert目录,在目录下添加localhost.conf文件,内容如上。
然后执行dotnet dev-certs命令

  1. dotnet dev-certs https -v -ep localhost.pfx -p e8202f07-66e5-4619-be07-72ba76fde97f -t

就会在目录下面生成localhost.pfx证书文件。

使用tye运行微服务

在目录下面执行tye运行命令

  1. tye run --watch

效果如下:


当然运行服务前我们需要把我们的基础服务都启动,如数据库,消息队列,redis等。
在tye dashboard可以查看服务的日志以及Metrics信息



下面是服务启动页面。
网关服务



认证服务


到这我们后端功能就基本完成啦

原文链接:https://www.cnblogs.com/fanshaoO/p/17170714.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号