提交 b03eeef0 编写于 作者: 檀越@新空间's avatar 檀越@新空间 🐭

fix:添加客户端

上级 9095a98b
<?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-demo</artifactId>
<groupId>org.kwan.shuyu</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>dubbo-api</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>zookeeper</artifactId>
<groupId>org.apache.zookeeper</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.kwan.shuyu.service;
/**
* 用户接口
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/5/18 11:21
*/
public interface UserService {
int getCount();//获取当前网站在线人数
}
...@@ -9,11 +9,17 @@ ...@@ -9,11 +9,17 @@
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>dubbo-common-api</artifactId> <artifactId>dubbo-client</artifactId>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
</properties> </properties>
<dependencies>
<dependency>
<groupId>org.kwan.shuyu</groupId>
<artifactId>dubbo-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project> </project>
\ No newline at end of file
package com.kwan.shuyu;
import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@EnableDubboConfiguration //开启dubbo配置
public class DubboClientApplication {
public static void main(String[] args) {
SpringApplication.run(DubboClientApplication.class, args);
}
}
package com.kwan.shuyu.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.kwan.shuyu.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class UserController {
@Reference(interfaceClass = UserService.class, version = "2.6.0", check = false)
private UserService userService;
@RequestMapping("/count")
@ResponseBody
public String getCount() {
int count = userService.getCount();
return "当前在线的人数为:" + count;
}
}
server:
port: 8083
#kwan:
# zookeeper:
# hostlist: 120.79.36.53:2181,120.79.36.53:2182,120.79.36.53:2183 #多个节点用逗号分隔
#
spring:
application:
name: dobbo-client
dubbo:
registry: zookeeper://120.79.36.53:2181
\ No newline at end of file
...@@ -8,9 +8,7 @@ ...@@ -8,9 +8,7 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>dubbo-server</artifactId> <artifactId>dubbo-server</artifactId>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
...@@ -18,9 +16,8 @@ ...@@ -18,9 +16,8 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.kwan.shuyu</groupId> <groupId>org.kwan.shuyu</groupId>
<artifactId>dubbo-common-api</artifactId> <artifactId>dubbo-api</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
package com.kwan.shuyu; package com.kwan.shuyu;
import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
@EnableDubboConfiguration //开启dubbo配置
public class DubboServerApplication { public class DubboServerApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(DubboServerApplication.class, args); SpringApplication.run(DubboServerApplication.class, args);
......
package com.kwan.shuyu.service.impl;
import com.alibaba.dubbo.config.annotation.Service;
import com.kwan.shuyu.service.UserService;
import org.springframework.stereotype.Component;
@Component
@Service(interfaceClass = UserService.class, version = "2.6.0", timeout = 15000)
public class UserServiceImpl implements UserService {
@Override
public int getCount() {
//调用数据持久层
return 1024;
}
}
server: server:
port: 8001 port: 8081
#kwan:
# zookeeper:
# hostlist: 120.79.36.53:2181,120.79.36.53:2182,120.79.36.53:2183 #多个节点用逗号分隔
#
spring: spring:
application: application:
name: dobbo-service name: dobbo-service
kwan: dubbo:
zookeeper: server: true
hostlist: 120.79.36.53:2181,120.79.36.53:2182,120.79.36.53:2183 #多个节点用逗号分隔 registry: zookeeper://120.79.36.53:2181
\ No newline at end of file \ No newline at end of file
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<modules> <modules>
<module>dubbo-common-api</module> <module>dubbo-api</module>
<module>dubbo-server</module> <module>dubbo-server</module>
<module>dubbo-client</module>
</modules> </modules>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册