0

我正在努力实现 gRPC 通信。有一个 maven 项目有两个模块,它们应该使用 gRPC 进行通信。

从 *.proto-files 生成的类包含SessionServiceInterface,它实际上是一个 MutinyService 接口。(以下部分实现)

运行这两个项目会导致以下错误:

Caused by: javax.enterprise.inject.spi.DeploymentException: de.ilem0n.SessionServiceInterface cannot be injected into de.ilem0n.sessions.FlinkSessionReconciler#sessionService - only Mutiny service interfaces, blocking stubs, reactive stubs based on Mutiny and io.grpc.Channel can be injected via @GrpcClient

错误本身说“只有 Mutiny 服务接口 [...] 可以通过 @GrpcClient 注入”

现在我很困惑。我在这里做错了什么还是这是一种奇怪的行为?希望你有一些想法;)

接口 session.proto:

syntax = "proto3";

option java_multiple_files = true;
option java_package = "de.ilem0n";
option java_outer_classname = "SessionProto";

package session;

service SessionServiceInterface {
  rpc getSessionInfo(SessionRequest) returns (SessionInfoReply) {}
  rpc createSession(SessionRequest) returns (SessionInfoReply) {}
}

message SessionRequest {
  string sessionId = 1;
}

message SessionInfoReply {
  bool isHealthy = 1;
  string errorMessage = 2;
  string sessionId = 3;
  string dnsName = 4;
  string ipAddress = 5;
}

会话服务.java:

@GrpcService
public class SessionService implements SessionServiceInterface {
  @Inject KubernetesClient k8s;
  @Inject SessionBootstrapper sessionBootstrapper;

  @Override
  public Uni<SessionInfoReply> getSessionInfo(SessionRequest request) {
    /* ... boring implementation detail ..*/
  }

  @Override
  public Uni<SessionInfoReply> createSession(SessionRequest request) {
    /* ... boring implementation detail ..*/
  }

服务器-'application.properties':

quarkus.http.port=8090

flink.base-image=flink:1.14.2-scala_2.11-java11

operations.namespace=ngbm-gitops
operations.flink.config-map=flink-config
operations.flink.templates-config-map=flink-templates
operations.service-account.name=ngbm-flink-operator-sa
operations.clusterrole-binding.name=ngbm-flink-operator-crb
operations.k8s.default-timeout.value=1
operations.k8s.default-timeout.unit=MINUTES
session.bootstrap.override-namespace=true
session.bootstrap.labels.controlled-by=flink-operator

会话客户端.java:

public class FlinkSessionReconciler implements Reconciler<FlinkSession> {

    @GrpcClient
    SessionServiceInterface sessionService;

    /* ... boring implementation detail ..*/
}

客户端-'application.properties':

quarkus.grpc.clients.sessionService.host=localhost
quarkus.http.port=8080

default.timeout.value=10
default.timeout.unit=SECONDS

session.bootstrap.timeout.value=10
session.bootstrap.timeout.unit=MINUTES

和 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>de.ilem0n</groupId>
    <artifactId>flink-operator</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <maven.compiler.source>16</maven.compiler.source>
        <maven.compiler.target>16</maven.compiler.target>
        <maven.compiler.release>16</maven.compiler.release>
        <compiler-plugin.version>3.8.1</compiler-plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
        <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
        <quarkus.platform.version>2.6.3.Final</quarkus.platform.version>
        <surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
    </properties>

    <modules>
        <module>resource-handler</module>
        <module>session-sidecar</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>${quarkus.platform.artifact-id}</artifactId>
                <version>${quarkus.platform.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-smallrye-health</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-smallrye-fault-tolerance</artifactId>
        </dependency>
    </dependencies>
</project>

客户端模块:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>de.ilem0n</groupId>
    <artifactId>flink-operator</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <artifactId>resource-handler</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <quarkus-sdk.version>3.0.1</quarkus-sdk.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>de.ilem0n</groupId>
      <artifactId>session-sidecar</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-arc</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-reactive</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkiverse.operatorsdk</groupId>
      <artifactId>quarkus-operator-sdk</artifactId>
      <version>${quarkus-sdk.version}</version>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-junit5</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>${quarkus.platform.group-id}</groupId>
        <artifactId>quarkus-maven-plugin</artifactId>
        <version>${quarkus.platform.version}</version>
        <extensions>true</extensions>
        <executions>
          <execution>
            <goals>
              <goal>build</goal>
              <goal>generate-code</goal>
              <goal>generate-code-tests</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${compiler-plugin.version}</version>
        <configuration>
          <source>${maven.compiler.source}</source>
          <target>${maven.compiler.target}</target>
          <compilerArgs>
            <arg>-parameters</arg>
          </compilerArgs>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${surefire-plugin.version}</version>
        <configuration>
          <systemPropertyVariables>
            <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
            <maven.home>${maven.home}</maven.home>
          </systemPropertyVariables>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>native</id>
      <activation>
        <property>
          <name>native</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${surefire-plugin.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
                <configuration>
                  <systemPropertyVariables>
                    <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
                    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                    <maven.home>${maven.home}</maven.home>
                  </systemPropertyVariables>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      <properties>
        <quarkus.package.type>native</quarkus.package.type>
      </properties>
    </profile>
  </profiles>
</project>

服务器项目:

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

    <parent>
        <groupId>de.ilem0n</groupId>
        <artifactId>flink-operator</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>session-sidecar</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>

    </properties>

    <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-arc</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-grpc</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-kubernetes-client</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>quarkus-maven-plugin</artifactId>
                <version>${quarkus.platform.version}</version>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <goals>
                            <goal>build</goal>
                            <goal>generate-code</goal>
                            <goal>generate-code-tests</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${compiler-plugin.version}</version>
                <configuration>
                    <compilerArgs>
                        <arg>-parameters</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <configuration>
                    <systemPropertyVariables>
                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        <maven.home>${maven.home}</maven.home>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jboss.jandex</groupId>
                <artifactId>jandex-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>make-index</id>
                        <goals>
                            <goal>jandex</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>native</id>
            <activation>
                <property>
                    <name>native</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>${surefire-plugin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <systemPropertyVariables>
                                        <native.image.path>
                                            ${project.build.directory}/${project.build.finalName}-runner
                                        </native.image.path>
                                        <java.util.logging.manager>org.jboss.logmanager.LogManager
                                        </java.util.logging.manager>
                                        <maven.home>${maven.home}</maven.home>
                                    </systemPropertyVariables>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <quarkus.package.type>native</quarkus.package.type>
            </properties>
        </profile>
    </profiles>
</project>
4

1 回答 1

0

Quarkus 2.8 之前,您需要将 proto 文件复制到客户端模块中。这在 2.8 中不再需要,因为您可以指出您可能在哪个依赖项中拥有 proto 文件,并且 Quarkus 将自动从这些文件生成代码。

于 2022-02-16T07:10:15.643 回答