Commit 21e68e02 by HanChao

增加,服务间互相调用 示例

parent d3a585c2
package com.gzicloud.industry.client.api;
package com.gzicloud.industry.client.export;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
......
package com.gzicloud.industry.client.api.controller;
package com.gzicloud.industry.client.export.controller;
import com.gzicloud.industry.client.facade.service.IAcrossService;
import com.gzicloud.industry.client.facade.service.ITestService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -13,6 +14,9 @@ public class TestController {
@DubboReference
private ITestService resumeService;
@DubboReference
private IAcrossService acrossService;
@GetMapping("/simple")
public String simple(String id) {
return resumeService.test(Long.valueOf(id));
......@@ -23,4 +27,9 @@ public class TestController {
return "测试:" + id;
}
@GetMapping("/across")
public String across(String id) {
return acrossService.acrossServer(Long.valueOf(id));
}
}
......@@ -16,7 +16,7 @@ dubbo:
protocol:
# dubbo 协议
name: dubbo
# dubbo 协议端口( -1 表示自增端口,从 20880 开始)
# # dubbo 协议端口( -1 表示自增端口,从 20880 开始)
port: -1
host: 127.0.0.1
registry:
......@@ -24,4 +24,4 @@ dubbo:
address: spring-cloud://localhost
cloud:
# 订阅服务提供方的应用列表,订阅多个服务提供者使用 "," 连接
subscribed-services: industry-client-resume-server
subscribed-services: industry-client-resume-server,industry-client-export-server
<?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>industry-cloud-parent</artifactId>
<groupId>org.gzicloud.industry</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>client-export-server</artifactId>
<properties>
<mybatis-plus.version>3.4.1</mybatis-plus.version>
</properties>
<dependencies>
<dependency>
<groupId>org.gzicloud.industry</groupId>
<artifactId>client-facade</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- MyBatis-Plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.gzicloud.industry.client.export;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@EnableDiscoveryClient
@SpringBootApplication
public class ClientExportApplication {
public static void main(String[] args) {
SpringApplication.run(ClientExportApplication.class, args);
}
}
package com.gzicloud.industry.client.export.dubbo.call;
import com.gzicloud.industry.client.facade.service.ITestService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
@Service
public class CallService {
@DubboReference
private ITestService testService;
public String call(Long id) {
return "服务间相互调用" + testService.test(id);
}
}
package com.gzicloud.industry.client.export.dubbo.impl;
import com.gzicloud.industry.client.export.service.ICountryService;
import com.gzicloud.industry.client.facade.service.IAcrossService;
import org.apache.dubbo.config.annotation.DubboService;
import javax.annotation.Resource;
@DubboService
public class AcrossServiceImpl implements IAcrossService {
@Resource
private ICountryService countryService;
@Override
public String acrossServer(Long id) {
return countryService.getCountry(id);
}
}
package com.gzicloud.industry.client.export.service;
public interface ICountryService {
String getCountry(Long id);
}
package com.gzicloud.industry.client.export.service.impl;
import com.gzicloud.industry.client.export.dubbo.call.CallService;
import com.gzicloud.industry.client.export.service.ICountryService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class CountryServiceImpl implements ICountryService {
@Resource
private CallService callService;
@Override
public String getCountry(Long id) {
return callService.call(id);
}
}
spring:
cloud:
nacos:
discovery:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
config:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
group: DEFAULT_GROUP # 默认分组就是DEFAULT_GROUP,如果使用默认分组可以不配置
file-extension: yml #默认properties
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: hanchao
password: 123123
url: jdbc:mysql://localhost:3306/db2020?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8
hikari:
minimum-idle: 10
maximum-pool-size: 15
connection-timeout: 1000
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper-locations: classpath:/mapper/*Mapper.xml
dubbo:
scan:
# dubbo 服务扫描基准包
base-packages: com.gzicloud.industry.client.export
protocol:
# dubbo 协议
name: dubbo
# dubbo 协议端口( -1 表示自增端口,从 20880 开始)
port: -1
host: 127.0.0.1
registry:
# 挂载到 Spring Cloud 的注册中心
address: spring-cloud://localhost
cloud:
subscribed-services: industry-client-resume-server
\ No newline at end of file
server:
port: 8003
spring:
application:
name: industry-client-resume-server
cloud:
nacos:
discovery:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
config:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
group: DEFAULT_GROUP # 默认分组就是DEFAULT_GROUP,如果使用默认分组可以不配置
file-extension: yml #默认properties
\ No newline at end of file
server:
port: 8003
spring:
application:
name: industry-client-resume-server
cloud:
nacos:
discovery:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
config:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
group: DEFAULT_GROUP # 默认分组就是DEFAULT_GROUP,如果使用默认分组可以不配置
file-extension: yml #默认properties
\ No newline at end of file
spring:
profiles:
active: dev
application:
name: industry-client-export-server
\ No newline at end of file
package com.gzicloud.industry.client.facade.service;
/**
* 测试服务间调用
*/
public interface IAcrossService {
String acrossServer(Long id);
}
package com.gzicloud.industry.client.resume.dubbo;
package com.gzicloud.industry.client.resume.dubbo.impl;
import com.gzicloud.industry.client.facade.service.ITestService;
import com.gzicloud.industry.client.resume.service.IResumeService;
......
......@@ -12,6 +12,7 @@
<module>client-api</module>
<module>client-resume-server</module>
<module>client-facade</module>
<module>client-export-server</module>
</modules>
<packaging>pom</packaging>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment