forked from JavaCourse00/JavaCourseCodes
-
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
Showing
16 changed files
with
453 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 |
---|---|---|
|
@@ -27,3 +27,5 @@ hs_err_pid* | |
classes/ | ||
target/ | ||
build/ | ||
|
||
.DS_Store |
Binary file not shown.
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,20 @@ | ||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.kimmking</groupId> | ||
<artifactId>dubbo-demo</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<!-- <relativePath/> <!– lookup parent from repository –>--> | ||
</parent> | ||
<groupId>io.kimmking</groupId> | ||
<artifactId>dubbo-demo-api</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>dubbo-demo-api</name> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
</project> |
40 changes: 40 additions & 0 deletions
40
07rpc/rpc02/dubbo-demo-api/src/main/java/io/kimmking/dubbo/demo/api/Order.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,40 @@ | ||
package io.kimmking.dubbo.demo.api; | ||
|
||
public class Order implements java.io.Serializable { | ||
|
||
private int id; | ||
|
||
private String name; | ||
|
||
private float amount; | ||
|
||
public Order(int id, String name, float amount) { | ||
this.id = id; | ||
this.name = name; | ||
this.amount = amount; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public float getAmount() { | ||
return amount; | ||
} | ||
|
||
public void setAmount(float amount) { | ||
this.amount = amount; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
07rpc/rpc02/dubbo-demo-api/src/main/java/io/kimmking/dubbo/demo/api/OrderService.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,7 @@ | ||
package io.kimmking.dubbo.demo.api; | ||
|
||
public interface OrderService { | ||
|
||
Order findOrderById(int id); | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
07rpc/rpc02/dubbo-demo-api/src/main/java/io/kimmking/dubbo/demo/api/User.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,30 @@ | ||
package io.kimmking.dubbo.demo.api; | ||
|
||
public class User implements java.io.Serializable { | ||
|
||
public User(){} | ||
|
||
public User(int id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
private int id; | ||
private String name; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
07rpc/rpc02/dubbo-demo-api/src/main/java/io/kimmking/dubbo/demo/api/UserService.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,7 @@ | ||
package io.kimmking.dubbo.demo.api; | ||
|
||
public interface UserService { | ||
|
||
User findById(int id); | ||
|
||
} |
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,64 @@ | ||
<?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>io.kimmking</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>dubbo-demo-consumer</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.kimmking</groupId> | ||
<artifactId>dubbo-demo-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<!-- <dependency>--> | ||
<!-- <groupId>org.springframework.boot</groupId>--> | ||
<!-- <artifactId>spring-boot-starter-web</artifactId>--> | ||
<!-- </dependency>--> | ||
|
||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-spring-boot-starter</artifactId> | ||
<version>2.7.8</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.junit.vintage</groupId> | ||
<artifactId>junit-vintage-engine</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
49 changes: 49 additions & 0 deletions
49
...o-demo-consumer/src/main/java/io/kimmking/dubbo/demo/consumer/DubboClientApplication.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,49 @@ | ||
package io.kimmking.dubbo.demo.consumer; | ||
|
||
import io.kimmking.dubbo.demo.api.Order; | ||
import io.kimmking.dubbo.demo.api.OrderService; | ||
import io.kimmking.dubbo.demo.api.User; | ||
import io.kimmking.dubbo.demo.api.UserService; | ||
import org.apache.dubbo.config.annotation.DubboReference; | ||
import org.springframework.boot.ApplicationRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@SpringBootApplication | ||
public class DubboClientApplication { | ||
|
||
@DubboReference(version = "1.0.0", url = "dubbo://127.0.0.1:12345") | ||
private UserService userService; | ||
|
||
@DubboReference(version = "1.0.0", url = "dubbo://127.0.0.1:12345") | ||
private OrderService orderService; | ||
|
||
public static void main(String[] args) { | ||
|
||
SpringApplication.run(DubboClientApplication.class).close(); | ||
|
||
// UserService service = new xxx(); | ||
// service.findById | ||
|
||
// UserService userService = Rpcfx.create(UserService.class, "http://localhost:8080/"); | ||
// User user = userService.findById(1); | ||
// System.out.println("find user id=1 from server: " + user.getName()); | ||
// | ||
// OrderService orderService = Rpcfx.create(OrderService.class, "http://localhost:8080/"); | ||
// Order order = orderService.findOrderById(1992129); | ||
// System.out.println(String.format("find order name=%s, amount=%f",order.getName(),order.getAmount())); | ||
|
||
} | ||
|
||
@Bean | ||
public ApplicationRunner runner() { | ||
return args -> { | ||
User user = userService.findById(1); | ||
System.out.println("find user id=1 from server: " + user.getName()); | ||
Order order = orderService.findOrderById(1992129); | ||
System.out.println(String.format("find order name=%s, amount=%f",order.getName(),order.getAmount())); | ||
}; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
07rpc/rpc02/dubbo-demo-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,14 @@ | ||
|
||
spring: | ||
application: | ||
name: dubbo-demo-consumer | ||
main: | ||
allow-bean-definition-overriding: true | ||
web-application-type: none | ||
dubbo: | ||
scan: | ||
base-packages: io.kimmking.dubbo.demo.consumer | ||
registry: | ||
address: zookeeper://localhost:2181 | ||
metadata-report: | ||
address: zookeeper://localhost:2181 |
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,64 @@ | ||
<?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>io.kimmking</groupId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>dubbo-demo-provider</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>8</maven.compiler.source> | ||
<maven.compiler.target>8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.kimmking</groupId> | ||
<artifactId>dubbo-demo-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-spring-boot-starter</artifactId> | ||
<version>2.7.7</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.junit.vintage</groupId> | ||
<artifactId>junit-vintage-engine</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
...o-demo-provider/src/main/java/io/kimmking/dubbo/demo/provider/DubboServerApplication.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 io.kimmking.dubbo.demo.provider; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class DubboServerApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(DubboServerApplication.class, args); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...2/dubbo-demo-provider/src/main/java/io/kimmking/dubbo/demo/provider/OrderServiceImpl.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,15 @@ | ||
package io.kimmking.dubbo.demo.provider; | ||
|
||
import io.kimmking.dubbo.demo.api.Order; | ||
import io.kimmking.dubbo.demo.api.OrderService; | ||
import org.apache.dubbo.config.annotation.DubboService; | ||
|
||
|
||
@DubboService(version = "1.0.0") | ||
public class OrderServiceImpl implements OrderService { | ||
|
||
@Override | ||
public Order findOrderById(int id) { | ||
return new Order(id, "Cuijing" + System.currentTimeMillis(), 9.9f); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...02/dubbo-demo-provider/src/main/java/io/kimmking/dubbo/demo/provider/UserServiceImpl.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,14 @@ | ||
package io.kimmking.dubbo.demo.provider; | ||
|
||
import io.kimmking.dubbo.demo.api.User; | ||
import io.kimmking.dubbo.demo.api.UserService; | ||
import org.apache.dubbo.config.annotation.DubboService; | ||
|
||
@DubboService(version = "1.0.0") | ||
public class UserServiceImpl implements UserService { | ||
|
||
@Override | ||
public User findById(int id) { | ||
return new User(id, "KK" + System.currentTimeMillis()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
07rpc/rpc02/dubbo-demo-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,16 @@ | ||
server: | ||
port: 8088 | ||
|
||
spring: | ||
application: | ||
name: dubbo-demo-provider | ||
dubbo: | ||
scan: | ||
base-packages: io.kimmking.dubbo.demo.provider | ||
protocol: | ||
name: dubbo | ||
port: 12345 | ||
registry: | ||
address: zookeeper://localhost:2181 | ||
metadata-report: | ||
address: zookeeper://localhost:2181 |
Oops, something went wrong.