- demo 项目,增加 RPC 接口
This commit is contained in:
@@ -11,5 +11,55 @@
|
||||
|
||||
<artifactId>demo-rpc-service</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- Mall 相关 -->
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>demo-rpc-service-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>demo-business-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<artifactId>demo-business</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- RPC 相关 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Registry 和 Config 相关 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-framework</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-recipes</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- 提供给 mapstruct 使用 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.iocoder.mall.demo.rpc.convert;
|
||||
|
||||
import cn.iocoder.mall.demo.business.bo.product.DemoProductBO;
|
||||
import cn.iocoder.mall.demo.rpc.vo.DemoProductVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface DemoProductConvert {
|
||||
|
||||
DemoProductConvert INSTANCE = Mappers.getMapper(DemoProductConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
DemoProductVO convert(DemoProductBO object);
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package cn.iocoder.mall.demo.rpc;
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.iocoder.mall.demo.rpc.service;
|
||||
|
||||
import cn.iocoder.mall.demo.business.api.DemoProductService;
|
||||
import cn.iocoder.mall.demo.business.bo.product.DemoProductBO;
|
||||
import cn.iocoder.mall.demo.rpc.api.DemoProductRpcService;
|
||||
import cn.iocoder.mall.demo.rpc.convert.DemoProductConvert;
|
||||
import cn.iocoder.mall.demo.rpc.vo.DemoProductVO;
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@Service(validation = "true", version = "${dubbo.provider.DemoProductRpcService.version}")
|
||||
public class DemoProductRpcServiceImpl implements DemoProductRpcService {
|
||||
|
||||
@Autowired
|
||||
private DemoProductService productService;
|
||||
|
||||
@Override
|
||||
public DemoProductVO get(Integer id) {
|
||||
DemoProductBO product = productService.get(id);
|
||||
return DemoProductConvert.INSTANCE.convert(product);
|
||||
}
|
||||
|
||||
}
|
||||
18
demo/demo-rpc-service/src/main/resources/rpc-local.yaml
Normal file
18
demo/demo-rpc-service/src/main/resources/rpc-local.yaml
Normal file
@@ -0,0 +1,18 @@
|
||||
# dubbo
|
||||
dubbo:
|
||||
application:
|
||||
name: demo-service
|
||||
registry:
|
||||
address: zookeeper://127.0.0.1:2181
|
||||
protocol:
|
||||
port: -1
|
||||
name: dubbo
|
||||
scan:
|
||||
base-packages: cn.iocoder.mall.demo.rpc.service
|
||||
# consumer:
|
||||
# ProductSpuService:
|
||||
# version: 1.0.0
|
||||
provider:
|
||||
# filter: -exception
|
||||
DemoProductRpcService:
|
||||
version: 1.0.0
|
||||
Reference in New Issue
Block a user