栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SOFA Boot 整合SOFA RPC 、SOFA Registry

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SOFA Boot 整合SOFA RPC 、SOFA Registry

参考资料

https://www.wenjiangs.com/doc/dc7xvpxh

https://www.sofastack.tech/projects/sofa-rpc/getting-started-with-rpc/

SOFA Stack 在gitee上的源码仓库

https://gitee.com/sofastack

源码

stulab-sofarpc.zip

整合的关键步骤 添加依赖项

注意版本号


    com.alipay.sofa
    sofaboot-dependencies
    2.6.4



    com.alipay.sofa
    sofa-rpc-all
    5.5.2


    com.alipay.sofa
    registry-client-all
    5.2.0

配制application.properties
spring.application.name=service-provider

logging.path=./logs

com.alipay.sofa.rpc.registry.address=sofa://127.0.0.1:9603
com.alipay.sofa.rpc.bolt.port=12201

server.port=8801
发布服务(服务提供方)
import org.springframework.stereotype.Service;

import com.alipay.sofa.runtime.api.annotation.SofaService;
import com.alipay.sofa.runtime.api.annotation.SofaServiceBinding;
import com.stulab.sofarpc.api.HelloService;

@SofaService(interfaceType = HelloService.class, 
bindings = { @SofaServiceBinding(bindingType = "bolt") })
@Service
public class HelloServiceImpl implements HelloService{

	@Override
	public String hello() {
		return "Hello World";
	}

}
调用服务(服务消息方)
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alipay.sofa.runtime.api.annotation.SofaReference;
import com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding;
import com.stulab.sofarpc.api.HelloService;

@RestController
public class HelloResource {

	@SofaReference(interfaceType = HelloService.class, binding =          @SofaReferenceBinding(bindingType = "bolt"))
	HelloService helloService;

	@RequestMapping("/hello")
	public String hello() {
		return helloService.hello();
	}
	
}
注意点

1、注意SOFA相关依赖的版本,这里面坑挺多

2、发布服务是注意加上@Service注解

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/459243.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号