Skip to content

Commit b6d72c3

Browse files
author
黑小马
committed
处理cloud模块
1 parent 9551b82 commit b6d72c3

28 files changed

Lines changed: 526 additions & 137 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>cn.hserver</groupId>
8+
<artifactId>hserver-cloud</artifactId>
9+
<version>3.7.M1</version>
10+
</parent>
11+
12+
<artifactId>hserver-cloud-common</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>8</maven.compiler.source>
16+
<maven.compiler.target>8</maven.compiler.target>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
</project>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package cn.hserver.cloud.common;
2+
3+
public class RegProp {
4+
//注册名字
5+
private String registerAddress;
6+
//注册名字
7+
private String registerName;
8+
//注册我的Ip
9+
private String registerMyIp;
10+
//注册我的端口
11+
private Integer registerMyPort;
12+
//注册分组
13+
private String groupName = "DEFAULT_GROUP";
14+
15+
public String getRegisterAddress() {
16+
return registerAddress;
17+
}
18+
19+
public void setRegisterAddress(String registerAddress) {
20+
this.registerAddress = registerAddress;
21+
}
22+
23+
public String getRegisterName() {
24+
return registerName;
25+
}
26+
27+
public void setRegisterName(String registerName) {
28+
this.registerName = registerName;
29+
}
30+
31+
public String getRegisterMyIp() {
32+
return registerMyIp;
33+
}
34+
35+
public void setRegisterMyIp(String registerMyIp) {
36+
this.registerMyIp = registerMyIp;
37+
}
38+
39+
public Integer getRegisterMyPort() {
40+
return registerMyPort;
41+
}
42+
43+
public void setRegisterMyPort(Integer registerMyPort) {
44+
this.registerMyPort = registerMyPort;
45+
}
46+
47+
public String getGroupName() {
48+
return groupName;
49+
}
50+
51+
public void setGroupName(String groupName) {
52+
this.groupName = groupName;
53+
}
54+
55+
public boolean hasNull() {
56+
if (this.registerAddress == null || this.registerMyIp == null || this.registerMyPort == null || this.registerName == null) {
57+
return true;
58+
} else {
59+
return false;
60+
}
61+
}
62+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package cn.hserver.cloud.common;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class ServerInstance {
7+
/**
8+
* instance ip.
9+
*/
10+
private String ip;
11+
12+
/**
13+
* instance port.
14+
*/
15+
private int port;
16+
17+
/**
18+
* instance weight.
19+
*/
20+
private double weight = 1.0D;
21+
22+
/**
23+
* instance health status.
24+
*/
25+
private boolean healthy = true;
26+
/**
27+
* Service information of instance.
28+
*/
29+
private String serviceName;
30+
31+
/**
32+
* 用户定义的服务名
33+
*/
34+
private String clusterName;
35+
36+
public String getClusterName() {
37+
return clusterName;
38+
}
39+
40+
public void setClusterName(String clusterName) {
41+
this.clusterName = clusterName;
42+
}
43+
44+
/**
45+
* user extended attributes.
46+
*/
47+
private Map<String, String> metadata = new HashMap<>();
48+
49+
public ServerInstance() {
50+
}
51+
52+
public ServerInstance(String ip, int port, double weight, boolean healthy, String serviceName, String clusterName, Map<String, String> metadata) {
53+
this.ip = ip;
54+
this.port = port;
55+
this.weight = weight;
56+
this.healthy = healthy;
57+
this.serviceName = serviceName;
58+
this.clusterName = clusterName;
59+
this.metadata = metadata;
60+
}
61+
62+
public String getIp() {
63+
return ip;
64+
}
65+
66+
public void setIp(String ip) {
67+
this.ip = ip;
68+
}
69+
70+
public int getPort() {
71+
return port;
72+
}
73+
74+
public void setPort(int port) {
75+
this.port = port;
76+
}
77+
78+
public double getWeight() {
79+
return weight;
80+
}
81+
82+
public void setWeight(double weight) {
83+
this.weight = weight;
84+
}
85+
86+
public boolean isHealthy() {
87+
return healthy;
88+
}
89+
90+
public void setHealthy(boolean healthy) {
91+
this.healthy = healthy;
92+
}
93+
94+
public String getServiceName() {
95+
return serviceName;
96+
}
97+
98+
public void setServiceName(String serviceName) {
99+
this.serviceName = serviceName;
100+
}
101+
102+
public Map<String, String> getMetadata() {
103+
return metadata;
104+
}
105+
106+
public void setMetadata(Map<String, String> metadata) {
107+
this.metadata = metadata;
108+
}
109+
110+
public String getEq() {
111+
return this.getIp()+getPort()+getClusterName()+isHealthy();
112+
}
113+
114+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>cn.hserver</groupId>
8+
<artifactId>hserver-cloud</artifactId>
9+
<version>3.7.M1</version>
10+
</parent>
11+
12+
<artifactId>hserver-cloud-discovery</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>8</maven.compiler.source>
16+
<maven.compiler.target>8</maven.compiler.target>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>cn.hserver</groupId>
22+
<artifactId>hserver-cloud-common</artifactId>
23+
<version>3.7.M1</version>
24+
<scope>compile</scope>
25+
</dependency>
26+
</dependencies>
27+
28+
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package cn.hserver.cloud.discovery;
2+
3+
4+
import cn.hserver.cloud.common.ServerInstance;
5+
6+
import java.util.List;
7+
8+
/**
9+
* @author hxm
10+
*/
11+
public abstract class DiscoveryHandler {
12+
13+
/**
14+
* 查询服务
15+
*/
16+
public abstract List<ServerInstance> find(String group, String service);
17+
18+
/**
19+
* 选择服务实例
20+
*/
21+
public ServerInstance choose(){
22+
return null;
23+
}
24+
25+
/**
26+
* 订阅服务
27+
*/
28+
public abstract void subscribe(String group, String service,DiscoveryListener discoveryListener);
29+
30+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package cn.hserver.cloud.discovery;
2+
3+
import cn.hserver.cloud.common.ServerInstance;
4+
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
public interface DiscoveryListener {
9+
void onChanged(String group, Map<String, List<ServerInstance>> newInstances);
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package cn.hserver.cloud.discovery;
2+
3+
import cn.hserver.core.plugin.bean.PluginInfo;
4+
import cn.hserver.core.plugin.handler.PluginAdapter;
5+
6+
public class DiscoveryPlugin extends PluginAdapter {
7+
@Override
8+
public PluginInfo getPluginInfo() {
9+
return new PluginInfo.Builder()
10+
.name("服务发现")
11+
.description("提供服务发现能力,让你快速查询相关服务配置")
12+
.build();
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cn.hserver.cloud.discovery.DiscoveryPlugin

hserver-plugin/hserver-plugin-nacos/pom.xml renamed to hserver-cloud/hserver-cloud-impl/hserver-cloud-nacos/pom.xml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
<modelVersion>4.0.0</modelVersion>
66
<parent>
77
<groupId>cn.hserver</groupId>
8-
<artifactId>hserver-plugin</artifactId>
8+
<artifactId>hserver-cloud</artifactId>
99
<version>3.7.M1</version>
10+
<relativePath>../../pom.xml</relativePath>
1011
</parent>
1112

12-
<artifactId>hserver-plugin-nacos</artifactId>
13+
<artifactId>hserver-cloud-nacos</artifactId>
1314

1415
<properties>
1516
<maven.compiler.source>8</maven.compiler.source>
@@ -21,7 +22,7 @@
2122
<dependencies>
2223
<dependency>
2324
<groupId>cn.hserver</groupId>
24-
<artifactId>hserver</artifactId>
25+
<artifactId>hserver-core</artifactId>
2526
<scope>provided</scope>
2627
</dependency>
2728
<!--注册配置中心-->
@@ -34,6 +35,24 @@
3435
<groupId>cn.hserver</groupId>
3536
<artifactId>hserver-cloud</artifactId>
3637
</dependency>
38+
<dependency>
39+
<groupId>cn.hserver</groupId>
40+
<artifactId>hserver-cloud-common</artifactId>
41+
<version>3.7.M1</version>
42+
<scope>compile</scope>
43+
</dependency>
44+
<dependency>
45+
<groupId>cn.hserver</groupId>
46+
<artifactId>hserver-cloud-discovery</artifactId>
47+
<version>3.7.M1</version>
48+
<scope>compile</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>cn.hserver</groupId>
52+
<artifactId>hserver-cloud-register</artifactId>
53+
<version>3.7.M1</version>
54+
<scope>compile</scope>
55+
</dependency>
3756
</dependencies>
3857

39-
</project>
58+
</project>

0 commit comments

Comments
 (0)