-
Notifications
You must be signed in to change notification settings - Fork 19
feature: v2 config amqp, grpc interceptors #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rustatian
wants to merge
10
commits into
master
Choose a base branch
from
feature/amqp-6.0
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e8a209d
feature: v2 config amqp
rustatian a80bed9
chore: update
rustatian 9dfe2b5
Update queues/amqp.md
rustatian 2b7597a
chore: update doc
rustatian 2869d91
chore: add what's next
rustatian addd5cb
chore: grpc interceptors docs
rustatian 12ae6b4
chore: update docs
rustatian 0ab1def
chore: update interceptors
rustatian 4a3649d
chore: update
rustatian 8a72dd3
chore: update grpc docs
rustatian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,231 @@ | ||
| # gRPC Interceptors | ||
|
|
||
| RoadRunner gRPC plugin supports custom unary interceptors. | ||
|
|
||
| Use interceptors when you want to add cross-cutting behavior around RPC calls, such as: | ||
|
|
||
| - request/response logging, | ||
| - auth checks, | ||
| - rate limiting, | ||
| - custom metrics. | ||
|
|
||
| {% hint style="info" %} | ||
| At the moment, RoadRunner supports unary gRPC interceptors (`grpc.UnaryServerInterceptor`). | ||
| {% endhint %} | ||
|
|
||
| ## Interceptor contract | ||
|
|
||
| Your plugin must implement this interface: | ||
|
|
||
| {% code title="grpc/api/interfaces.go" %} | ||
|
|
||
| ```go | ||
| type Interceptor interface { | ||
| UnaryServerInterceptor() grpc.UnaryServerInterceptor | ||
| Name() string | ||
| } | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| The `Name()` return value is used in the `grpc.interceptors` configuration list. | ||
|
|
||
| ## Configuration | ||
|
|
||
| Add interceptor names under the `grpc.interceptors` section: | ||
|
|
||
| {% code title=".rr.yaml" %} | ||
|
|
||
| ```yaml | ||
| version: "3" | ||
|
|
||
| server: | ||
| command: "php grpc-worker.php" | ||
|
|
||
| grpc: | ||
| listen: "tcp://127.0.0.1:9001" | ||
|
|
||
| proto: | ||
| - "proto/helloworld.proto" | ||
|
|
||
| interceptors: | ||
| - "sample-grpc-interceptor" | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| {% hint style="warning" %} | ||
| Make sure every name in `grpc.interceptors` matches a registered interceptor plugin name. | ||
| {% endhint %} | ||
|
|
||
| ## Execution order | ||
|
|
||
| RoadRunner applies configured interceptors in the same order as the config list. | ||
|
|
||
| Example: | ||
|
|
||
| {% code title=".rr.yaml" %} | ||
|
|
||
| ```yaml | ||
| grpc: | ||
| interceptors: ["first", "second", "third"] | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| Execution order will be: | ||
|
|
||
| `first -> second -> third -> handler` | ||
|
|
||
| ## Example plugin | ||
|
|
||
| Ready-to-use example code is available in the samples repository: | ||
|
|
||
| - [gRPC interceptor sample](https://github.com/roadrunner-server/samples/tree/master/grpc_interceptor) | ||
|
|
||
| ## Build a custom RoadRunner binary with interceptor | ||
|
|
||
| ### Build options | ||
|
|
||
| #### Build with Velox | ||
|
|
||
| Use [Velox](../customization/build.md) when you want to build RoadRunner from a `velox.toml` configuration. | ||
|
|
||
| {% code title="velox.toml" %} | ||
|
|
||
| ```toml | ||
| [roadrunner] | ||
| ref = "v2025.1.5" | ||
|
|
||
| [github] | ||
| [github.token] | ||
| token = "${RT_TOKEN}" | ||
|
|
||
| [github.plugins] | ||
| appLogger = { ref = "v5.0.2", owner = "roadrunner-server", repository = "app-logger" } | ||
| logger = { ref = "v5.0.2", owner = "roadrunner-server", repository = "logger" } | ||
| lock = { ref = "v5.0.2", owner = "roadrunner-server", repository = "lock" } | ||
| rpc = { ref = "v5.0.2", owner = "roadrunner-server", repository = "rpc" } | ||
| server = { ref = "v5.0.2", owner = "roadrunner-server", repository = "server" } | ||
| grpc = { ref = "v5.0.2", owner = "roadrunner-server", repository = "grpc" } | ||
| grpcInterceptor = { ref = "master", owner = "roadrunner-server", repository = "samples", folder = "grpc_interceptor" } | ||
|
|
||
| [log] | ||
| level = "info" | ||
| mode = "production" | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| {% code %} | ||
|
|
||
| ```bash | ||
| go install github.com/roadrunner-server/velox/v2025/cmd/vx@latest | ||
| vx build -c velox.toml -o . | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| The binary is created as `./rr`. | ||
|
|
||
| #### Build with RoadRunner | ||
|
|
||
| Use this option when you build directly from the RoadRunner repository. | ||
|
|
||
| ##### Clone RoadRunner | ||
|
|
||
| {% code %} | ||
|
|
||
| ```bash | ||
| git clone https://github.com/roadrunner-server/roadrunner.git | ||
| cd roadrunner | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| ##### Add interceptor package | ||
|
|
||
| You can either: | ||
|
|
||
| - copy sample code into your project, or | ||
| - import the sample package directly. | ||
|
|
||
| To import the sample package directly: | ||
|
|
||
| {% code %} | ||
|
|
||
| ```bash | ||
| go get github.com/roadrunner-server/samples/grpc_interceptor@latest | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| ##### Register plugin in container | ||
|
|
||
| Edit `container/plugins.go` and add your interceptor plugin to the plugin list: | ||
|
|
||
| {% code title="container/plugins.go" %} | ||
|
|
||
| ```go | ||
| import ( | ||
| grpcPlugin "github.com/roadrunner-server/grpc/v5" | ||
| grpcInterceptor "github.com/roadrunner-server/samples/grpc_interceptor" | ||
| ) | ||
|
|
||
| func Plugins() []any { | ||
| return []any{ | ||
| // ... | ||
| &grpcInterceptor.Plugin{}, | ||
| &grpcPlugin.Plugin{}, | ||
| // ... | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| ##### Build binary | ||
|
|
||
| {% code %} | ||
|
|
||
| ```bash | ||
| make build | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| The binary is created as `./rr`. | ||
|
|
||
| ### Configure interceptor in `.rr.yaml` | ||
|
|
||
| Use the plugin name returned by `Name()`: | ||
|
|
||
| {% code title=".rr.yaml" %} | ||
|
|
||
| ```yaml | ||
| grpc: | ||
| interceptors: | ||
| - "sample-grpc-interceptor" | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| ### Run and verify | ||
|
|
||
| Start RoadRunner: | ||
|
|
||
| {% code %} | ||
|
|
||
| ```bash | ||
| ./rr serve -c .rr.yaml | ||
| ``` | ||
|
|
||
| {% endcode %} | ||
|
|
||
| Send a request using your preferred gRPC client (for example, `grpc-client-cli`) and verify interceptor logs in RR output. | ||
|
|
||
| ## What's next? | ||
|
|
||
| 1. [Intro into gRPC](./grpc.md) | ||
| 2. [Writing a Middleware](../customization/middleware.md) | ||
| 3. [Building RR with a custom plugin](../customization/build.md) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.