Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

关于registry 设置 consul的问题 #120

Closed
bluedragonflyliu opened this issue Sep 10, 2019 · 12 comments
Closed

关于registry 设置 consul的问题 #120

bluedragonflyliu opened this issue Sep 10, 2019 · 12 comments
Labels
question Further information is requested

Comments

@bluedragonflyliu
Copy link

bluedragonflyliu commented Sep 10, 2019

  1. 192.168.1.3 启动网关 micro api --handler=api --namespace=com.test.api
  2. 192.168.1.4 启动服务api/user go run main.go --registry_address=192.168.1.3
  3. 192.168.1.4 启动服务srv/user go run main.go --registry_address=192.168.1.3

访问 192.168.1.3:8080没有问题但是如果换成consul后

  1. 192.168.1.3启动consul consul agent -dev -ui -client 0.0.0.0
  2. 192.168.1.3 启动网关 MICRO_REGISTRY=consul MICRO_REGISRY_ADDRESS=192.168.1.3 micro api --namespace=com.test.api --handler=api
  3. 192.168.1.4 启动服务api/user go run main.go --registry=consul --registry_address=192.168.1.3
  4. 192.168.1.4 启动服务srv/user go run main.go --registry=consul --registry_address=192.168.1.3

会报错user 的srv 找不到但是 user api 能访问,访问consul的ui也能看到user的srv是正常的 我想问是因为设置或启动或代码缺少参数吗

micro 和go-micro 的版本都是micro version 1.9.1

@printfcoder
Copy link
Owner

明显有问题 MICRO_REGISRY_ADDRESS -> MICRO_REGISTRY_ADDRESS

@printfcoder
Copy link
Owner

printfcoder commented Sep 11, 2019

但是写错MICRO_REGISRY_ADDRESS这个相当于没有写,会默认使用127.0.0.1,也就相当于是192.168.1.3

@printfcoder
Copy link
Owner

是user-api->user-srv这一步不通?把代码脱敏放上来看看

@bluedragonflyliu
Copy link
Author

bluedragonflyliu commented Sep 12, 2019

我想用一个最简单的例子看看有没有我提到的问题但是却出现另外一个问题
我在目录micro_demo创建应用
micro version 1.9.1

  1. micro new micro_demo/api/user --type api --namespace com.abc
  2. micro new micro_demo/srv/user --type srv --namespace com.abc
  3. protoc --proto_path=$GOPATH/src:. --go_out=. --micro_out=. srv/user/proto/user/user.proto
  4. protoc --proto_path=$GOPATH/src:. --go_out=. --micro_out=. api/user/proto/user/user.proto
  5. 修改api user里的client 和 handler 的srv user proto引入路径修改成 user "micro_demo/srv/user/proto/user"
  6. 进入目录运行 api/user 和 srv/user

go run main.go --registry=consul --registry_address=192.168.1.3
srv/user 运行
但是api/user build command-line-arguments: cannot load micro_demo/srv/user/proto/user: cannot find module providing package micro_demo/srv/user/proto/user

@printfcoder
Copy link
Owner

micro_demo/srv/user/proto/user -> github.com/你的site/micro_demo/srv/....,或其它domain下。参考gopath下的每个公司的包名路径

@bluedragonflyliu
Copy link
Author

bluedragonflyliu commented Sep 16, 2019

问题依旧在
go 是GOPATH路径
go/src/github.com/mytest/micro_demo/api/user
micro new srv/user api/user 后
protoc 运行完
问题还是srv正常运行api cannot load github.com/mytest/micro_demo/srv/user/proto/user: cannot find module providing package github.com/mytest/micro_demo/srv/user/proto/user
go version go1.12.9 linux/amd64

@printfcoder
Copy link
Owner

把代码传到你的仓库中,我看看

@bluedragonflyliu
Copy link
Author

@bluedragonflyliu
Copy link
Author

bluedragonflyliu commented Sep 17, 2019

关于第一个有关consul的问题,好像知道表面原因了,是新的micro创建client的方式和以前不一样了

@bluedragonflyliu
Copy link
Author

bluedragonflyliu commented Sep 17, 2019

micro new 找不到srv/user/proto/user 的问题我又试了一下

  1. 新建虚机centos7 最新的
  2. 安上micro 的环境和依赖
  3. micro new 新建
  4. 运行protoc --proto_path=.:$GOPATH/src --go_out=. --micro_out=. mytest/api/user/proto/user/user.proto 会提示 github.com/micro/go-micro/api/proto/api.proto: File not found.
  5. 直接git clone后protoc 通过
  6. 将 api/user 里client 和 handler 依赖改成现有srv/user/proto/user
  7. 运行srv/user 正常
  8. 运行api/user 还是找不到srv/user/proto

go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://goproxy.io"
GOROOT="/usr/local/bin/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/bin/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/go/src/github.com/abc/mytest/srv/user/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build962096667=/tmp/go-build -gno-record-gcc-switches"

@printfcoder printfcoder added the question Further information is requested label Sep 18, 2019
@printfcoder
Copy link
Owner

printfcoder commented Sep 18, 2019

Emm,我感觉生成proto文件的那一步指令很奇怪。一般我是切到服务proto目录的上级,相当于micro_demo/api/user目录,然后执行命令,命令参考如下:

protoc --proto_path=.:$GOPATH/src --go_out=. --micro_out=. ./proto/user/user.proto

这样生成的文件与引用方式就是很干净的,不清楚为什么要加上mytest这个与项目目录并不相关的目录。

引用大致如下:

import (
	"github.com/bluedragonflyliu/micro_demo/micro_demo/api/user/client"
	user "github.com/bluedragonflyliu/micro_demo/micro_demo/api/user/proto/user"
	"github.com/micro/go-micro"
	"github.com/micro/go-micro/util/log"
)

@bluedragonflyliu
Copy link
Author

是模板中go.mod的问题

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants