gRPC

Know the component and how to use it.

Micaella Mazoni avatar
Written by Micaella Mazoni
Updated over a week ago

IMPORTANT: This documentation has been discontinued. Read the updated gRPC documentation on our new documentation portal.

The gRPC component enables calls to gRPC service of the unary and client stream type via payload or via file.

Take a look at the configuration parameters of the component:

  • Method Type: type of method to be used in the service invocation. The supported method types are Unary, Client Stream - via Payload and Client Stream - via File. This parameter doesn’t support Double Braces.

  • URL: call address of the gRPC service. Eg: localhost:50051. This parameter doesn’t support Double Braces.

  • Headers: configures all the types of necessary headers for the call (eg.: Authorization: Bearer Co4ECg1FeGFtcGxlLnByb3RvIjwKDEh).

  • Service name: name of the service described inside the configuration file .proto of the gRPC server. This parameter doesn’t support Double Braces. In the example below, Service Name will be “Greeter”:

service Greeter {
rpc helloMethod(Hellorequest) returns (HelloResponse);

}
  • Method Name: name of the method to be described inside the configuration file .proto of the gRPC server. This parameter doesn’t support Double Braces. In the example below, Method Name wil be “helloMethod”:

service Greeter {
rpc helloMethod(Hellorequest) returns (HelloResponse);

}
  • Proto Descriptor File: base64 of the “Descriptor” file from the .proto file. Firstly, “Descriptor” must be generated from a .proto file. To make it, just run the following command in the current directory that is being located in the .proto file:

1. Generate the descriptor file

.proto file of the directory: Example.proto

Name of the descriptor file to be generated: proto.desc

protoc --include_imports --descriptor_set_out=proto.desc Example.proto

Download of the protoc compilator: https://grpc.io/docs/protoc-installation/

2. Encode this file to base64:

tLmRpZ2liZWUuZ3JwY0IMRGlnaWJlZVByb3RvUAGiAgNITFdiBnByb3RvMw==

3. Informar esse base64 na propriedade “Proto Descriptor File”

This parameter doesn’t support Double Braces.

  • Payload: the request payload to be sent to the gRPC server. For the Unary method type, a simple object that has the fields defined in the .proto file must be used. For the Client Stream - via Payload type method an object array, in which each array item is a message to be sent to the gRPC server must be used. This parameter accepts Double Braces.

  • File Name: name of the file to be used to send the payload in the Client Stream - via File mode. This file must be a JSON file that has an array and, inside this array, there must be messages to be sent to the gRPC server in an asynchronous way (stream).

  • JSON Path: JSON Path expression to determine how JSON file stream reading will be made. Exclusive for the Client Stream - via File method type.

  • Connection Timeout: expiration time of the connection with the server (in milliseconds).

  • Request Timeout: expiration time of the component request call with the gRPC server (in milliseconds).

  • Fail On Error: if the option is enabled, the execution of the pipeline with error will be interrupted; otherwise, the pipeline execution proceeds, but the result will show a false value for the “success” property.

IMPORTANT: some of the parameters above support Double Braces. To understand how this language works, read our article by clicking here.

Messages flow

Input

An input payload to be used inside the component payload parameter is expected.

Output

When executing a SFTP component using the download, upload or move operations, the following JSON structure will be generated:

{
"response": {},
"success": "true"
}
  • response: response JSON received from the gRPC service

  • success: "true" if there’s a connection and the script is execution even without returning errors in stderr

Output with error

{
"success": false,
"message": "Something went wrong while trying to call the gRPC server",
"error": "java.net.SocketTimeoutException: connect timed out"
}
  • success: “false” when the operation fails

  • message: message about the error

  • exception: information about the type of occured error

To better understand the messages flow in the Platform, click here and read our article.

gRPC component in Action

Unary

Given the .proto file example:

Example.proto

syntax = "proto3";
package digibee;

service Greeter {
rpc unary (HelloRequest) returns (HelloReply) {}
rpc clientStream (stream HelloRequest) returns (HelloReply) {}
rpc serverStream (HelloRequest) returns (stream HelloReply) {}
rpc Bidi(stream HelloRequest) returns (stream HelloReply);
}

message HelloRequest {
string name = 1;
string address = 2;
}

message HelloReply {
string message = 1;
int32 status = 2;
}

Firstly, it’s necessary to generate the “descriptor” file:

1. Inside the file directory, execute the command:

protoc --include_imports --descriptor_set_out=proto.desc Example.proto

2. With the “descriptor” at hand, generate the base64 of the proto.desc file and add it in the Proto Descriptor File field.

Component configurations:

Method Type: Unary

URL: localhost:50051

Service Name: Greeter

Method Name: unary

Proto Descriptor File: <BASE64 OF THE DESCRIPTOR FILE GENERATE ABOVE>

Payload:

{
"name": "Charles",
"address": "390 Fifth Avenue"
}

Connect Timeout: 30000

Request Timeout: 30000

Fail On Error: disabled

Response

{
"message": "Hi Charles",
"status": 200
}

Client Stream - via Payload

Given the .proto file:

Example.proto

syntax = "proto3";
package digibee;

service Greeter {
rpc unary (HelloRequest) returns (HelloReply) {}
rpc clientStream (stream HelloRequest) returns (HelloReply) {}
rpc serverStream (HelloRequest) returns (stream HelloReply) {}
rpc Bidi(stream HelloRequest) returns (stream HelloReply);
}

message HelloRequest {
string name = 1;
string address = 2;
}

message HelloReply {
string message = 1;
int32 status = 2;
}

Firstly, it’s necessary to generate the “descriptor” file:

1. Inside the file directory, execute the command:

protoc --include_imports --descriptor_set_out=proto.desc Example.proto

2. With the “descriptor” at hand, generate the base64 of the proto.desc file and add it in the Proto Descriptor File field.

Component configurations:

Method Type: Client Stream - via Payload

URL: localhost:50051

Service Name: Greeter

Method Name: clientStream

Proto Descriptor File: <BASE64 OF THE DESCRIPTOR FILE GENERATED ABOVE>

Payload:

[
{
"name": "Charles",
"address": "390 Fifth Avenue"
},
{
"name": "Paul",
"address": "32 Seventh Avenue"
},

{
"name": "Yan",
"address": "12 Fourth Avenue"
}


]

Connect Timeout: 30000

Request Timeout: 30000

Fail On Error: disabled

Response

{
"message": "Hi Charles, Paul and Yan",
"status": 200
}

Client Stream - via File

Given the following .proto file:

Example.proto

syntax = "proto3";
package digibee;

service Greeter {
rpc unary (HelloRequest) returns (HelloReply) {}
rpc clientStream (stream HelloRequest) returns (HelloReply) {}
rpc serverStream (HelloRequest) returns (stream HelloReply) {}
rpc Bidi(stream HelloRequest) returns (stream HelloReply);
}

message HelloRequest {
string name = 1;
string address = 2;
}

message HelloReply {
string message = 1;
int32 status = 2;
}

Firstly, it’s necessary to generate the “descriptor” file:

1. Inside the file directory, execute the command:

protoc --include_imports --descriptor_set_out=proto.desc Example.proto

2. With the “descriptor” at hand, generate the base64 of the proto.desc file and add it in the Proto Descriptor File field.

Component configurations:

Method Type: Client Stream - via Payload

URL: localhost:50051

Service Name: Greeter

Method Name: clientStream

Proto Descriptor File: <BASE64 OF THE DESCRIPTOR FILE GENERATED ABOVE>

File Name: file.json

file.json:
{ "infos": [
{
"name": "Charles",
"address": "390 Fifth Avenue"
},
{
"name": "Paul",
"address": "32 Seventh Avenue"
},

{
"name": "Yan",
"address": "12 Fourth Avenue"
}


]
}

JSON Path: $.infos[*]

Connect Timeout: 30000

Request Timeout: 30000

Fail On Error: disabled

Response

{
"message": "Hi Charles, Paul and Yan",
"status": 200
}
Did this answer your question?