21.微服务工具箱(运行时)学习:了解Micro、复习、列出所有服务

21.微服务工具箱(运行时)学习:了解Micro、复习、列出所有服务

因为新版Micro工具已经弃用了consul,加入了etcd的支持,所以我们把服务注册放入到etcd中

package main

import (
    "github.com/micro/go-micro"
    "github.com/micro/go-micro/registry"
    "github.com/micro/go-micro/registry/etcd"
    "micro/Services"
    "micro/ServicesImpl"
)

func main() {
    //consulReg := consul.NewRegistry(registry.Addrs("localhost:8500"))
    etcdReg := etcd.NewRegistry(registry.Addrs("106.12.72.181:23791")) //注册服务到etcd中
    myservice := micro.NewService(
        micro.Name("test.xiahualou"+".com"),
        micro.Address(":8001"),
        micro.Registry(etcdReg),
    )
    Services.RegisterTestServiceHandler(myservice.Server(), new(ServicesImpl.TestService))
    myservice.Run()
}

使用micro工具查看服务和调用服务

1.查看服務

micro --registry=etcd --registry_address=106.12.72.181:23791 list services

21.微服务工具箱(运行时)学习:了解Micro、复习、列出所有服务

2.获取服务

micro --registry=etcd --registry_address=106.12.72.181:23791 get service test.xiahualou.com

21.微服务工具箱(运行时)学习:了解Micro、复习、列出所有服务

3.调用服务

micro --registry=etcd --registry_address=106.12.72.181:23791 call test.xiahualou.com TestService.Call "{\"id\":3}"
# 调用的时候必须要加上Endpoint,传入的json参数key要用双引号括起来,反引号转义

使用micro工具的Dashboard

micro --registry=etcd --registry_address=106.12.72.181:23791 web

下图是service在micro的dashboard中查看到的详细信息

21.微服务工具箱(运行时)学习:了解Micro、复习、列出所有服务

相关文章:

  • 2021-05-02
  • 2021-10-25
  • 2021-11-18
  • 2021-06-20
猜你喜欢
  • 2021-05-16
  • 2021-09-08
  • 2022-12-23
  • 2023-01-26
  • 2021-09-27
  • 2022-12-23
  • 2021-12-18
相关资源
相似解决方案