NutzCN Logo
问答 grpc 客户端调用问题
发布于 2523天前 作者 苍蓝猛兽 6900 次浏览 复制 上一个帖子 下一个帖子
标签:

grpc 客户端调用问题

现象

  1. 已发现服务
  2. 用stub调用服务失败

    客户端代码

package com.elvish.springcloud.service;

import org.springframework.stereotype.Component;

import io.grpc.Channel;
import net.devh.springboot.autoconfigure.grpc.client.GrpcClient;
import yjmyzz.grpc.study.dto.PersonList;
import yjmyzz.grpc.study.dto.QueryParameter;
import yjmyzz.grpc.study.service.DemoServiceGrpc;

@Component
public class TestGrpcService {

	@GrpcClient("PROVIDER-USER")
	private Channel serverChannel;

	public PersonList getPersonList() {
		DemoServiceGrpc.DemoServiceBlockingStub blockingStub = DemoServiceGrpc.newBlockingStub(serverChannel);
		QueryParameter queryParameter = yjmyzz.grpc.study.dto.QueryParameter.newBuilder().setAgeStart(5).setAgeEnd(10)
				.build();
		return blockingStub.getPersonList(queryParameter);
	}

}

日志

2018-01-29 10:01:33.707  INFO 12620 --- [ault-executor-0] n.d.s.a.g.c.DiscoveryClientNameResolver  : Found grpc server PROVIDER-USER DESKTOP-ENB3GMH:7052
Exception in thread "grpc-default-executor-1" java.lang.InstantiationError: io.netty.util.internal.PriorityQueue
	at io.netty.handler.codec.http2.WeightedFairQueueByteDistributor$State.<init>(WeightedFairQueueByteDistributor.java:243)
	at io.netty.handler.codec.http2.WeightedFairQueueByteDistributor.<init>(WeightedFairQueueByteDistributor.java:58)
	at io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController.<init>(DefaultHttp2RemoteFlowController.java:65)
	at io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController.<init>(DefaultHttp2RemoteFlowController.java:56)
	at io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder.<init>(DefaultHttp2ConnectionEncoder.java:52)
	at io.grpc.netty.NettyClientHandler.newHandler(NettyClientHandler.java:146)
	at io.grpc.netty.NettyClientHandler.newHandler(NettyClientHandler.java:125)
	at io.grpc.netty.NettyClientTransport.newHandler(NettyClientTransport.java:251)
	at io.grpc.netty.NettyClientTransport.start(NettyClientTransport.java:140)
	at io.grpc.internal.ForwardingConnectionClientTransport.start(ForwardingConnectionClientTransport.java:45)
	at io.grpc.internal.TransportSet.startNewTransport(TransportSet.java:222)
	at io.grpc.internal.TransportSet.obtainActiveTransport(TransportSet.java:192)
	at io.grpc.internal.ManagedChannelImpl$3.getTransport(ManagedChannelImpl.java:651)
	at io.grpc.internal.ManagedChannelImpl$3.getTransport(ManagedChannelImpl.java:592)
	at io.grpc.internal.RoundRobinServerList.getTransportForNextServer(RoundRobinServerList.java:83)
	at io.grpc.util.RoundRobinLoadBalancerFactory$RoundRobinLoadBalancer$1.get(RoundRobinLoadBalancerFactory.java:148)
	at io.grpc.internal.DelayedClientTransport$2.run(DelayedClientTransport.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

虽然没用到nutz的grpc,但是还是想问下。

2 回复

hosts没配好吧

@wendal 不是很明白

客户端配置文件

spring:
  profiles:
    active: dev

eureka:
  client:
    service-url:
      defaultZone: http://admin:admin@localhost:9080/eureka/
      
  instance:
    instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
    
provider-user:
  ribbon:
    NFLoadBalancerRuleClassName: com.netflix.loadbalancer.WeightedResponseTimeRule
    
grpc:
  client:
    provider-user:
      host: localhost
      port: 7052

服务端配置

spring:
  profiles:
    active: dev
    
  datasource:
    druid:
      url: jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=UTF-8
      username: root
      password: 123456
      filter:
        config:
          enabled: true
      initial-size: 5
      min-idle: 5
      max-active: 100
      max-wait: 60000
      time-between-eviction-runs-millis: 60000
      min-evictable-idle-time-millis: 300000
      validation-query: select 'x'
      validation-query-timeout: 60000
      test-while-idle: true
      test-on-borrow: false
      test-on-return: false
      pool-prepared-statements: false
      max-pool-prepared-statement-per-connection-size: -1
      filters: stat,wall,log4j
  application:
    name: provider-user
eureka:
  client:
    service-url:
      defaultZone: http://admin:admin@localhost:9080/eureka/
grpc:
  server:
    port: 7052

兽总,帮看看

添加回复
请先登陆
回到顶部