Skip to content

Forwarding and Recording gRPC Traffic

Rodrigo edited this page Mar 6, 2021 · 3 revisions

The generated mock server is capable of forwarding an incoming request to another gRPC server and store the response before returning it to the caller. The recorded responses can be obtained by the /recordings endpoint in the REST server.

Usage

Creating a Forward Stub

To activate forwarding you must create a stub that contains a forward instead of the response. Using the provided Greeter service as an example, the stub would be created like this:

POST 127.0.0.1:1068/stubs

{
    "fullMethod": "/carvalhorr.greeter.Greeter/SayHello",
    "request": {
        "match": "exact",
        "content": {
            "name": "John"
        }
    },
    "forward": {
        "serverAddress": "yourserver:port",
        "record": true
    }
}

You can control if the communication will be recorded through the record field. You must provide the remote server address in the field serverAddress in the format HOST:PORT.

When the mock server receives a request that matches the stub's request, it forwards the call to the external server, records the request/response (if recording is enabled), and returns the response to the original caller.

Obtaining all recordings

To obtain the recorded stubs, make a GET call to the /recordings endpoint.

Limitations

  • Only insecure requests are supported.
  • Error responses are not recorded at this moment.
  • No support through the generated client