微服务框架—搭建 go-micro环境详解编程语言
2023-06-13 09:11:48 时间
//下载,不同的版本文件名称不一样,我们这里选择protoc-3.9.1-win64.zip protoc-3.9.1-win64.zip
//解压到目标文件架,我们以e:/dev为例 e:/dev/protoc-3.9.1-win64 //添加e:/dev/protoc-3.9.1-win64/bin到环境变量path3.安装protoc-gen-micro插件
//这个插件主要作用是通过.proto文件生成适用于go-micro的代码 go get -u -v github.com/micro/protoc-gen-micro4.安装 consul
//下载windows版本 https://www.consul.io/downloads.html //解压到 e:/dev/consul
添加e:/dev/consul到环境变量path
使用如下指查看是否安装成功,如下所示安装成功
consul Usage: consul [--version] [--help] command [ args ] Available commands are: acl Interact with Consuls ACLs agent Runs a Consul agent catalog Interact with the catalog config Interact with Consuls Centralized Configurations connect Interact with Consul Connect debug Records a debugging archive for operators5.创建微服务 hello world
//使用如下指令创建微服务 micro new techidea8.com/microapp/hello Creating service go.micro.srv.hello in E:/winlion/gopath/src/techidea8.com/microapp/hello ├── main.go ├── plugin.go ├── handler │ └── hello.go ├── subscriber │ └── hello.go ├── proto/hello │ └── hello.proto ├── Dockerfile ├── Makefile ├── README.md └── go.mod6.生成适配proto的golang代码
go get -u github.com/golang/protobuf/{proto,protoc-gen-go} go get -u github.com/micro/protoc-gen-micro compile the proto file hello.proto: cd E:/winlion/gopath/src/techidea8.com/microapp/hello protoc --proto_path=.:$GOPATH/src --go_out=. --micro_out=. proto/hello/hello.proto
#切换到项目目录下 cd /d E:/winlion/gopath/src/techidea8.com/microapp/hello # 根据proto生成文件 protoc --proto_path=. --go_out=. --micro_out=. proto/hello/hello.proto # 启动应用 go run main.go 2019/08/19 13:00:46 Transport [http] Listening on [::]:54689 2019/08/19 13:00:46 Broker [http] Connected to [::]:54690 2019/08/19 13:00:46 Registry [mdns] Registering node: go.micro.srv.hello-4851dce2-ab5d-4e4c-801e-44dae5d93f26 2019/08/19 13:00:46 Subscribing go.micro.srv.hello-4851dce2-ab5d-4e4c-801e-44dae5d93f26 to topic: go.micro.srv.hello 2019/08/19 13:00:46 Subscribing go.micro.srv.hello-4851dce2-ab5d-4e4c-801e-44dae5d93f26 to topic: go.micro.srv.hello # 查看是否启动 micro list services go.micro.srv.hello topic:go.micro.srv.hello7.启动restful api接口支持支持
注意其中的 namespace参数,我们每一个微服务都属于一个命名空间,通过api暴露出来该命名空间后,满足go.micro.srv.*格式的微服务都可以访问。如go.micro.srv.hello可以通过如下格式访问
# 访问http://127.0.0.1:8080/hello/call micro api --namespace=go.micro.srv 2019/08/19 13:07:11 Registering API Default Handler at / 2019/08/19 13:07:11 HTTP API Listening on [::]:8080 2019/08/19 13:07:11 Transport [http] Listening on [::]:54934 2019/08/19 13:07:11 Broker [http] Connected to [::]:54935 2019/08/19 13:07:11 Registry [mdns] Registering node: go.micro.api-1753185c-b8e1-49c4-aa0f-617f243a8e2a
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/18129.html
cgojavalinuxwindows相关文章
- Vue3.0实现todolist之跳转路由(常用的push,back,go等方法)
- go语言集成开发工具:GoLand 2022.2.1中文版「免账号登录」
- 让你最快上手 go 的 pprof 性能分析大杀器
- GO系列(3)-协程 线程 进程 基础
- go-zero 成长之路—微服务电商实战系列(七、并发处理工具MapReduce的使用)
- 【火绒安全周报】 CS:GO 交易网站被黑 /微软员工意外泄漏登录凭据
- go-redis版本不一致导致CPU使用率问题
- 「Go工具箱」将文件大小转换成Kb、Mb、Gb就用这个库:go-humanize
- 「Go工具箱」一个对语义化版本进行解析、比较的库:go-version
- Go微服务(二)——Protobuf详细入门
- Go-包管理-go get(二)
- Go-包管理-go build(二)
- Go-HTTP服务(二)
- Go语言inject库:依赖注入
- Go语言纯文本文件的读写操作
- Go语言圣经–示例: 并发的Echo服务详解编程语言
- Go-连接Redis-学习go-redis包详解编程语言
- Go语言实现RSA和AES加解密
- Linux上构建Go开发环境(linux安装go环境)
- SQL Server和Go组合,助力数据库计算更高效(sqlserver加go)
- 便捷使用Go编程连接Redis(go连接redis)
- 用Go语言深入Redis缓存技术(用go写redis)
- 去oracle之路探索从零开始的新挑战(go 连oracle)
- js判断当页面无法回退时关闭网页否则就history.go(-1)