Skip to content

Commit

Permalink
update dubbo demo
Browse files Browse the repository at this point in the history
  • Loading branch information
kimmking committed Dec 12, 2020
1 parent ef939af commit 7fc6668
Show file tree
Hide file tree
Showing 16 changed files with 453 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ hs_err_pid*
classes/
target/
build/

.DS_Store
Binary file removed 07rpc/rpc01/.DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions 07rpc/rpc02/dubbo-demo-api/pom.xml
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/> &lt;!&ndash; lookup parent from repository &ndash;&gt;-->
</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>
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;
}
}
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);

}
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;
}
}
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);

}
64 changes: 64 additions & 0 deletions 07rpc/rpc02/dubbo-demo-consumer/pom.xml
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>
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 07rpc/rpc02/dubbo-demo-consumer/src/main/resources/application.yml
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
64 changes: 64 additions & 0 deletions 07rpc/rpc02/dubbo-demo-provider/pom.xml
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>
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);
}

}
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);
}
}
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 07rpc/rpc02/dubbo-demo-provider/src/main/resources/application.yml
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
Loading

0 comments on commit 7fc6668

Please sign in to comment.