com.foo.service.micro 是我们的目标服务,micro.http.broker 是默认的中间件服务。 在调用前,使用get命令查看服务的详情,端点定义,元数据和节点信息等 通过命令行调用服务 互动模式的命令不同,因为非互动模式下支持了更多的功能 在启动web后,可以进入https://127.0.0.1:8082/client 创建一个项目,布局如下: main.go
通过命令行工具调用服务
luslin@local:~/software/zipkin$ MICRO_REGISTRY=etcd micro list services com.foo.service.micro go.micro.web micro.http.broker
luslin@local:~/software/zipkin$ MICRO_REGISTRY=etcd micro get service com.foo.service.micro service com.foo.service.micro version latest ID Address Metadata com.foo.service.micro-06796a43-b7ee-47e9-ae4e-2fbd208de511 192.168.1.88:34441 protocol=grpc,registry=etcd,server=grpc,transport=grpc,broker=http com.foo.service.micro-fafcc3b2-e1b0-475e-b1b7-45799abb8775 192.168.1.88:43877 broker=http,protocol=grpc,registry=etcd,server=grpc,transport=grpc Endpoint: Micro.Call Request: { name string } Response: { msg string } Endpoint: Micro.PingPong Metadata: stream=true Request: {} Response: {} Endpoint: Micro.Stream Metadata: stream=true Request: {} Response: {} Endpoint: Micro.Handle Metadata: subscriber=true,topic=go.micro.service.micro Request: { say string } Response: {}
luslin@local:~/software/zipkin$ MICRO_REGISTRY=etcd micro call com.foo.service.micro Micro.Call '{"name":"bill"}' { "msg": "Hello bill" }
通过互动模式调用服务
luslin@local:~/software/zipkin$ MICRO_REGISTRY=etcd micro cli micro> help Commands: call Call a service deregister Deregister a service exit Exit the CLI get Get service info health Get service health help CLI usage list List services, peers or routes publish Publish a message to a topic quit Exit the CLI register Register a service stats Get service stats stream Stream a call to a service
micro> list com.foo.service.micro go.micro.web micro.http.broker micro> get com.foo.service.micro service com.foo.service.micro version latest ID Address Metadata com.foo.service.micro-06796a43-b7ee-47e9-ae4e-2fbd208de511 192.168.1.88:34441 broker=http,protocol=grpc,registry=etcd,server=grpc,transport=grpc com.foo.service.micro-fafcc3b2-e1b0-475e-b1b7-45799abb8775 192.168.1.88:43877 broker=http,protocol=grpc,registry=etcd,server=grpc,transport=grpc Endpoint: Micro.Call Request: { name string } Response: { msg string } Endpoint: Micro.PingPong Metadata: stream=true Request: {} Response: {} Endpoint: Micro.Stream Metadata: stream=true Request: {} Response: {} Endpoint: Micro.Handle Metadata: topic=go.micro.service.micro,subscriber=true Request: { say string } Response: {} micro> call com.foo.service.micro Micro.Call {"name":"lin"} // 这里不需要使用json字符串 { "msg": "Hello lin" }
通过web链接调用服务
通过代码调用服务
luslin@local:~/go/workspace/tools/micro-hello-cli$ tree . ├── go.mod ├── go.sum ├── main.go ├── micro_hello_cli ├── plugin.go └── proto └── hello ├── micro.pb.go ├── micro.pb.micro.go └── micro.proto
package main import ( "context" "fmt" "github.com/micro/go-micro/v2" hello "micro-hello-cli/proto/hello" ) func main() { // New Service service := micro.NewService( // 创建服务 micro.Name("com.foo.service.micro.clinet"), micro.Version("latest"), ) service.Init() // 服务初始化 resp,err := hello.NewMicroService("com.foo.service.micro",service.Client()).Call(context.TODO(),&hello.Request{Name: "lin"}) // 创建client并调用call方法 if err != nil { panic(err) } fmt.Println(resp.Msg) } 结果 Hello lin
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算