我正在尝试在DGraph数据库中进行一个突变,但是当我运行代码时,它会抛出下一个错误:
rpc错误:代码=不可用desc =连接关闭退出状态1
我在端口8000中使用dGraph和docker,我在这里的代码是golang:
package main
import (
"fmt"
"context"
"encoding/json"
"log"
dgo "github.com/dgraph-io/dgo"
api "github.com/dgraph-io/dgo/protos/api"
grpc "google.golang.org/grpc"
)
type Person struct {
Name string `json:"name,omitempty"`
Lastname string `json:"lastname,omitempty"`
}
func main() {
conn, err := grpc.Dial("localhost:8000", grpc.WithInsecure())
if err != nil {
log.Fatal(err)
}
defer conn.Close()
dgraphClient := dgo.NewDgraphClient(api.NewDgraphClient(conn))
p := Person {
Name: "Giovanni",
Lastname: "Mosquera Diazgranados",
}
txn := dgraphClient.NewTxn()
ctx := context.Background()
defer txn.Discard(ctx)
pb, err := json.Marshal(p)
if err != nil {
log.Fatal(err)
}
mu := &api.Mutation{
SetJson: pb,
}
res, err := txn.Mutate(ctx, mu)
if err != nil {
fmt.Println("Aqui toy")
log.Fatal(err)
} else {
fmt.Println(res)
}
}如何解决这个错误来连接我的DGraph并进行变异?
发布于 2020-08-31 15:11:46
欢迎来到堆栈溢出!
为了让代码在本地使用DGraph的独立版本,我必须更改2件事情:
9080。容器公开3个端口:8000、8080、9080。使用8080或8000我得到了您提到的相同的错误。v2导入。不确定您正在运行的是哪个版本的DGraph服务器,因此您可能不需要这样做。但是,如果您有一个新的服务器,您需要这些导入:import (
dgo "github.com/dgraph-io/dgo/v2"
api "github.com/dgraph-io/dgo/v2/protos/api"
)发布于 2020-12-15 16:34:21
端口8000是为ratel提供的,这是随dgraph而来的。要使用dgraph客户机进行突变,您需要连接到公开的grpc端口,这通常是在9080上进行的。
https://stackoverflow.com/questions/63672856
复制相似问题