Skip to content

Commit 7fc6668

Browse files
committed
update dubbo demo
1 parent ef939af commit 7fc6668

File tree

16 files changed

+453
-0
lines changed

16 files changed

+453
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ hs_err_pid*
2727
classes/
2828
target/
2929
build/
30+
31+
.DS_Store

07rpc/rpc01/.DS_Store

-8 KB
Binary file not shown.

07rpc/rpc02/dubbo-demo-api/pom.xml

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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>io.kimmking</groupId>
7+
<artifactId>dubbo-demo</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<!-- <relativePath/> &lt;!&ndash; lookup parent from repository &ndash;&gt;-->
10+
</parent>
11+
<groupId>io.kimmking</groupId>
12+
<artifactId>dubbo-demo-api</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>dubbo-demo-api</name>
15+
16+
<properties>
17+
<java.version>1.8</java.version>
18+
</properties>
19+
20+
</project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.kimmking.dubbo.demo.api;
2+
3+
public class Order implements java.io.Serializable {
4+
5+
private int id;
6+
7+
private String name;
8+
9+
private float amount;
10+
11+
public Order(int id, String name, float amount) {
12+
this.id = id;
13+
this.name = name;
14+
this.amount = amount;
15+
}
16+
17+
public int getId() {
18+
return id;
19+
}
20+
21+
public void setId(int id) {
22+
this.id = id;
23+
}
24+
25+
public String getName() {
26+
return name;
27+
}
28+
29+
public void setName(String name) {
30+
this.name = name;
31+
}
32+
33+
public float getAmount() {
34+
return amount;
35+
}
36+
37+
public void setAmount(float amount) {
38+
this.amount = amount;
39+
}
40+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.kimmking.dubbo.demo.api;
2+
3+
public interface OrderService {
4+
5+
Order findOrderById(int id);
6+
7+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.kimmking.dubbo.demo.api;
2+
3+
public class User implements java.io.Serializable {
4+
5+
public User(){}
6+
7+
public User(int id, String name) {
8+
this.id = id;
9+
this.name = name;
10+
}
11+
12+
private int id;
13+
private String name;
14+
15+
public int getId() {
16+
return id;
17+
}
18+
19+
public void setId(int id) {
20+
this.id = id;
21+
}
22+
23+
public String getName() {
24+
return name;
25+
}
26+
27+
public void setName(String name) {
28+
this.name = name;
29+
}
30+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.kimmking.dubbo.demo.api;
2+
3+
public interface UserService {
4+
5+
User findById(int id);
6+
7+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
<parent>
6+
<artifactId>dubbo-demo</artifactId>
7+
<groupId>io.kimmking</groupId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>dubbo-demo-consumer</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>8</maven.compiler.source>
16+
<maven.compiler.target>8</maven.compiler.target>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>io.kimmking</groupId>
22+
<artifactId>dubbo-demo-api</artifactId>
23+
<version>${project.version}</version>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter</artifactId>
29+
</dependency>
30+
31+
<!-- <dependency>-->
32+
<!-- <groupId>org.springframework.boot</groupId>-->
33+
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
34+
<!-- </dependency>-->
35+
36+
<dependency>
37+
<groupId>org.apache.dubbo</groupId>
38+
<artifactId>dubbo-spring-boot-starter</artifactId>
39+
<version>2.7.8</version>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-test</artifactId>
45+
<scope>test</scope>
46+
<exclusions>
47+
<exclusion>
48+
<groupId>org.junit.vintage</groupId>
49+
<artifactId>junit-vintage-engine</artifactId>
50+
</exclusion>
51+
</exclusions>
52+
</dependency>
53+
</dependencies>
54+
55+
<build>
56+
<plugins>
57+
<plugin>
58+
<groupId>org.springframework.boot</groupId>
59+
<artifactId>spring-boot-maven-plugin</artifactId>
60+
</plugin>
61+
</plugins>
62+
</build>
63+
64+
</project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package io.kimmking.dubbo.demo.consumer;
2+
3+
import io.kimmking.dubbo.demo.api.Order;
4+
import io.kimmking.dubbo.demo.api.OrderService;
5+
import io.kimmking.dubbo.demo.api.User;
6+
import io.kimmking.dubbo.demo.api.UserService;
7+
import org.apache.dubbo.config.annotation.DubboReference;
8+
import org.springframework.boot.ApplicationRunner;
9+
import org.springframework.boot.SpringApplication;
10+
import org.springframework.boot.autoconfigure.SpringBootApplication;
11+
import org.springframework.context.annotation.Bean;
12+
13+
@SpringBootApplication
14+
public class DubboClientApplication {
15+
16+
@DubboReference(version = "1.0.0", url = "dubbo://127.0.0.1:12345")
17+
private UserService userService;
18+
19+
@DubboReference(version = "1.0.0", url = "dubbo://127.0.0.1:12345")
20+
private OrderService orderService;
21+
22+
public static void main(String[] args) {
23+
24+
SpringApplication.run(DubboClientApplication.class).close();
25+
26+
// UserService service = new xxx();
27+
// service.findById
28+
29+
// UserService userService = Rpcfx.create(UserService.class, "http://localhost:8080/");
30+
// User user = userService.findById(1);
31+
// System.out.println("find user id=1 from server: " + user.getName());
32+
//
33+
// OrderService orderService = Rpcfx.create(OrderService.class, "http://localhost:8080/");
34+
// Order order = orderService.findOrderById(1992129);
35+
// System.out.println(String.format("find order name=%s, amount=%f",order.getName(),order.getAmount()));
36+
37+
}
38+
39+
@Bean
40+
public ApplicationRunner runner() {
41+
return args -> {
42+
User user = userService.findById(1);
43+
System.out.println("find user id=1 from server: " + user.getName());
44+
Order order = orderService.findOrderById(1992129);
45+
System.out.println(String.format("find order name=%s, amount=%f",order.getName(),order.getAmount()));
46+
};
47+
}
48+
49+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
spring:
3+
application:
4+
name: dubbo-demo-consumer
5+
main:
6+
allow-bean-definition-overriding: true
7+
web-application-type: none
8+
dubbo:
9+
scan:
10+
base-packages: io.kimmking.dubbo.demo.consumer
11+
registry:
12+
address: zookeeper://localhost:2181
13+
metadata-report:
14+
address: zookeeper://localhost:2181

0 commit comments

Comments
 (0)