sofastack / sofa-rpc-boot-projects

SOFABoot projects for SOFARPC, include starter and samples.
https://github.com/sofastack/sofa-rpc
Apache License 2.0
292 stars 117 forks source link

REST 协议使用咨询 #23

Closed leizhiyuan closed 6 years ago

leizhiyuan commented 6 years ago

问题来源:

https://github.com/alipay/sofa-rpc-boot-projects/issues/22

@wangxiaotao00 我看sofa框架支持restful,restful也需要注册中心,同样可以用zookeeper做注册中心吗

leizhiyuan commented 6 years ago

@NeGnail

wangxiaotao00 commented 6 years ago

按照demo中配置rest协议, 启动后报错 RPC-02306: 没有获得服务[com.jsmfbank.sse.facade.RestService:1.0]的调用地址,请检查服务是否已经推送

wangxiaotao00 commented 6 years ago

本地访问rest接口正常:http://localhost:8341/webapi/restService/1001

leizhiyuan commented 6 years ago

@wangxiaotao00 本地 zk 起了吗? 报错日志也提供下.

入门文档中有提到这个.

您可以直接在工程下找到本文档的示例代码。注意,示例代码中需要本地安装 zookeeper 环境,如果没有安装.需要将application.properties中的com.alipay.sofa.rpc.registry.address 配置注释掉.走本地文件注册中心的方式

wangxiaotao00 commented 6 years ago

没有zk,配置文件中注释了。 完整错误日志如下:

2018-05-05 11:50:43.892 INFO 7024 --- [ main] c.j.s.s.SpringBootSseApplication : Started SpringBootSseApplication in 57.374 seconds (JVM running for 57.696) Exception in thread "main" com.alipay.sofa.rpc.core.exception.SofaRouteException: RPC-02306: 没有获得服务[com.jsmfbank.sse.facade.RestService:1.0]的调用地址,请检查服务是否已经推送 at com.alipay.sofa.rpc.client.AbstractCluster.noAvailableProviderException(AbstractCluster.java:419) at com.alipay.sofa.rpc.client.AbstractCluster.select(AbstractCluster.java:391) at com.alipay.sofa.rpc.client.FailoverCluster.doInvoke(FailoverCluster.java:64) at com.alipay.sofa.rpc.client.AbstractCluster.invoke(AbstractCluster.java:286) at com.alipay.sofa.rpc.client.ClientProxyInvoker.invoke(ClientProxyInvoker.java:83) at com.alipay.sofa.rpc.proxy.jdk.JDKInvocationHandler.invoke(JDKInvocationHandler.java:74) at com.sun.proxy.$Proxy51.sayRest(Unknown Source) at com.jsmfbank.sse.springbootsse.SpringBootSseApplication.main(SpringBootSseApplication.java:27)

NeGnail commented 6 years ago

在调用之前睡一下线程试试。如 sample 中的例子,在调用之前加入 Thread.sleep :

RestService restService = (RestService) applicationContext.getBean("restServiceReference");
Thread.sleep(5000)
String result = restService.sayRest("rest");
wangxiaotao00 commented 6 years ago

可以了,谢谢

leizhiyuan commented 6 years ago

@wangxiaotao00 好的,稍后相关用例我们做一下优化.