Reputation: 12441
I want to server-side load balance for gRPC client and server and trying to come up with simple Nginx config for the OS X. I have 2 servers running on the port 50051 and 50052 and this is I start the server:
Server server = ServerBuilder.forPort(50051)
.addService(new ImageStreamingServerImpl())
.addService(ProtoReflectionService.newInstance())
// .useTransportSecurity(
// new File("ssl/server.crt"),
// new File("ssl/server.pem")
// )
.build();
server.start();
This is my Nginx config:
worker_processes 1;
error_log /usr/local/var/log/nginx/error.log;
events {
worker_connections 10;
}
http {
access_log /usr/local/var/log/nginx/access.log;
upstream backend {
server 0.0.0.0:50051;
server 0.0.0.0:50052;
}
server {
listen 8080;
location / {
grpc_pass grpc://backend;
}
}
}
So my idea is the client can listen to the port of 8080 over the Nginx and perform the code as before. Client creation is below:
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080)
.usePlaintext()
.build();
// ManagedChannel channel = NettyChannelBuilder.forAddress("localhost", 8080)
// .sslContext(GrpcSslContexts.forClient().trustManager(new File("ssl/ca.crt")).build())
// .build();
FileServiceGrpc.FileServiceStub imageStreamingClient = FileServiceGrpc.newStub(channel);
Previously, the client and server can run decently in the same port (say, 50051 or 50052) without Nginx. Why does this not working now?
The proto file is provided below:
syntax = "proto3";
option java_multiple_files = true; package com.grpc.protobuf;
message DownloadFileRequest {
string url = 1;
}
message DataChunk {
bytes data = 1;
int32 size = 2;
}
service FileService {
rpc downloadFile (DownloadFileRequest) returns (stream DataChunk);
}
I omit the TLS encryption for the simplification purpose.
Upvotes: 4
Views: 123
Reputation: 35951
It doesn't look like you have configured Nginx to enabled HTTP2, which is the protocol used by gRPC.
Try with:
server {
listen 8080 http2;
....
}
Upvotes: 4