rpc error: code = Unimplemented desc = RPC method not implemented
Asked Answered
J

3

6

I have been trying to create a grpc client in Go and I have followed the correct instructions as shown in the official grpc site. When I start my grpc server written in node.js, the connection works well but upon compiling the protocol buffer in Go and creating a client interface with the correct grpc client configurations, I run into an error.

Here is my what I have in my identity.pb.go.

type IdentityServiceClient interface {
    CreateUser(ctx context.Context, in *GoogleIdToken, opts ...grpc.CallOption) (error, *UserInfo)
}

type simpleServerClient struct {
    connection *grpc.ClientConn
}

func NewSimpleServerClient(connection *grpc.ClientConn) IdentityServiceClient {
    return &simpleServerClient{connection}
}

func (simpleClient *simpleServerClient) CreateUser(ctx context.Context, in *GoogleIdToken, opts ...grpc.CallOption) (error, *UserInfo) {
    out := new(UserInfo)
    err := simpleClient.connection.Invoke(ctx, "/protobuf.IdentityService/CreateUser", in, out, opts...)

    if err != nil {
        return err, nil
    }

    return nil, out
}

here is the identity.proto

syntax="proto3";

package protobuf;

service IdentityService {
    rpc CreateUser (GoogleIdToken) returns (UserInfo) {}
}

message GoogleIdToken {
    string token = 1;
}

message UserInfo {
    string name = 1;
    string email = 2;
    message Profile {
        string imageUrl = 1;
        string lastUpdated = 2;
    };
    Profile profile = 3;
    string token = 4;
}

here is my main.go

import pb "github.com/Duncanian/iam-gateway/server/protobuf"

func grpcConnection() {
    conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure())
    if err != nil {
        log.Fatalf("Failed to start gRPC connection: %v", err)
    }

    defer conn.Close()

    client := pb.NewSimpleServerClient(conn)

    err, _ = client.CreateUser(context.Background(), &pb.GoogleIdToken{Token: "tevgvybububvvg"})
    if err != nil {
        log.Fatalf("Failed to create user: %v", err)
    }
    log.Println("Created user!")
}

I expect the output of passing a correct google auth token to get me the correct user details which are

name: user,
email: [email protected],
profile: {
   imageUrl: myimageUrl,
   lastUpdated: mylastUpdatedTime,
},
token,

but got

rpc error: code = Unimplemented desc = RPC method not implemented /protobuf.IdentityService/CreateUser

Here are my github repos: Go grpc client & Node JS grpc server

Jorgejorgensen answered 8/5, 2019 at 6:49 Comment(0)
M
3

I had the same problem.

Here is my solution: After compiling .proto I created 2 files: client.go and server.go.

In client.go I implemented my methods (rpc in terms of protobuffers) and had a main function.

In server.go I defined a server struct server with one field: Unimplemented*ServiceName*Server. After that I also implemented the mentioned above methods, but those had a receiver type: func (s *server) Foo(ctx context.Context, *other params*)

That worked for me, hopefully it will help you!

Miniaturist answered 3/2, 2021 at 20:32 Comment(0)
I
1

The error indicates that the /protobuf.IdentityService/CreateUser method is not registered at the server side. And I didn't see any service registration code in your linked server code. Please take a look at the node.js guide here.

Insignificancy answered 8/5, 2019 at 18:24 Comment(2)
I have registered the service here in my node.js server. Also have a look at the procedures here.Jorgejorgensen
I am not very familiar with how node.js works. I would suggest you to use a command line tool (like github.com/grpc/grpc/blob/master/doc/command_line_tool.md) to check whether the service is indeed registered, because the error indicates it is not registered.Insignificancy
S
0

Using GUI of grpc try to send your protos to your both servers and check for upcoming errors/correct endpoints.

In my case java proto had a package inside which was added to the endpoint.
Had package com.example.grpc; instead of option java_package = "com.example.grpc";

Sporulate answered 20/12, 2019 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.