cybros labs

Create a gRPC Client

4 min

The openHES application provides a public connectRPC interface that is fully compatible with gRPC for efficient and scalable communication.

To integrate openHES into your system or automate data readings, you can build your own gRPC client to communicate with openHES.

  • The following example describes client generation using the Go programming language on macOS. Tool installation is done via Homebrew.
  • For different languages or operating systems, see the Buf documentation.

Tools Used


Generate Clients

To generate a client, follwo these steps:

  1. Install the necessary prerequisites.

    brew install grpcurl
    brew install bufbuild/buf/buf
    
    go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
    go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
    
    export PATH="$PATH:$(go env GOPATH)/bin"
    
    brew install protobuf
    
  2. Download the proto files.
    Replace <host:port> with the address of the openHES server.

    grpcurl -proto-out-dir=protos <host:port> list
    
  3. Generate client files from the protos directory.

    cd protos
    
    echo "version: v2
    plugins:
    - local: protoc-gen-go-grpc
        out: ../gen/go
        opt: paths=source_relative
    - protoc_builtin: go
        out: ../gen/go
        opt:
        - paths=source_relative
        - default_api_level=API_OPAQUE
    - protoc_builtin: python
        out: ../gen/python/platform_api
    - remote: buf.build/grpc/python
        out: ../gen/python/platform_api" >buf.gen.yaml
    
    buf generate
    
  • All client files will be generated and placed in the path ../gen/.

Example YAML File

You can generate clients for multiple programming languages using a single yaml configuration file.

The following example describes client generation using the Go and Python programming languages.

version: v2
plugins:
  - local: protoc-gen-go-grpc
    out: ../gen/go
    opt: paths=source_relative
  - protoc_builtin: go
    out: ../gen/go
    opt:
      - paths=source_relative
      - default_api_level=API_OPAQUE
  - protoc_builtin: python
    out: ../gen/python/platform_api
  - remote: buf.build/grpc/python
    out: ../gen/python/platform_api

For each client defined in the yaml file, ensure that the specified plugin or plugins can generate both data types and API methods.

For a complete description of the yaml file, see the Buf documentation.


Back to articles