亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

springboot+HttpInvoke?實(shí)現(xiàn)RPC調(diào)用的方法

 更新時間:2022年03月07日 08:27:01   作者:秋水秋色  
RPC框架大家或多或少都用過,出自于阿里系的就有dubbo,HSF,sofaRPC等,今天通過本文給大家介紹springboot+HttpInvoke?實(shí)現(xiàn)RPC調(diào)用的方法,感興趣的朋友一起看看吧

開始用springboot2+hession4實(shí)現(xiàn)RPC服務(wù)時,發(fā)現(xiàn)第一個服務(wù)可以調(diào)用成功,但第二個就一直報'<'isanunknowncode。第一個服務(wù)還是可以調(diào)用的。參考網(wǎng)上的方法,客戶端與服務(wù)端hession版本保持一致,查看本地版本是一致的, 換成其他版本也沒有效果。設(shè)置重載方法為true,都沒有效果。如果有其他小伙伴有過解決方法,望指正。 后改用用了spring自帶的HTTPInvoke?,F(xiàn)記錄如下:

1、將服務(wù)端的服務(wù)暴露出來

@Configuration
public class HttpInvokeServiceConfig {
 @Bean("/xxx")
 public HttpInvokerServiceExporter rpcService(xxxService xxxService) {
  HttpInvokerServiceExporter httpInvokerServiceExporter = new HttpInvokerServiceExporter();
  httpInvokerServiceExporter.setService(xxxService);
  httpInvokerServiceExporter.setServiceInterface(xxxService.class);
  return httpInvokerServiceExporter;
 }
}

2、客戶端,將接口交由代理去執(zhí)行遠(yuǎn)程方法

@Configuration
public class ClientRpcConfig {
 @Bean
 public HttpInvokerProxyFactoryBean rpcService() {
  HttpInvokerProxyFactoryBean httpInvokerProxyFactoryBean = new HttpInvokerProxyFactoryBean();
  httpInvokerProxyFactoryBean.setServiceUrl(server_url);
  httpInvokerProxyFactoryBean.setServiceInterface(xxxService.class);
  return httpInvokerProxyFactoryBean;
 }
}

注意點(diǎn)

1)、服務(wù)端與客戶端接口名一致、方法參數(shù)一致

2)、如果接口參數(shù)是對象的話,參數(shù)對象須實(shí)現(xiàn)序列化

3)、接口參數(shù)是對象的話,服務(wù)端與客戶端對象名要一致、包路徑也得一致。 不然會報找不到類

3、將接口注入在所需要的地方即可實(shí)現(xiàn)遠(yuǎn)程調(diào)用接口所定義的方法

到此這篇關(guān)于springboot+HttpInvoke 實(shí)現(xiàn)RPC調(diào)用的文章就介紹到這了,更多相關(guān)springboot RPC調(diào)用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論