loopback4-extension-grpc icon indicating copy to clipboard operation
loopback4-extension-grpc copied to clipboard

Not starting GRPC server

Open hsenapati opened this issue 5 years ago • 5 comments

Description/Steps to reproduce

  1. Scaffolded a LB 4 app as "loopback4-example-express-composition"
  2. $ npm install --save @loopback/grpc
  3. Modified Index.ts file with the code explained in the section "Component Configuration" of https://www.npmjs.com/package/@loopback/grpc
  4. Followed the rest of the steps as mentioned in npm module "@loopback/grpc"

Link to reproduction sandbox

Expected result

  1. Suppose to generate "greeter.proto.ts", but it never generate the .tc file for the proto file.
  2. Copied the greeter.proto.ts file from "loopback4-extension-grpc/fixtures/greeter.proto.ts" to my above application.
  3. When I run "$npm start", it does not throw any error but the command prompt returns and server is not listening to any specific port.

Additional information

  1. How can I make the client application to call this server?
  2. How can I extend this to make grpc stream calls between client and server on loopback 4.

hsenapati avatar Jun 28 '19 13:06 hsenapati

@raymondfeng , could you please take a look? Thanks.

dhmlau avatar Jun 28 '19 13:06 dhmlau

@hsenapati Can you try @loopback/[email protected]?

raymondfeng avatar Jun 28 '19 16:06 raymondfeng

@raymondfeng The path I mentioned with the issue "https://www.npmjs.com/package/@loopback/grpc" is for 0.1.1 revision, I suppose. Can you help providing sample code. Thanks

hsenapati avatar Jun 28 '19 16:06 hsenapati

I just released @loopback/[email protected] 15 mins ago. Please upgrade your app to this version and try again.

raymondfeng avatar Jun 28 '19 16:06 raymondfeng

Thanks @raymondfeng for the details.

The grpc npm package works for Hello World on linux, but following changes were done to make the Hello World work on Windows 64 bit.

  1. Changed code block for “Component.Configuration” part from “const config: Config.Component” to “const config: object”
  2. Grpc compiler for LB4 is not installed as part of grpc npm module. So manually copied compiler to “node_modules@loopback\grpc”
  3. Controller code should not refer the .proto file till the proto.ts is generated by the compiler.
  4. We had to install “npm install ts-protoc-gen@next” as opposed to “npm install ts-protoc-gen” to make the grpc compiler generate the compiled protos file.
  5. Updated the compiler command file from “protoc-gen-ts” to “protoc-gen-ts.cmd” in the “node_modules@loopback\grpc\dist\grpc.generator.js” for the compiler to work.
  6. It does not generate proto.ts file with interfaces which is required for grpc server to instantiate. But it compiles to following 3 files for a single greeter.proto file a. greeter_pb_service.d.ts b. greeter_pb_service.js c. greeter_pb.d.ts
  7. So manually had to copy the proto.ts file from the linux machine which had the required interfaces.
  8. Now, LB4 + gRPC Server started.
  9. Now for client, used NodeJS grpc client (non-LB4 client) as her "https://grpc.io/docs/quickstart/node/" to send a simple message to server. This worked.

Following are the open challenges

  1. Can you update the grpc npm module of LB4 to make the above fixes for windows 64 bit.
  2. No sample code available to work for grpc client, streaming call (bidirectional) and authentication etc. So can you provide or point up code references for us to try out.

hsenapati avatar Jul 02 '19 07:07 hsenapati