-
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
26 changed files
with
750 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
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,45 @@ | ||
<?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>com.bruce.rpc</groupId> | ||
<artifactId>lightning-parent</artifactId> | ||
<version>1.0</version> | ||
</parent> | ||
|
||
<artifactId>lightning-rpc-example</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>pom</packaging> | ||
|
||
<name>lightning-rpc-example</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<modules> | ||
<module>rpc-provider</module> | ||
<module>rpc-consumer</module> | ||
<module>rpc-interface</module> | ||
</modules> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.bruce.rpc</groupId> | ||
<artifactId>lightning-rpc</artifactId> | ||
<version>1.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.bruce.rpc</groupId> | ||
<artifactId>rpc-interface</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
</dependencyManagement> | ||
|
||
</project> |
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,33 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
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,66 @@ | ||
<?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>com.bruce.rpc</groupId> | ||
<artifactId>lightning-rpc-example</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>rpc-consumer</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>rpc-consumer</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>com.bruce.rpc</groupId> | ||
<artifactId>lightning-rpc</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.bruce.rpc</groupId> | ||
<artifactId>rpc-interface</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</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> |
16 changes: 16 additions & 0 deletions
16
...le/rpc-consumer/src/main/java/com/lightning/rpc/example/LightningConsumerApplication.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,16 @@ | ||
package com.lightning.rpc.example; | ||
|
||
import com.bruce.lightning.rpc.spring.client.EnableNettyRpcClient; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@EnableNettyRpcClient(host = "127.0.0.1",port = 8008) | ||
@SpringBootApplication | ||
public class LightningConsumerApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(LightningConsumerApplication.class, args); | ||
|
||
|
||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...-consumer/src/main/java/com/lightning/rpc/example/config/LightningRpcClientBootstrap.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,34 @@ | ||
package com.lightning.rpc.example.config; | ||
|
||
import com.bruce.lightning.rpc.client.LightningClient; | ||
import org.springframework.beans.factory.DisposableBean; | ||
import org.springframework.boot.context.event.ApplicationReadyEvent; | ||
import org.springframework.context.ApplicationListener; | ||
|
||
//@Configuration | ||
public class LightningRpcClientBootstrap implements ApplicationListener<ApplicationReadyEvent>, DisposableBean { | ||
|
||
private LightningClient lightningClient; | ||
|
||
public LightningClient getNettyRpcClient() { | ||
return lightningClient; | ||
} | ||
|
||
@Override | ||
public void onApplicationEvent(ApplicationReadyEvent event) { | ||
lightningClient = new LightningClient(); | ||
try { | ||
lightningClient.startSync("127.0.0.1", 8088); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void destroy() throws Exception { | ||
if (lightningClient != null) { | ||
lightningClient.close(); | ||
} | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
.../rpc-consumer/src/main/java/com/lightning/rpc/example/consumer/RpcConsumerController.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 com.lightning.rpc.example.consumer; | ||
|
||
import com.bruce.lightning.rpc.spring.client.RpcReference; | ||
import com.lightning.api.UserService; | ||
import com.lightning.api.bean.User; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Collections; | ||
|
||
@RestController | ||
@RequestMapping("/consumer") | ||
public class RpcConsumerController { | ||
|
||
@RpcReference | ||
private UserService userService; | ||
|
||
@GetMapping("/test") | ||
public String test() { | ||
User user = new User(); | ||
user.setId(123); | ||
user.setName("bruce"); | ||
|
||
String s = userService.toString(); | ||
String s1 = userService.saveUsers(Collections.singletonList(user)); | ||
|
||
return s1; | ||
} | ||
|
||
@GetMapping("/test2") | ||
public User test2() { | ||
User user = new User(); | ||
user.setId(123); | ||
user.setName("bruce"); | ||
|
||
return userService.saveUser(user); | ||
} | ||
|
||
@GetMapping("/test3") | ||
public int test3() { | ||
User user = new User(); | ||
user.setId(123); | ||
user.setName("bruce"); | ||
return userService.updateUser(user, 18, "上海", true); | ||
} | ||
|
||
|
||
} |
1 change: 1 addition & 0 deletions
1
lightning-rpc-example/rpc-consumer/src/main/resources/application.properties
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 @@ | ||
|
29 changes: 29 additions & 0 deletions
29
...ing-rpc-example/rpc-consumer/src/test/java/com/lightning/rpc/example/ApplicationTest.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,29 @@ | ||
package com.lightning.rpc.example; | ||
|
||
|
||
import com.lightning.api.UserService; | ||
import com.lightning.api.bean.User; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest(classes = LightningConsumerApplication.class) | ||
public class ApplicationTest { | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
@Test | ||
public void test1(){ | ||
|
||
User user = new User(); | ||
userService.saveUser(user); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...rpc-example/rpc-consumer/src/test/java/com/lightning/rpc/example/LightningClientTest.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,55 @@ | ||
package com.lightning.rpc.example; | ||
|
||
import com.bruce.lightning.rpc.client.DefaultResponseFuture; | ||
import com.bruce.lightning.rpc.client.LightningClient; | ||
import com.bruce.lightning.rpc.common.RpcRequest; | ||
import com.bruce.lightning.rpc.common.RpcResponse; | ||
import com.bruce.lightning.rpc.util.JsonUtils; | ||
import com.lightning.api.UserService; | ||
import com.lightning.api.bean.User; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class LightningClientTest { | ||
|
||
@Test | ||
public void test1() { | ||
LightningClient client = new LightningClient(); | ||
client.startSync("127.0.0.1", 8008); | ||
|
||
RpcRequest rpcRequest = new RpcRequest(); | ||
rpcRequest.setId(1L); | ||
rpcRequest.setFullMethodName("com.bruce.use.service.UserService.saveUsers"); | ||
|
||
User user = new User(); | ||
user.setId(121); | ||
user.setName("hahaha 中文"); | ||
|
||
ArrayList<User> users = new ArrayList<>(); | ||
users.add(user); | ||
users.add(user); | ||
|
||
rpcRequest.setArgs(new Object[]{users}); | ||
|
||
DefaultResponseFuture responseFuture = client.send(rpcRequest); | ||
RpcResponse response = responseFuture.get(); | ||
|
||
System.out.println(JsonUtils.toJson(response)); | ||
} | ||
|
||
|
||
@Test | ||
public void test2() { | ||
LightningClient client = new LightningClient(); | ||
client.startSync("127.0.0.1", 8008); | ||
UserService userService = client.createProxy(UserService.class, 3000); | ||
|
||
User user = new User(); | ||
user.setName("bruce"); | ||
|
||
userService.saveUser(user); | ||
} | ||
|
||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...c-consumer/src/test/java/com/lightning/rpc/example/LightningConsumerApplicationTests.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 com.lightning.rpc.example; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class LightningConsumerApplicationTests { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
} |
Oops, something went wrong.