26 changed files with 585 additions and 2 deletions
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>blade-example-api</artifactId> |
||||
<groupId>org.springblade</groupId> |
||||
<version>2.0.0.RELEASE</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>blade-dubbo-provider-api</artifactId> |
||||
<name>${project.artifactId}</name> |
||||
<version>${bladex.project.version}</version> |
||||
<packaging>jar</packaging> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.apache.dubbo</groupId> |
||||
<artifactId>dubbo</artifactId> |
||||
<version>${dubbo.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.dubbo</groupId> |
||||
<artifactId>dubbo-registry-nacos</artifactId> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>com.alibaba.nacos</groupId> |
||||
<artifactId>nacos-client</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
<version>${dubbo.version}</version> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
</project> |
@ -0,0 +1,31 @@
|
||||
package org.springblade.example.provider.entity; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* Blog实体类 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@Data |
||||
public class Blog implements Serializable { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
/** |
||||
* 主键 |
||||
*/ |
||||
private Integer id; |
||||
|
||||
/** |
||||
* 标题 |
||||
*/ |
||||
private String title; |
||||
/** |
||||
* 内容 |
||||
*/ |
||||
private String content; |
||||
|
||||
} |
@ -0,0 +1,19 @@
|
||||
package org.springblade.example.provider.rpc; |
||||
|
||||
import org.springblade.example.provider.entity.Blog; |
||||
|
||||
/** |
||||
* RPC接口类 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
public interface IBlogRpc { |
||||
|
||||
/** |
||||
* Blog详情 |
||||
* |
||||
* @param id 主键 |
||||
* @return |
||||
*/ |
||||
Blog detail(Integer id); |
||||
} |
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>BladeX-Biz</artifactId> |
||||
<groupId>org.springblade</groupId> |
||||
<version>2.0.0.RELEASE</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>blade-example-api</artifactId> |
||||
<name>${project.artifactId}</name> |
||||
<version>${bladex.project.version}</version> |
||||
<packaging>pom</packaging> |
||||
<description>BladeX 微服务范例API集合</description> |
||||
|
||||
<modules> |
||||
<module>blade-dubbo-provider-api</module> |
||||
</modules> |
||||
|
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.springframework.boot</groupId> |
||||
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
<configuration> |
||||
<skip>true</skip> |
||||
<finalName>${project.name}</finalName> |
||||
</configuration> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>com.spotify</groupId> |
||||
<artifactId>docker-maven-plugin</artifactId> |
||||
<version>${docker.plugin.version}</version> |
||||
<configuration> |
||||
<skipDockerBuild>true</skipDockerBuild> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
|
||||
</project> |
@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>blade-example</artifactId> |
||||
<groupId>org.springblade</groupId> |
||||
<version>2.0.0.RELEASE</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>blade-dubbo-consumer</artifactId> |
||||
<name>${project.artifactId}</name> |
||||
<version>${bladex.project.version}</version> |
||||
<packaging>jar</packaging> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.springblade</groupId> |
||||
<artifactId>blade-core-boot</artifactId> |
||||
<version>${bladex.tool.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springblade</groupId> |
||||
<artifactId>blade-starter-swagger</artifactId> |
||||
<version>${bladex.tool.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springblade</groupId> |
||||
<artifactId>blade-dubbo-provider-api</artifactId> |
||||
<version>${bladex.project.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.dubbo</groupId> |
||||
<artifactId>dubbo</artifactId> |
||||
<version>${dubbo.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.dubbo</groupId> |
||||
<artifactId>dubbo-registry-nacos</artifactId> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>com.alibaba.nacos</groupId> |
||||
<artifactId>nacos-client</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
<version>${dubbo.version}</version> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
|
||||
</project> |
@ -0,0 +1,23 @@
|
||||
package org.springblade.example.consumer; |
||||
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; |
||||
import org.springblade.common.constant.CommonConstant; |
||||
import org.springblade.core.cloud.feign.EnableBladeFeign; |
||||
import org.springblade.core.launch.BladeApplication; |
||||
import org.springframework.cloud.client.SpringCloudApplication; |
||||
|
||||
/** |
||||
* DubboConsumerApplication |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@EnableDubbo |
||||
@EnableBladeFeign |
||||
@SpringCloudApplication |
||||
public class DubboConsumerApplication { |
||||
|
||||
public static void main(String[] args) { |
||||
BladeApplication.run(CommonConstant.APPLICATION_DUBBO_CONSUMER_NAME, DubboConsumerApplication.class, args); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,23 @@
|
||||
package org.springblade.example.consumer.config; |
||||
|
||||
import org.springblade.core.secure.registry.SecureRegistry; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
/** |
||||
* ConsumerConfiguration |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@Configuration |
||||
public class ConsumerConfiguration { |
||||
|
||||
@Bean |
||||
public SecureRegistry secureRegistry() { |
||||
SecureRegistry secureRegistry = new SecureRegistry(); |
||||
secureRegistry.excludePathPatterns("/blog/**"); |
||||
return secureRegistry; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
package org.springblade.example.consumer.controller; |
||||
|
||||
import org.apache.dubbo.config.annotation.Reference; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.example.provider.entity.Blog; |
||||
import org.springblade.example.provider.rpc.IBlogRpc; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PathVariable; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* Blog控制器 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("blog") |
||||
public class BlogController { |
||||
|
||||
@Reference( |
||||
version = "${blade.service.version}", |
||||
mock = "org.springblade.example.consumer.rpc.BlogMock", |
||||
//stub = "org.springblade.example.consumer.rpc.BlogStub",
|
||||
check = false |
||||
) |
||||
private IBlogRpc rpc; |
||||
|
||||
@GetMapping("detail/{id}") |
||||
public R<Blog> detail(@PathVariable Integer id) { |
||||
Blog detail = rpc.detail(id); |
||||
return R.data(detail); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,17 @@
|
||||
package org.springblade.example.consumer.rpc; |
||||
|
||||
|
||||
import org.springblade.example.provider.entity.Blog; |
||||
import org.springblade.example.provider.rpc.IBlogRpc; |
||||
|
||||
/** |
||||
* 降级容错 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
public class BlogMock implements IBlogRpc { |
||||
@Override |
||||
public Blog detail(Integer id) { |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,28 @@
|
||||
package org.springblade.example.consumer.rpc; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.example.provider.entity.Blog; |
||||
import org.springblade.example.provider.rpc.IBlogRpc; |
||||
|
||||
/** |
||||
* 本地存根 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@Slf4j |
||||
@AllArgsConstructor |
||||
public class BlogStub implements IBlogRpc { |
||||
|
||||
private IBlogRpc rpc; |
||||
|
||||
@Override |
||||
public Blog detail(Integer id) { |
||||
try { |
||||
return rpc.detail(id); |
||||
} catch (Exception ex) { |
||||
log.error(ex.getMessage()); |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,16 @@
|
||||
#服务器端口 |
||||
server: |
||||
port: 8306 |
||||
|
||||
dubbo: |
||||
#协议配置端口 |
||||
protocol: |
||||
port: 28306 |
||||
|
||||
#数据源配置 |
||||
spring: |
||||
datasource: |
||||
url: ${blade.datasource.dev.url} |
||||
username: ${blade.datasource.dev.username} |
||||
password: ${blade.datasource.dev.password} |
||||
|
@ -0,0 +1,16 @@
|
||||
#服务器端口 |
||||
server: |
||||
port: 8306 |
||||
|
||||
dubbo: |
||||
#协议配置端口 |
||||
protocol: |
||||
port: 28306 |
||||
|
||||
#数据源配置 |
||||
spring: |
||||
datasource: |
||||
url: ${blade.datasource.prod.url} |
||||
username: ${blade.datasource.prod.username} |
||||
password: ${blade.datasource.prod.password} |
||||
|
@ -0,0 +1,16 @@
|
||||
#服务器端口 |
||||
server: |
||||
port: 8306 |
||||
|
||||
dubbo: |
||||
#协议配置端口 |
||||
protocol: |
||||
port: 28306 |
||||
|
||||
#数据源配置 |
||||
spring: |
||||
datasource: |
||||
url: ${blade.datasource.test.url} |
||||
username: ${blade.datasource.test.username} |
||||
password: ${blade.datasource.test.password} |
||||
|
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>blade-example</artifactId> |
||||
<groupId>org.springblade</groupId> |
||||
<version>2.0.0.RELEASE</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>blade-dubbo-provider</artifactId> |
||||
<name>${project.artifactId}</name> |
||||
<version>${bladex.project.version}</version> |
||||
<packaging>jar</packaging> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.springblade</groupId> |
||||
<artifactId>blade-core-boot</artifactId> |
||||
<version>${bladex.tool.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springblade</groupId> |
||||
<artifactId>blade-starter-swagger</artifactId> |
||||
<version>${bladex.tool.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springblade</groupId> |
||||
<artifactId>blade-dubbo-provider-api</artifactId> |
||||
<version>${bladex.project.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.dubbo</groupId> |
||||
<artifactId>dubbo</artifactId> |
||||
<version>${dubbo.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.dubbo</groupId> |
||||
<artifactId>dubbo-registry-nacos</artifactId> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>com.alibaba.nacos</groupId> |
||||
<artifactId>nacos-client</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
<version>${dubbo.version}</version> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
</project> |
@ -0,0 +1,23 @@
|
||||
package org.springblade.example.provider; |
||||
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; |
||||
import org.springblade.common.constant.CommonConstant; |
||||
import org.springblade.core.cloud.feign.EnableBladeFeign; |
||||
import org.springblade.core.launch.BladeApplication; |
||||
import org.springframework.cloud.client.SpringCloudApplication; |
||||
|
||||
/** |
||||
* DubboProviderApplication |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@EnableDubbo |
||||
@EnableBladeFeign |
||||
@SpringCloudApplication |
||||
public class DubboProviderApplication { |
||||
|
||||
public static void main(String[] args) { |
||||
BladeApplication.run(CommonConstant.APPLICATION_DUBBO_PROVIDER_NAME, DubboProviderApplication.class, args); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,12 @@
|
||||
package org.springblade.example.provider.controller; |
||||
|
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
/** |
||||
* Blog控制器 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@RestController |
||||
public class BlogController { |
||||
} |
@ -0,0 +1,23 @@
|
||||
package org.springblade.example.provider.rpc; |
||||
|
||||
import org.apache.dubbo.config.annotation.Service; |
||||
import org.springblade.example.provider.entity.Blog; |
||||
|
||||
/** |
||||
* BlogRpc实现类 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@Service( |
||||
version = "${blade.service.version}" |
||||
) |
||||
public class BlogRpc implements IBlogRpc { |
||||
@Override |
||||
public Blog detail(Integer id) { |
||||
Blog blog = new Blog(); |
||||
blog.setId(id); |
||||
blog.setTitle("博客标题"); |
||||
blog.setContent("博客内容"); |
||||
return blog; |
||||
} |
||||
} |
@ -0,0 +1,15 @@
|
||||
#服务器端口 |
||||
server: |
||||
port: 8305 |
||||
|
||||
dubbo: |
||||
#协议配置端口 |
||||
protocol: |
||||
port: 28305 |
||||
|
||||
#数据源配置 |
||||
spring: |
||||
datasource: |
||||
url: ${blade.datasource.dev.url} |
||||
username: ${blade.datasource.dev.username} |
||||
password: ${blade.datasource.dev.password} |
@ -0,0 +1,17 @@
|
||||
#服务器端口 |
||||
server: |
||||
port: 8305 |
||||
|
||||
dubbo: |
||||
#协议配置端口 |
||||
protocol: |
||||
port: 28305 |
||||
|
||||
#数据源配置 |
||||
spring: |
||||
datasource: |
||||
url: ${blade.datasource.prod.url} |
||||
username: ${blade.datasource.prod.username} |
||||
password: ${blade.datasource.prod.password} |
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
#服务器端口 |
||||
server: |
||||
port: 8305 |
||||
|
||||
dubbo: |
||||
#协议配置端口 |
||||
protocol: |
||||
port: 28305 |
||||
|
||||
#数据源配置 |
||||
spring: |
||||
datasource: |
||||
url: ${blade.datasource.test.url} |
||||
username: ${blade.datasource.test.username} |
||||
password: ${blade.datasource.test.password} |
||||
|
||||
|
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<parent> |
||||
<artifactId>BladeX-Biz</artifactId> |
||||
<groupId>org.springblade</groupId> |
||||
<version>2.0.0.RELEASE</version> |
||||
</parent> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<artifactId>blade-example</artifactId> |
||||
<name>${project.artifactId}</name> |
||||
<version>2.0.0.RELEASE</version> |
||||
<packaging>pom</packaging> |
||||
<description>BladeX 微服务范例集合</description> |
||||
|
||||
<modules> |
||||
<module>blade-dubbo-consumer</module> |
||||
<module>blade-dubbo-provider</module> |
||||
</modules> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.springblade</groupId> |
||||
<artifactId>blade-common</artifactId> |
||||
<version>${bladex.project.version}</version> |
||||
</dependency> |
||||
</dependencies> |
||||
|
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>com.spotify</groupId> |
||||
<artifactId>docker-maven-plugin</artifactId> |
||||
<version>${docker.plugin.version}</version> |
||||
<configuration> |
||||
<skipDockerBuild>true</skipDockerBuild> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
|
||||
</project> |
Loading…
Reference in new issue