2

我有一个提供 GRPC 的 Java 后端,在没有 Envoy 的情况下使用它时效果很好,但是对于 GRPC-web,它给了我 503 响应。我已经尝试了几天,但没有任何成功。

这是我的 envoy.yaml:

admin:
  access_log_path: /tmp/admin_access.log
  address:
    socket_address: { address: 0.0.0.0, port_value: 9901 }

static_resources:
  listeners:
    - name: listener_0
      address:
        socket_address: { address: 0.0.0.0, port_value: 8081 }
      filter_chains:
        - filters:
            - name: envoy.filters.network.http_connection_manager
              typed_config:
                "@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
                codec_type: auto
                stat_prefix: ingress_http
                route_config:
                  name: local_route
                  virtual_hosts:
                    - name: local_service
                      domains: ["*"]
                      routes:
                        - match: { prefix: "/" }
                          route:
                            cluster: greeter_service
                            max_grpc_timeout: 50s
                      cors:
                        allow_origin_string_match:
                          - prefix: "*"
                        allow_methods: GET, PUT, DELETE, POST, OPTIONS
                        allow_headers: keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout
                        max_age: "1728000"
                        expose_headers: custom-header-1,grpc-status,grpc-message
                http_filters:
                  - name: envoy.filters.http.grpc_web
                  - name: envoy.filters.http.cors
                  - name: envoy.filters.http.router
  clusters:
    - name: greeter_service
      connect_timeout: 50.25s
      type: logical_dns
      http2_protocol_options: {}
      lb_policy: round_robin
      # win/mac hosts: Use address: host.docker.internal instead of address: localhost in the line below
      load_assignment:
        cluster_name: cluster_0
        endpoints:
          - lb_endpoints:
              - endpoint:
                  address:
                    socket_address:
                      address: 0.0.0.0
                      port_value: 6565

以下是我的 ReactJS 代码:

componentDidMount() {
    this.setState({ name: "mounted" });

    var xtcoinsClient = new XTCoinsClient('http://127.0.0.1:8081');


    var request = new GetProfileRequest();
    request.setUserid("5fc951e5e44055118cf193c5");
    xtcoinsClient.getProfile(request, {}, function (err, response) {
        console.log(response.getMessage());
    });


}

这导致以下结果:

ReactJS 通信

这是我尝试使用 GRPCUI 的时候:

在此处输入图像描述

这是使用卷曲:

Lemmers-MBP:~ lemmer$ curl -v http://localhost:8081/com.lemmer.grpc.xtcoins.XTCoins/getProfile
*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 8081 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8081 (#0)
> GET /com.lemmer.grpc.xtcoins.XTCoins/getProfile HTTP/1.1
> Host: localhost:8081
> User-Agent: curl/7.64.1
> Accept: */*
> 
< HTTP/1.1 503 Service Unavailable
< content-length: 19
< content-type: text/plain
< date: Sun, 06 Dec 2020 10:56:52 GMT
< server: envoy
< 
* Connection #0 to host localhost left intact
no healthy upstream* Closing connection 0

我很感激任何帮助。

4

0 回答 0