-
Notifications
You must be signed in to change notification settings - Fork 914
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
Add gRPC reverse proxy server example #5722
Merged
Merged
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
9f5e044
Add gRPC reverse proxy server example
eottabom 4cacfc1
Add gRPC reverse proxy server example
eottabom 774b34f
Add gRPC reverse proxy server example
eottabom 8f22629
Add gRPC reverse proxy server example
eottabom 61c3429
ISSUE-2353: Add reverse proxy example
eottabom b4abca8
ISSUE-2353: Add reverse proxy example
eottabom 00fa962
ISSUE-2353: Add reverse proxy example
eottabom 5759a6c
ISSUE-2353: Add reverse proxy example
eottabom 7016aaa
ISSUE-2353: Add reverse proxy example
eottabom cd3d8e0
ISSUE-2353: Add reverse proxy example
eottabom b1efcca
ISSUE-2353: Add reverse proxy example
eottabom ce6ab18
ISSUE-2353: Add reverse proxy example
eottabom 9424ddb
ISSUE-2353: Add reverse proxy example
eottabom 4946a11
ISSUE-2353: Add reverse proxy example
eottabom 0dd24d8
minor updates
jrhee17 958c0f6
test for multiple protocols
jrhee17 4ff7116
remove unnecessary dependencies
jrhee17 b3fd200
handle flakiness
jrhee17 39322a3
retry for http status unavailable
jrhee17 70a7c66
use testcontainers host, open the host port preemptively
jrhee17 f2569dc
ISSUE-2353: Add reverse proxy example
eottabom e1332e6
ISSUE-2353: Add reverse proxy example
eottabom 0c8ecb4
ISSUE-2353: Add reverse proxy example
eottabom 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 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 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,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: 8080 |
63 changes: 63 additions & 0 deletions
63
examples/grpc/src/test/java/example/armeria/grpc/GrpcReverseProxyServerTest.java
This file contains 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,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) | ||
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(8080) | ||
trustin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.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!"); | ||
} | ||
} |
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.
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?