rpc错误:代码=不可用desc = Go代码中的连接已关闭 [英] rpc error: code = Unavailable desc = connection closed in Go code
问题描述
我正在进行 Dgraph
和 Go
集成.我正在尝试访问 Go
中的 Dgraph
查询,为此,我正在使用 github.com/dgraph-io/dgo
库.
I am working on Dgraph
and Go
integration.I am trying to access Dgraph
query in Go
and for that I am using github.com/dgraph-io/dgo
library.
这是代码:
package main
import (
"bytes"
"context"
"fmt"
"io/ioutil"
"log"
"github.com/dgraph-io/dgo"
"github.com/dgraph-io/dgo/protos/api"
"google.golang.org/grpc"
)
func main() {
query := `{
people(func: has(name)) {
name
follows{
name
}
}
}`
conn, err := grpc.Dial("x.x.x.x:8000", grpc.WithInsecure())
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
dgraphClient := dgo.NewDgraphClient(api.NewDgraphClient(conn))
txn := dgraphClient.NewTxn()
txn.Query(ctx, query)
request := &api.Request{
Query: query,
}
response, err := txn.Do(ctx, request)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(response.Json))
}
我遇到错误 rpc错误:尝试运行代码时,代码=不可用desc =连接已关闭.由于我是 Go
和 DGraph数据库
的新手,所以我的知识非常有限.
I am getting error rpc error: code = Unavailable desc = connection closed when I an trying to run code.
As I am new to the Go
and DGraph Database
I have very limited knowledge.
任何人都可以帮忙,需要进行哪些确切的更改以解决此错误.
Can anyone please help what exact changes need to be done to fix this error.
推荐答案
端口8000上的服务仅是UI.如果要使用gRPC,则必须在端口9080中调用它.绝不要8080、8000、6080等.检查此文档 https://dgraph.io/docs/deploy/ports-usage/#types-of-ports
The service at the port 8000 is the UI only. If you wanna use gRPC you have to call it in the port 9080. Never 8080, 8000, 6080, and so on. Check this docs https://dgraph.io/docs/deploy/ports-usage/#types-of-ports
在此示例中 https://github.com/dgraph-io/dgo/blob/a38d5eaacbf8667cc2d6e7b40bd0978cede4000f/examples_test.go#L35
它正在使用端口9180.因为测试群集的偏移量为100.这意味着Alpha中的所有端口都增加了100个整数.因此,Alpha中的所有端口都必须考虑偏移量.其余的API是8180,而gRPC是9180.
It is using the port 9180. Cuz the Cluster for testing has an offset of 100. That means that all ports in the Alpha increases 100 ints. So, all ports in Alpha have to take into account the offset. The rest API is 8180 and the gRPC is 9180.
在通常情况下,您在学习事物时就不会考虑使用偏移量.因此,您可能启动了一个普通集群.默认端口为9080.
In the usual cases, you would never think about using offset when you are learning things. So you probably started a normal cluster. And the default port is 9080.
这篇关于rpc错误:代码=不可用desc = Go代码中的连接已关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!