grpc客户端流式Java客户端获取io.grpc.StatusRuntimeException:UNAVAILABLE



我有一个grpcNodejs服务器,位于HAproxy客户端流式rpcjavamaven之后。

当我运行java客户端时,它返回一个错误:

io.grpc.StatusRuntimeException:不可用:HTTP状态代码503无效的内容类型:text/html标头:元数据(:状态=503,缓存控制=无缓存,内容类型=text.html(数据-------------------------

503服务不可用没有服务器可用于处理此请求。

我已经用Nodejs测试了rpc客户端流式传输,它成功了。

我的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
}
}

我的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();

GRPC中不同语言库的不同实现是否会出现此问题?

很明显,我为Target("example.com(进行了更改,并成功了。我不应该为它指定端口。

相关内容

  • 没有找到相关文章

最新更新