java - 使用依赖注入(inject)从另一个 GrpcService 调用一个 GrpcService

标签 java spring spring-boot grpc grpc-java

我在使用 Spring Boot 构建的同一个项目中有两个 grpc 服务。我尝试使用 Autowiring 在 X 服务中调用 Y 服务,但我无法将所需的 StreamObserver 传递给 Y 服务方法。

下面是代码。

XService.java

@GrpcService
public class XService extends XServiceImplBase {

@Autowired
YService yService;

@Override
public void getInfo(RequestId request, StreamObserver<Info> responseObserver) {

    // Not abe to pass the second argument here
    yService.getData(request, <observer>);

 }
}

YService.java

@GrpcService
public class YService extends YServiceImplBase {

 @Override
 public void getData(RequestId request, StreamObserver<Data> responseObserver) {
    // Code Logic
 }
}

提前致谢!

最佳答案

在application.properties中创建一个与服务器同名的客户端,并使用stub进行调用。为我工作

关于java - 使用依赖注入(inject)从另一个 GrpcService 调用一个 GrpcService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60979561/

相关文章:

java - 将XML解析为包含List属性的java对象

java - 如何使用 -Xlint :unchecked? 进行编译

spring - 如何防止更新时的 Spring 验证

java - 一个 Java 项目中的队列和主题

java - Spring 启动: Load property file in constructor and use as autowire annotation

java - 在此 Spring MVC 展示示例中如何使用 @RequestAttribute 和 @ModelAttribute 注释?

java - 更改(重命名)jung 中的顶点标签

spring - 将 @ConfigurationProperties 与构建器一起使用的最佳方法是什么?

java - Spring Boot GET 请求 API

java - 在 Spring Boot 中流式传输/下载文件而不保留在内存中