diff --git a/dubbo-api/pom.xml b/dubbo-api/pom.xml index 6daf7ee5838864466e97a1df7bab725dc107483d..3fb4fee2debd83562c24a79697774b6e6d56af71 100644 --- a/dubbo-api/pom.xml +++ b/dubbo-api/pom.xml @@ -8,45 +8,9 @@ 1.0-SNAPSHOT 4.0.0 - dubbo-api - 8 8 - - - - org.apache.curator - curator-framework - 2.8.0 - - - org.apache.curator - curator-recipes - 2.8.0 - - - com.101tec - zkclient - 0.10 - - - slf4j-log4j12 - org.slf4j - - - zookeeper - org.apache.zookeeper - - - - - com.alibaba.spring.boot - dubbo-spring-boot-starter - 2.0.0 - - - \ No newline at end of file diff --git a/dubbo-api/src/main/java/com/kwan/shuyu/config/ZookeeperConfig.java b/dubbo-api/src/main/java/com/kwan/shuyu/config/ZookeeperConfig.java deleted file mode 100644 index 703c67686875aa9a6c5eacdc9a7507ad6a6f5dc9..0000000000000000000000000000000000000000 --- a/dubbo-api/src/main/java/com/kwan/shuyu/config/ZookeeperConfig.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.kwan.shuyu.config; - - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; - -/** - * zookeeper的配置类 - * - * @author : qinyingjie - * @version : 2.2.0 - * @date : 2023/5/10 12:37 - */ -@Configuration -public class ZookeeperConfig { - - @Value("${kwan.zookeeper.hostlist}") - private String hostlist; - -} \ No newline at end of file diff --git a/dubbo-api/src/main/java/com/kwan/shuyu/enums/ResultConstant.java b/dubbo-api/src/main/java/com/kwan/shuyu/enums/ResultConstant.java new file mode 100644 index 0000000000000000000000000000000000000000..756d18e6d884a40efdc85b6c1304c014653ed768 --- /dev/null +++ b/dubbo-api/src/main/java/com/kwan/shuyu/enums/ResultConstant.java @@ -0,0 +1,43 @@ +package com.kwan.shuyu.enums; + +/** + * 结果集枚举 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/3/10 14:00 + */ +public enum ResultConstant { + /** + * 系统异常 + */ + ERROR("-1", "系统异常"), + /** + * ok + */ + SUCCESS("0", "ok"); + + private String code; + private String msg; + + private ResultConstant(String code, String msg) { + this.code = code; + this.msg = msg; + } + + public String getCode() { + return this.code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getMsg() { + return this.msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } +} diff --git a/dubbo-api/src/main/java/com/kwan/shuyu/pojo/Payload.java b/dubbo-api/src/main/java/com/kwan/shuyu/pojo/Payload.java new file mode 100644 index 0000000000000000000000000000000000000000..dec266f04c1f9ff5f5fb937cfbf260684852d488 --- /dev/null +++ b/dubbo-api/src/main/java/com/kwan/shuyu/pojo/Payload.java @@ -0,0 +1,61 @@ +package com.kwan.shuyu.pojo; + +import com.kwan.shuyu.enums.ResultConstant; + +import java.io.Serializable; + +/** + * 结果集 + * + * @author : qinyingjie + * @version : 2.2.0 + * @date : 2023/3/13 14:45 + */ +public class Payload implements Serializable { + private static final long serialVersionUID = -1549643581827130116L; + private T payload; + private String code; + private String msg; + + public Payload() { + this.code = ResultConstant.SUCCESS.getCode(); + this.msg = ResultConstant.SUCCESS.getMsg(); + } + + public Payload(T payload) { + this.code = ResultConstant.SUCCESS.getCode(); + this.msg = ResultConstant.SUCCESS.getMsg(); + this.payload = payload; + } + + public Payload(String code, String msg) { + this.code = ResultConstant.SUCCESS.getCode(); + this.msg = ResultConstant.SUCCESS.getMsg(); + this.code = code; + this.msg = msg; + } + + public Payload(T payload, String code, String msg) { + this.code = ResultConstant.SUCCESS.getCode(); + this.msg = ResultConstant.SUCCESS.getMsg(); + this.payload = payload; + this.code = code; + this.msg = msg; + } + + public String getCode() { + return this.code; + } + + public String getMsg() { + return this.msg; + } + + public T getPayload() { + return this.payload; + } + + public boolean success() { + return this.getCode().equals("0"); + } +} \ No newline at end of file diff --git a/dubbo-client/pom.xml b/dubbo-client/pom.xml index a3ce1ff52ea5c34cc0116d7cd2119dd0cec0bef9..9aaf5c34d238bb6baaa8474f43bbe69cfeebebec 100644 --- a/dubbo-client/pom.xml +++ b/dubbo-client/pom.xml @@ -21,5 +21,35 @@ dubbo-api 1.0-SNAPSHOT + + org.apache.curator + curator-framework + 5.2.1 + + + org.apache.curator + curator-recipes + 5.2.1 + + + org.apache.curator + curator-x-discovery + 5.2.1 + + + org.apache.dubbo + dubbo-spring-boot-starter + 3.0.7 + + + org.springframework.boot + spring-boot-starter + 2.0.6.RELEASE + + + org.springframework.boot + spring-boot-starter-web + 2.0.1.RELEASE + \ No newline at end of file diff --git a/dubbo-client/src/main/java/com/kwan/shuyu/DubboClientApplication.java b/dubbo-client/src/main/java/com/kwan/shuyu/DubboClientApplication.java index 896bb75396816e7fe9f0dceaf1e52f80a7a7ef8a..8f6c58ac972e8fa094bffa2a62826e621c88d1f5 100644 --- a/dubbo-client/src/main/java/com/kwan/shuyu/DubboClientApplication.java +++ b/dubbo-client/src/main/java/com/kwan/shuyu/DubboClientApplication.java @@ -1,11 +1,12 @@ package com.kwan.shuyu; -import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration; +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; + +@EnableDubbo @SpringBootApplication -@EnableDubboConfiguration //开启dubbo配置 public class DubboClientApplication { public static void main(String[] args) { SpringApplication.run(DubboClientApplication.class, args); diff --git a/dubbo-client/src/main/java/com/kwan/shuyu/controller/UserController.java b/dubbo-client/src/main/java/com/kwan/shuyu/controller/UserController.java index 2749e264dd9faf61b7c8a16dc88d981ff3c740a1..8e88b8ee1c009ead4931b2e1ced1cac50cc2c7c2 100644 --- a/dubbo-client/src/main/java/com/kwan/shuyu/controller/UserController.java +++ b/dubbo-client/src/main/java/com/kwan/shuyu/controller/UserController.java @@ -1,21 +1,21 @@ package com.kwan.shuyu.controller; -import com.alibaba.dubbo.config.annotation.Reference; +import com.kwan.shuyu.pojo.Payload; import com.kwan.shuyu.service.UserService; -import org.springframework.stereotype.Controller; +import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController +@RequestMapping("/user") public class UserController { - @Reference(interfaceClass = UserService.class, version = "2.6.0", check = false) + @DubboReference(interfaceClass = UserService.class, check = false) private UserService userService; @RequestMapping("/count") - @ResponseBody - public String getCount() { + public Payload getCount() { int count = userService.getCount(); - return "当前在线的人数为:" + count; + return new Payload("当前在线的人数为:" + count); } } diff --git a/dubbo-client/src/main/resources/application.yml b/dubbo-client/src/main/resources/application.yml index feeb701e7f3cf59ce71446723da288d43d5e5170..6b4af031d338f7c023e0dc8a2fc3b3ec4a072aa9 100644 --- a/dubbo-client/src/main/resources/application.yml +++ b/dubbo-client/src/main/resources/application.yml @@ -7,5 +7,16 @@ server: spring: application: name: dobbo-client - dubbo: - registry: zookeeper://120.79.36.53:2181 \ No newline at end of file + +dubbo: + protocol: + name: dubbo + port: 20881 + registry: + address: zookeeper://120.79.36.53:2181 + +management: + endpoints: + web: + exposure: + include: '*' diff --git a/dubbo-server/pom.xml b/dubbo-server/pom.xml index daec06b6d1af7251895f7b01ae7c0f91663b40be..60799cfd0d1418e8cda4dc0220bda73df2e6771b 100644 --- a/dubbo-server/pom.xml +++ b/dubbo-server/pom.xml @@ -19,5 +19,35 @@ dubbo-api 1.0-SNAPSHOT + + org.apache.curator + curator-framework + 5.2.1 + + + org.apache.curator + curator-recipes + 5.2.1 + + + org.apache.curator + curator-x-discovery + 5.2.1 + + + org.apache.dubbo + dubbo-spring-boot-starter + 3.0.7 + + + org.springframework.boot + spring-boot-starter + 2.0.6.RELEASE + + + org.springframework.boot + spring-boot-starter-web + 2.0.1.RELEASE + \ No newline at end of file diff --git a/dubbo-server/src/main/java/com/kwan/shuyu/DubboServerApplication.java b/dubbo-server/src/main/java/com/kwan/shuyu/DubboServerApplication.java index fd22251faeb919b46d926bafe1a7c08d67d4cd24..9da70bfdcab6a07b2c439fea8820992ef566c8a9 100644 --- a/dubbo-server/src/main/java/com/kwan/shuyu/DubboServerApplication.java +++ b/dubbo-server/src/main/java/com/kwan/shuyu/DubboServerApplication.java @@ -1,11 +1,12 @@ package com.kwan.shuyu; -import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +@EnableDubbo @SpringBootApplication -@EnableDubboConfiguration //开启dubbo配置 public class DubboServerApplication { public static void main(String[] args) { SpringApplication.run(DubboServerApplication.class, args); diff --git a/dubbo-server/src/main/java/com/kwan/shuyu/service/impl/UserServiceImpl.java b/dubbo-server/src/main/java/com/kwan/shuyu/service/impl/UserServiceImpl.java index dbfd4f87ba3e2e450827874f1b8f2bee2d9c98f8..3aab9fd422ceb69a15966ea294df5f53004e8ce6 100644 --- a/dubbo-server/src/main/java/com/kwan/shuyu/service/impl/UserServiceImpl.java +++ b/dubbo-server/src/main/java/com/kwan/shuyu/service/impl/UserServiceImpl.java @@ -1,11 +1,9 @@ package com.kwan.shuyu.service.impl; -import com.alibaba.dubbo.config.annotation.Service; import com.kwan.shuyu.service.UserService; -import org.springframework.stereotype.Component; +import org.apache.dubbo.config.annotation.DubboService; -@Component -@Service(interfaceClass = UserService.class, version = "2.6.0", timeout = 15000) +@DubboService(interfaceClass = UserService.class) public class UserServiceImpl implements UserService { @Override diff --git a/dubbo-server/src/main/resources/application.yml b/dubbo-server/src/main/resources/application.yml index 94f7f76f07b0923ebc4a543606a027b9ccf82385..daf51c0733a608deccc82e71d934c76d2530de8d 100644 --- a/dubbo-server/src/main/resources/application.yml +++ b/dubbo-server/src/main/resources/application.yml @@ -7,6 +7,14 @@ server: spring: application: name: dobbo-service - dubbo: - server: true - registry: zookeeper://120.79.36.53:2181 \ No newline at end of file + +dubbo: + registry: + address: 120.79.36.53:2181,120.79.36.53:2182,120.79.36.53:2183 + protocol: zookeeper + +management: + endpoints: + web: + exposure: + include: '*' diff --git a/pom.xml b/pom.xml index 4ebb7c6d15095fd87dc0674d90bb2d4117d7a270..155d8e7fefac9901c9f6af3425ec31b7c692d500 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,6 @@ 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"> 4.0.0 - org.kwan.shuyu dubbo-demo pom @@ -17,32 +16,4 @@ 8 8 - - - org.springframework.boot - spring-boot-starter-web - 2.0.1.RELEASE - - - org.projectlombok - lombok - 1.16.10 - - - org.apache.commons - commons-io - 1.3.2 - - - org.apache.commons - commons-lang3 - 3.1 - - - com.alibaba - fastjson - 1.2.83 - - - \ No newline at end of file