forked from wuyouzhuguli/SpringAll
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
727f860
commit b6f95a6
Showing
11 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?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>dubbo-boot</artifactId> | ||
<groupId>cc.mrbird</groupId> | ||
<version>1.0</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>common-api</artifactId> | ||
|
||
</project> |
5 changes: 5 additions & 0 deletions
5
53.Dubbo-High-Availability/common-api/src/main/java/cc/mrbird/common/api/HelloService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package cc.mrbird.common.api; | ||
|
||
public interface HelloService { | ||
String hello(String message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>cc.mrbird</groupId> | ||
<artifactId>dubbo-boot</artifactId> | ||
<packaging>pom</packaging> | ||
<version>1.0</version> | ||
|
||
<name>dubbo-boot</name> | ||
<description>Spring Boot-Dubbo-ZooKeeper</description> | ||
|
||
<modules> | ||
<module>common-api</module> | ||
<module>server-provider</module> | ||
<module>server-consumer</module> | ||
</modules> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.0.4.RELEASE</version> | ||
<relativePath/> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
<project.version>1.0</project.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<!-- dubbo --> | ||
<dependency> | ||
<groupId>com.alibaba.boot</groupId> | ||
<artifactId>dubbo-spring-boot-starter</artifactId> | ||
<version>0.2.0</version> | ||
</dependency> | ||
|
||
<!-- zookeeper --> | ||
<dependency> | ||
<groupId>org.apache.zookeeper</groupId> | ||
<artifactId>zookeeper</artifactId> | ||
<version>3.4.8</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.101tec</groupId> | ||
<artifactId>zkclient</artifactId> | ||
<version>0.10</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
<encoding>${project.build.sourceEncoding}</encoding> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?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>dubbo-boot</artifactId> | ||
<groupId>cc.mrbird</groupId> | ||
<version>1.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>server-consumer</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>cc.mrbird</groupId> | ||
<artifactId>common-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
13 changes: 13 additions & 0 deletions
13
53.Dubbo-High-Availability/server-consumer/src/main/java/cc/mrbird/ConsumerApplicaiton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cc.mrbird; | ||
|
||
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@EnableDubbo | ||
@SpringBootApplication | ||
public class ConsumerApplicaiton { | ||
public static void main(String[] args) { | ||
SpringApplication.run(ConsumerApplicaiton.class, args); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...lability/server-consumer/src/main/java/cc/mrbird/consumer/controller/HelloController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cc.mrbird.consumer.controller; | ||
|
||
import cc.mrbird.common.api.HelloService; | ||
import com.alibaba.dubbo.config.annotation.Reference; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class HelloController { | ||
|
||
// @Reference(url = "http://127.0.0.1:8080") | ||
// @Reference(loadbalance = RoundRobinLoadBalance.NAME) | ||
@Reference(timeout = 1000) | ||
private HelloService helloService; | ||
|
||
@GetMapping("/hello/{message}") | ||
public String hello(@PathVariable String message) { | ||
return this.helloService.hello(message); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
53.Dubbo-High-Availability/server-consumer/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
server: | ||
port: 8081 | ||
|
||
dubbo: | ||
application: | ||
# 服务名称,保持唯一 | ||
name: server-consumer | ||
# zookeeper地址,用于从中获取注册的服务 | ||
registry: | ||
address: zookeeper://127.0.0.1:2181 | ||
protocol: | ||
# dubbo协议,固定写法 | ||
name: dubbo | ||
monitor: | ||
protocol: registry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?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>dubbo-boot</artifactId> | ||
<groupId>cc.mrbird</groupId> | ||
<version>1.0</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>server-provider</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>cc.mrbird</groupId> | ||
<artifactId>common-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId> | ||
<version>2.0.2.RELEASE</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
16 changes: 16 additions & 0 deletions
16
53.Dubbo-High-Availability/server-provider/src/main/java/cc/mrbird/ProviderApplicaiton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cc.mrbird; | ||
|
||
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.netflix.hystrix.EnableHystrix; | ||
|
||
@EnableHystrix | ||
@EnableDubbo | ||
@SpringBootApplication | ||
public class ProviderApplicaiton { | ||
public static void main(String[] args) { | ||
SpringApplication.run(ProviderApplicaiton.class, args); | ||
System.out.println("complete"); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ailability/server-provider/src/main/java/cc/mrbird/provider/service/HelloServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package cc.mrbird.provider.service; | ||
|
||
import cc.mrbird.common.api.HelloService; | ||
import com.alibaba.dubbo.config.annotation.Service; | ||
import com.alibaba.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance; | ||
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@Service( | ||
interfaceClass = HelloService.class, | ||
weight = 100, | ||
loadbalance = RoundRobinLoadBalance.NAME) | ||
@Component | ||
public class HelloServiceImpl implements HelloService { | ||
|
||
@Override | ||
@HystrixCommand(fallbackMethod = "defaultHello") | ||
public String hello(String message) { | ||
System.out.println("调用 cc.mrbird.provider.service.HelloServiceImpl#hello"); | ||
// try { | ||
// TimeUnit.SECONDS.sleep(2); | ||
// } catch (InterruptedException e) { | ||
// e.printStackTrace(); | ||
// } | ||
String a = null; | ||
a.toString(); | ||
return "hello," + message; | ||
} | ||
|
||
public String defaultHello(String message) { | ||
return "hello anonymous"; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
53.Dubbo-High-Availability/server-provider/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
server: | ||
port: 8080 | ||
|
||
dubbo: | ||
application: | ||
# 服务名称,保持唯一 | ||
name: server-provider | ||
# zookeeper地址,用于向其注册服务 | ||
registry: | ||
address: zookeeper://127.0.0.1:2181 | ||
#暴露服务方式 | ||
protocol: | ||
# dubbo协议,固定写法 | ||
name: dubbo | ||
# 暴露服务端口 (默认是20880,不同的服务提供者端口不能重复) | ||
port: 20880 | ||
monitor: | ||
protocol: registry |