grpc java spring服务器“错误”:“2未知:流已删除”

wqlqzqxt  于 2021-07-16  发布在  Java
关注(0)|答案(1)|浏览(475)

我创建了一个简单的测试grpc服务器(java,spring)来测试这项技术。
当试图从服务器调用函数时,我得到一个错误{“error”:“2 unknown:stream removed”}
blumrpc错误图像
在应用程序内部,没有打印堆栈跟踪,我无法使用断点对我不可见的代码捕获程序执行

syntax = "proto3";

package com.example.grpc;

message LoginRequest{
  string login =1;
  string password =2;
}
message LoginResponse{
  string token = 1;
}

service LoginService{
  rpc login(LoginRequest) returns (LoginResponse);
}

这是我的原始文件
我的pom xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.exampledriven</groupId>
    <artifactId>spring-boot-grpc-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>spring-boot-grpc-server</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-stub</artifactId>
            <version>1.0.1</version>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-protobuf</artifactId>
            <version>1.0.1</version>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-netty</artifactId>
            <version>1.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.lognet</groupId>
            <artifactId>grpc-spring-boot-starter</artifactId>
            <version>0.0.6</version>
            <exclusions>
                <exclusion>
                    <groupId>io.grpc</groupId>
                    <artifactId>grpc-netty</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <!--Details here : https://github.com/grpc/grpc-java-->

    <build>
        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.4.1.Final</version>

            </extension>
        </extensions>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.xolstice.maven.plugins</groupId>
                <artifactId>protobuf-maven-plugin</artifactId>
                <version>0.5.0</version>
                <configuration>
                    <!--
                      The version of protoc must match protobuf-java. If you don't depend on
                      protobuf-java directly, you will be transitively depending on the
                      protobuf-java version that grpc depends on.
                    -->
                    <protocArtifact>com.google.protobuf:protoc:3.0.2:exe:${os.detected.classifier}</protocArtifact>
                    <pluginId>grpc-java</pluginId>
                    <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1:exe:${os.detected.classifier}</pluginArtifact>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>compile-custom</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>bintray-lognet-maven</id>
            <name>bintray</name>
            <url>http://dl.bintray.com/lognet/maven</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>bintray-lognet-maven</id>
            <name>bintray-plugins</name>
            <url>http://dl.bintray.com/lognet/maven</url>
        </pluginRepository>
    </pluginRepositories>

</project>

我的grpc服务

@GRpcService
public class LoginServiceImpl extends LoginServiceGrpc.LoginServiceImplBase {
    @Override
    public void login(com.example.grpc.LoginServiceOuterClass.LoginRequest loginRequest,
                      StreamObserver<LoginServiceOuterClass.LoginResponse> responseObserver){
        com.example.grpc.LoginServiceOuterClass.LoginResponse response = com.example.grpc.LoginServiceOuterClass.LoginResponse
                .newBuilder().setToken(UUID.randomUUID().toString()).build();
        responseObserver.onNext(response);
    }
}

已成功生成所有grpc类
项目结构
什么会导致问题?请帮忙
链接到github上的项目以进行更好的分析:https://github.com/aretomko/smartnews-project/tree/main/smartnewssever
事先谢谢你的帮助

wecizke3

wecizke31#

我不能解释问题的真正根源,但是帮助我的是为服务器和grpc提供了不同的端口,希望它能帮助一些人


## Server Properties

server:
  port: 6789
  compression.enabled: true
  max-http-header-size: 20000

grpc:
  port: 6790

相关问题