https://www.wenjiangs.com/doc/dc7xvpxh
https://www.sofastack.tech/projects/sofa-rpc/getting-started-with-rpc/
SOFA Stack 在gitee上的源码仓库
注意版本号
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofaboot-dependencies</artifactId>
<version>2.6.4</version>
</parent>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-rpc-all</artifactId>
<version>5.5.2</version>
</dependency>
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-client-all</artifactId>
<version>5.2.0</version>
</dependency>
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注解