[英]grpc Client-Streaming Java Client gets io.grpc.StatusRuntimeException: UNAVAILABLE: HTTP status code 503
I have a grpc Nodejs server behind a HAproxy and client-streaming rpc java maven .我在HAproxy和客户端流 rpc java maven后面有一个grpc Nodejs服务器。
When I run the java client it return an error:当我运行java 客户端时,它返回一个错误:
io.grpc.StatusRuntimeException: UNAVAILABLE: HTTP status code 503 invalid content-type: text/html headers: Metadata(:status=503,cache-control=no-cache,content-type=text/html) DATA-----------------------------
io.grpc.StatusRuntimeException: UNAVAILABLE: HTTP status code 503 invalid content-type: text/html headers: Metadata(:status=503,cache-control=no-cache,content-type=text/html) DATA---- -------------------------
503 Service Unavailable No server is available to handle this request.
503 Service Unavailable 没有可用的服务器来处理这个请求。
I already test a rpc client streaming with Nodejs and it worked.我已经用Nodejs测试了一个rpc 客户端流,它工作正常。
My java client code:我的java客户端代码:
public class App {
public static void main(String[] args) throws InterruptedException {
WebRTCStats stat = WebRTCStats.newBuilder().setUserId("abc").build();
SendWebRTCStats(stat);
}
public static void SendWebRTCStats(WebRTCStats stat) throws InterruptedException {
ManagedChannel channel = ManagedChannelBuilder.forTarget("example.com:443").useTransportSecurity()
.build();
ClientGrpc.ClientStub stub = ClientGrpc.newStub(channel);
StreamObserver<Stat.Status> responseObserver = new StreamObserver<Stat.Status>() {
@Override
public void onNext(Stat.Status status) {
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
}
@Override
public void onCompleted() {
System.out.print("complete");
}
};
StreamObserver<WebRTCStats> requestObserver = stub.sendWebRTCStats(responseObserver);
try {
// Send numPoints points randomly selected from the features list.
requestObserver.onNext(stat);
// Sleep for a bit before sending the next one.
} catch (RuntimeException e) {
// Cancel RPC
requestObserver.onError(e);
throw e;
}
// Mark the end of requests
requestObserver.onCompleted();
// Receiving happens asynchronously
}
}
My NodeJS server:我的 NodeJS 服务器:
const PROTO_PATH = './stat.proto';
const grpc = require('grpc');
const protoLoader = require('@grpc/proto-loader');
const fs = require('fs');
const tcp = require('./using.js');
let packageDefinition = protoLoader.loadSync(PROTO_PATH);
let protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
const server = new grpc.Server();
server.addService(protoDescriptor.Client.service, {
SendWebRTCStats: async (call, callback) => {
call.on('data', value => {
console.log(value);
tcp.sendLog("test", value);
});
call.on('end', () => {
callback(null, { status: 'success' });
})
},
});
let credentials = grpc.ServerCredentials.createSsl(
fs.readFileSync('ca.cer'), [{
cert_chain: fs.readFileSync('cer.crt'),
private_key: fs.readFileSync('cer_key.key')
}], false);
server.bind("0.0.0.0:443", credentials);
console.log("Server running at 443");
server.start();
Can this problem occurs by different implementations of different libraries of language in GRPC? GRPC 中不同语言库的不同实现会出现这个问题吗?
所以显然我改变了 forTarget("example.com) 并且它起作用了。我不应该为它指定端口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.