Skip to main content
Version: 3.2

gRPC gRPC Integration Guide

Call the methods of your own services, MES and cloud APIs that speak gRPC, and start pipelines from their streams, with requests and answers as JSON.

Authentication
None · Basic · Bearer · API key · OAuth2 token · mutual TLS
Operations
Call Read Method · Call Write Method · Subscribe
Transport
gRPC over HTTP/2, plain or TLS

Overview​

The gRPC connector is a client: MaestroHub connects to a gRPC server and calls its methods, as the REST connector calls an HTTP API. It works with any service, without generated code.

  • Call Read Method: call a method that only reads, such as a line's status.
  • Call Write Method: call a method that changes data, such as reporting a quantity or sending a command.
  • Subscribe: keep a server-streaming method open and start a pipeline for every message it sends.

All four kinds of gRPC method are supported: unary, server streaming, client streaming and bidirectional streaming.

Why two call functions? gRPC does not say whether a method changes data. You say it by choosing the function, and permissions, retries and store-and-forward follow that choice: a failed read is retried as the node's settings ask, and a write whose outcome is unknown is never sent again automatically.

Prerequisites​

  • The server's host and port, reachable from MaestroHub.
  • The service's contract, one of:
    • server reflection switched on at the server, so MaestroHub can ask it for its definitions;
    • its .proto files;
    • a compiled descriptor set.
  • Credentials, and the CA certificate if the server's certificate comes from your own CA.

Connection Configuration​

Navigate to Connections → New Connection → gRPC.

gRPC connection formgRPC connection form

The Connection tab: the server, metadata and message settings

Connection​

FieldDefaultDescription
Profile Name-A descriptive name for this connection (required, at most 100 characters)
Description-Optional
Host-Host name or IP address of the gRPC server (required)
Port50051The server's port. One behind a TLS load balancer is usually on 443
Metadata-Key and value pairs sent with every call, e.g. a tenant the service asks for. Keys are lower case; a key ending in -bin takes a base64 value
Max Message Size (bytes)4194304The largest single message accepted from the server (4 MiB, gRPC's own default)
Compressionnonegzip compresses request messages
Keep-Alive Interval0sSend an HTTP/2 ping when the connection has been idle this long, so a firewall does not drop it silently. 0s sends none; otherwise at least 10s
Send Idempotency KeyOnA store-and-forward write carries its write key as the idempotency-key metadata entry. Turn it off for a server that refuses metadata it does not know

Contract​

gRPC contract settingsgRPC contract settings

The Contract tab: where the service definitions come from

FieldDefaultDescription
Contract Sourcereflectionreflection asks the server for its definitions; files compiles the .proto files you upload; descriptor reads a compiled descriptor set
.proto Files-With files: the service's .proto files. Files that import each other are matched by path, or by file name when uploaded without their folders. google/protobuf imports need no upload
Descriptor Set-With descriptor: the file written by protoc --include_imports --descriptor_set_out=contract.binpb or buf build -o contract.binpb
Contract Cache Duration1hWith reflection: how long the definitions are reused before the server is asked again
Field NamesjsonHow answers spell field names: json is the Protobuf JSON name (lineId), proto the name as the contract writes it (line_id). Requests accept both
Health Service-The service name the health check asks about. Leave empty to ask about the server as a whole

Uploaded files are compiled when you save. A file that does not compile is refused with its name and line.

Many production servers have reflection switched off. Connecting to one with reflection fails with a message saying so: switch Contract Source to files and upload its .proto files.

Authentication​

Credentials are sent as gRPC metadata with every call.

TypeFieldsWhat is sent
None-Nothing
BasicUsername, Passwordauthorization: Basic ...
BearerBearer Tokenauthorization: Bearer <token>
API keyAPI Key Header, API KeyThe key under the metadata key you name, e.g. x-api-key
OAuth2 tokenToken URL, Token Request Body and its optionsA token fetched from the token endpoint, reused for the Token Cache Duration, and fetched again when the server refuses it

Credentials sent without TLS travel in clear text.

TLS​

FieldDefaultDescription
Use TLSOffEncrypt the connection. Off sends plain HTTP/2, for a server inside a trusted network
CA Certificate (PEM)-A CA that signed the server's certificate. Leave empty to trust the system's CAs
Client Certificate (PEM), Client Private Key (PEM)-For mutual TLS
Server Name-The name the server's certificate is checked against, when it differs from Host
Skip Certificate VerificationOffAccept any server certificate. Insecure: for tests only

Health check​

MaestroHub asks the standard gRPC health service (grpc.health.v1.Health). A server that answers SERVING is healthy; one that answers NOT_SERVING is not. A server without the health service is healthy when it answers at all.

Function Builder​

After saving the connection, open its Functions tab → New Function and choose Call Read Method, Call Write Method or Subscribe.

gRPC function typesgRPC function types

Call Read Method reads, Call Write Method writes, Subscribe feeds a trigger

Call Read Method and Call Write Method​

FieldRequiredDescription
MethodYesThe method to call, as package.Service/Method, picked from the connection's contract. Called as written: it cannot hold ((parameters))
RequestCall Write MethodThe request message as JSON, e.g. {"lineId": "((lineId))"}. Supports ((parameters)). A method that takes a stream takes a JSON list of messages, at most 10000
MetadataNoA JSON object of metadata sent with this call, beside the connection's
Max ResponsesNoThe most messages collected from a method that answers with a stream, 1000 by default and at most 10000. The call is cancelled at that number
TimeoutNoBound on this operation, 30s by default

Picking a method fills Request with a template of its message: every field with a placeholder value.

gRPC function parametersgRPC function parameters

A Call Read Method function whose request carries the ((lineId)) parameter

Each function checks the call before anything is sent: the method must be in the contract, and a request field its message does not define is refused by name.

How JSON maps to a message​

Requests and answers follow the standard Protobuf JSON mapping.

In the contractIn JSON
A 64-bit integerText, such as "18250", because a JSON number loses precision above 253. A request may give text or a number
An enumIts name, such as "RUNNING". A request may give the name or the number
A Timestamp, a DurationRFC 3339 text; seconds text such as "3.5s"
BytesBase64 text
A field left at its defaultWritten out (0, "", false), so a pipeline sees the same keys on every message. An unset sub-message is null; an unset optional field is left out

The four kinds of method​

Method kindWhat the function does
One request, one answerSends the request and returns the answer in result.response
One request, a stream of answersCollects the answers in result.responses until the server ends the stream or Max Responses is reached; result.complete says which
A stream of requests, one answerSends the list of messages on one call and returns the answer
A stream of requests and a stream of answersSends the list of messages and collects the answers, reading while it sends

A conversation that stays open across several pipeline runs is not supported.

A write is not repeated safely

gRPC defines no idempotency key: a method called twice may act twice. The connector sends a write once. A write whose answer was lost (a timeout, a dropped connection) may already have run on the server: check the server before running it again. With store-and-forward on, a buffered write is sent when the link returns and carries the idempotency-key metadata entry, for a service that honours it.

Subscribe​

FieldRequiredDescription
MethodYesA server-streaming method, as package.Service/Method
RequestNoThe one request message the stream is opened with, as JSON. Sent as written: it cannot hold ((parameters))
MetadataNoA JSON object of metadata sent when the stream is opened

A Subscribe function is the source of the gRPC trigger. gRPC has no replay: messages the server sent while the connection was down are not delivered afterwards.

Pipeline Integration​

Each call operation is its own node in the Pipeline Designer, under APIs: gRPC Call Read Method and gRPC Call Write Method. The gRPC nodes page lists what they return, and the gRPC trigger page what a stream message carries.

gRPC Call Read Method nodegRPC Call Read Method node

The gRPC Call Read Method node with its connection and function

Common Use Cases​

Read a line's status from a service​

gRPC Call Read Method with method plant.v1.LineService/GetLineStatus and request {"lineId": "((lineId))"}, then a condition on $node["Status"].result.response.state.

Report production when a batch ends​

  1. A trigger fires when the batch counter resets.
  2. gRPC Call Write Method with the MES's report method and request {"workOrderId": "((workOrderId))", "quantity": ((count))}.

Start a pipeline on every status change​

A Subscribe function on plant.v1.LineService/WatchLine with request {"lineId": "L3"}, and a gRPC trigger on it.

Troubleshooting​

What you seeCause and fix
"this server does not offer server reflection"Reflection is switched off at the server. Set Contract Source to files and upload its .proto files, or to descriptor
"the server did not complete the HTTP/2 handshake"Use TLS does not match the server, or the port is not a gRPC port
"the server answered HTTP 404, not gRPC"A web server or a proxy answered on that address. Check the host and port
A certificate error at connectThe server's certificate is not signed by a CA MaestroHub trusts: add the CA certificate, or set Server Name when the certificate names another host
UNAUTHENTICATED at connectThe server refuses the credentials
"method ... is not in this connection's contract"The contract does not define the method. With reflection, the server is asked once more before this is said; with uploaded files, upload the current ones
"the request does not fit ...: unknown field"The request names a field the message does not define. Compare it with the template the form fills in
RESOURCE_EXHAUSTED on a large answerA message is larger than Max Message Size. Raise it on the connection
result.complete is falseMax Responses stopped the read. Raise it, or narrow the request