-
Notifications
You must be signed in to change notification settings - Fork 997
Add gRPC reverse proxy server example #5722
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
Changes from 4 commits
9f5e044
4cacfc1
774b34f
8f22629
61c3429
b4abca8
00fa962
5759a6c
7016aaa
cd3d8e0
b1efcca
ce6ab18
9424ddb
4946a11
0dd24d8
958c0f6
4ff7116
b3fd200
39322a3
70a7c66
f2569dc
e1332e6
0c8ecb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| static_resources: | ||
| listeners: | ||
| - name: listener_0 | ||
| address: | ||
| socket_address: | ||
| address: 0.0.0.0 | ||
| port_value: 9090 | ||
| filter_chains: | ||
| - filters: | ||
| - name: envoy.filters.network.http_connection_manager | ||
| typed_config: | ||
| "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager | ||
| stat_prefix: ingress_http | ||
| codec_type: AUTO | ||
| route_config: | ||
| name: local_route | ||
| virtual_hosts: | ||
| - name: local_service | ||
| domains: ["*"] | ||
| routes: | ||
| - match: | ||
| prefix: "/" | ||
| route: | ||
| cluster: grpc_service | ||
| timeout: 0s | ||
| idle_timeout: 0s | ||
| http_filters: | ||
| - name: envoy.filters.http.router | ||
| typed_config: | ||
| "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router | ||
| clusters: | ||
| - name: grpc_service | ||
| connect_timeout: 1s | ||
| type: STRICT_DNS | ||
| lb_policy: round_robin | ||
| http2_protocol_options: {} | ||
| load_assignment: | ||
| cluster_name: grpc_service | ||
| endpoints: | ||
| - lb_endpoints: | ||
| - endpoint: | ||
| address: | ||
| socket_address: | ||
| address: host.docker.internal | ||
| port_value: 18080 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package example.armeria.grpc; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.testcontainers.containers.BindMode; | ||
| import org.testcontainers.containers.GenericContainer; | ||
| import org.testcontainers.junit.jupiter.Container; | ||
|
|
||
| import com.linecorp.armeria.client.WebClient; | ||
| import com.linecorp.armeria.client.grpc.GrpcClients; | ||
| import com.linecorp.armeria.server.Server; | ||
| import com.linecorp.armeria.server.grpc.GrpcService; | ||
|
|
||
| import example.armeria.grpc.Hello.HelloReply; | ||
| import example.armeria.grpc.Hello.HelloRequest; | ||
|
|
||
| class GrpcReverseProxyServerTest { | ||
|
|
||
| private static Server server; | ||
|
|
||
| @Container | ||
| private static GenericContainer<?> envoy = new GenericContainer<>("envoyproxy/envoy:v1.22.0") | ||
| .withExposedPorts(9090) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use a random unused port to avoid port collision as much as possible. Use |
||
| .withFileSystemBind("./envoy/envoy.yaml", "/etc/envoy/envoy.yaml", BindMode.READ_WRITE); | ||
|
|
||
| @BeforeAll | ||
| static void startServer() { | ||
| server = Server.builder() | ||
| .http(18080) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use an ephemeral port to avoid port collision |
||
| .service(GrpcService.builder() | ||
| .addService(new HelloServiceImpl()) | ||
| .build()) | ||
| .build(); | ||
| server.start().join(); | ||
| envoy.start(); | ||
| } | ||
|
|
||
| @AfterAll | ||
| static void stopServer() { | ||
| server.stop().join(); | ||
| envoy.stop(); | ||
| } | ||
|
|
||
| @Test | ||
| void reverseProxy() { | ||
|
|
||
| // given | ||
| final String envoyAddress = "http://" + envoy.getHost() + ":" + envoy.getMappedPort(9090); | ||
|
|
||
| final WebClient client = WebClient.of(envoyAddress); | ||
| final HelloServiceGrpc.HelloServiceBlockingStub helloService = GrpcClients.builder(client.uri()) | ||
| .build(HelloServiceGrpc.HelloServiceBlockingStub.class); | ||
|
|
||
| // when | ||
| final HelloReply reply = helloService.hello(HelloRequest.newBuilder().setName("Armeria").build()); | ||
|
|
||
| // then | ||
| assertThat(reply.getMessage()).isEqualTo("Hello, Armeria!"); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please create a separate project for the example you're writing. Don't make an example do more than one thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, am I right to understand?
Are you telling me to create and use a grpc-reverse-proxy project in the sample directory?