简体   繁体   English

grpc 客户端-流式 Java 客户端获取 io.grpc.StatusRuntimeException: UNAVAILABLE: HTTP 状态代码 503

[英]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.

相关问题 数据流中的错误:io.grpc.StatusRuntimeException:不可用 - Error in Dataflow: io.grpc.StatusRuntimeException: UNAVAILABLE gRpc,客户端获取 io.grpc.StatusRuntimeException: UNIMPLEMENTED: 即使消息被服务器接收并反序列化的方法 - gRpc, client getting io.grpc.StatusRuntimeException: UNIMPLEMENTED: Method even when the message is received and deserialized by the server io.grpc.StatusRuntimeException:UNIMPLEMENTED:找不到方法 - io.grpc.StatusRuntimeException: UNIMPLEMENTED: Method not found 引起:io.grpc.StatusRuntimeException:NOT_FOUND:找不到资源 - Caused by: io.grpc.StatusRuntimeException: NOT_FOUND: Resource not found Google DocumentAI Java 示例因 io.grpc.StatusRuntimeException 失败:INVALID_ARGUMENT:请求包含无效参数 - Google DocumentAI Java example fails with io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Request contains an invalid argument 通过 Java API 创建 Google Cloud Function:“io.grpc.StatusRuntimeException: INVALID_ARGUMENT” - Creating Google Cloud Function via Java API: “io.grpc.StatusRuntimeException: INVALID_ARGUMENT” io.grpc.StatusRuntimeException:未实现:未知服务 manipula.core2.core.proto.Centrifugo - io.grpc.StatusRuntimeException: UNIMPLEMENTED: unknown service manipula.core2.core.proto.Centrifugo io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED 同时从谷歌云 PubSub 获取主题(发布者)名称 - io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED while getting the topic(publisher) name from Google cloud PubSub 在 gRPC Java 应用程序中使客户端流同步/阻塞 - Make client-side streaming synchronous/blocking in gRPC Java application 如何使用 mockito 模拟 grpc ServiceBlockingStub 抛出 StatusRuntimeException(Status.UNAVAILABLE)? - How to use mockito to mock grpc ServiceBlockingStub to throw StatusRuntimeException(Status.UNAVAILABLE)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM