soul 入门 第四章 sofa 接入网关
首先启动网关,具体步骤 见 第一章
作为rpc框架,sofa跟dubbo在接入上差不多
使用官方提供的工程soul-examples-sofa做演示
1、引入依赖jar,soul-spring-boot-starter-client-sofa 的作用是把sofa接口信息同步到soul网关
<dependency>
<groupId>org.dromara</groupId>
<artifactId>soul-spring-boot-starter-client-sofa</artifactId>
<version>${soul.version}</version>
<exclusions>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency>
2、修改配置文件 application.yml
com:
alipay:
sofa:
rpc:
registry-address: zookeeper://127.0.0.1:2181 # sofa 接口注册到zookeeper
bolt-port: 8888
soul:
sofa:
adminUrl: http://localhost:9095 # sofa 接口同步到soul到地址
contextPath: /sofa # 路径前缀
appName: sofa
3、sofa接口加上注解 SoulSofaClient
@Service("sofaTestService")
public class SofaTestServiceImpl implements DubboTestService {
@Override
@SoulSofaClient(path = "/findById", desc = "Find by Id")
public DubboTest findById(final String id) {
DubboTest dubboTest = new DubboTest();
dubboTest.setId(id);
dubboTest.setName("hello world Soul Sofa, findById");
return dubboTest;
}
}
4、启动zookeeper
5、soul-admin 控制台启用sofa插件
6、执行类 TestSofaApplication启动sofa服务