github.com/craicoverflow/tyk@v2.9.6-rc3+incompatible/coprocess/grpc/README.md (about)

     1  # Coprocess (gRPC)
     2  
     3  This feature makes it possible to write Tyk middleware using a [gRPC](http://www.grpc.io/) backend. gRPC is a very interesting framework that has official support for many languages: C++, Java, Python, Go, Ruby, C#, Node.JS, Java, Objective C & PHP.
     4  
     5  The Tyk Coprocess feature uses Protocol Buffers for dispatching messages (mostly requests and events), this makes it easier to connect Tyk to a gRPC server (which is based on Protocol Buffers too), it works by specifying a [gRPC service definition](../proto/coprocess_object.proto) that covers the dispatcher logic:
     6  
     7  ```
     8  service Dispatcher {
     9    rpc Dispatch (Object) returns (Object) {}
    10    rpc DispatchEvent (Event) returns (EventReply) {}
    11  }
    12  ```
    13  
    14  ## gRPC backend
    15  
    16  A very simple use case is as follows: you write a gRPC server in a language of your choice, using the Tyk's Protocol Buffer definitions.
    17  
    18  When Tyk starts it performs a connection to your gRPC server (this is specified as a global setting in `tyk.conf`, you could use a UNIX socket -local- or even a TCP connection -over the network-).
    19  
    20  When Tyk receives a request, it performs a call to your gRPC server, which is responsible for doing the actual tasks (middleware tasks like transformations or even authentication)
    21  
    22  ## Global settings
    23  
    24  This is a section of `tyk.conf` that will:
    25  
    26  * Enable the Coprocess feature.
    27  * Indicate your gRPC server address.
    28  
    29  ```json
    30  "coprocess_options": {
    31    "enable_coprocess": true,
    32    "coprocess_grpc_server": "tcp://127.0.0.1:5555"
    33  },
    34  "enable_bundle_downloader": true,
    35  "bundle_base_url": "http://my-bundle-server.com/bundles/",
    36  "public_key_path": "/path/to/my/pubkey",
    37  ```
    38  
    39  
    40  * `enable_coprocess`: Enables the rich plugins feature.
    41  * `coprocess_grpc_server`: Sets the gRPC server host address. This is only required for gRPC plugins.
    42  * `enable_bundle_downloader`: Enables the bundle downloader.
    43  * `bundle_base_url`: A base URL that will be used to download the bundle, in this example we have "test-bundle" specified in the API settings, Tyk will fetch the following URL: "http://my-bundle-server.com/bundles/test-bundle".
    44  * `public_key_path`: Sets a public key, this is used for verifying signed bundles, you may omit this if unsigned bundles are used.
    45  
    46  ## API settings
    47  
    48  This is a sample configuration that will authenticate your API through a Coprocess (gRPC in this case, see `driver`), and a hook a "pre" middleware.
    49  
    50  ```json
    51  "enable_coprocess_auth": true,
    52  "custom_middleware": {
    53    "pre": [
    54      {
    55        "name": "MyPreMiddleware",
    56        "require_session": false
    57      }
    58    ],
    59    "auth_check": {
    60      "name": "MyAuthCheck"
    61    },
    62    "driver": "grpc"
    63  },
    64  ```
    65  
    66  ## Examples (Ruby)
    67  
    68  You may find a Ruby sample [here](ruby/sample_server.rb).