diff --git a/whatsmars-rpc/README.md b/whatsmars-rpc/README.md index 631d37fc..bbd25f2c 100644 --- a/whatsmars-rpc/README.md +++ b/whatsmars-rpc/README.md @@ -1,2 +1,6 @@ # RPC -Transport & Protocol & Serialization \ No newline at end of file +Transport & Protocol & Serialization + +- [《Netty权威指南》](http://e.jd.com/30186249.html) `e.jd.com` +- [开发者如何玩转 RocketMQ?附最全源码解读 【Remoting篇】](https://blog.csdn.net/javahongxi/article/details/86628470) +- https://github.com/javahongxi/grpc-spring-boot-starter \ No newline at end of file diff --git a/whatsmars-rpc/pom.xml b/whatsmars-rpc/pom.xml index 095dc22e..a6ac1e56 100644 --- a/whatsmars-rpc/pom.xml +++ b/whatsmars-rpc/pom.xml @@ -18,7 +18,6 @@ whatsmars-remoting whatsmars-serialization - whatsmars-rpc-grpc whatsmars-logging diff --git a/whatsmars-rpc/whatsmars-remoting/README.md b/whatsmars-rpc/whatsmars-remoting/README.md deleted file mode 100644 index 1de4acf7..00000000 --- a/whatsmars-rpc/whatsmars-remoting/README.md +++ /dev/null @@ -1,5 +0,0 @@ -Netty is an asynchronous event-driven network application framework -for rapid development of maintainable high performance protocol servers & clients. - -- [《Netty权威指南》](http://e.jd.com/30186249.html) `e.jd.com` -- [开发者如何玩转 RocketMQ?附最全源码解读 【Remoting篇】](https://blog.csdn.net/javahongxi/article/details/86628470) \ No newline at end of file diff --git a/whatsmars-rpc/whatsmars-rpc-grpc/README.md b/whatsmars-rpc/whatsmars-rpc-grpc/README.md deleted file mode 100644 index 7fb1483e..00000000 --- a/whatsmars-rpc/whatsmars-rpc-grpc/README.md +++ /dev/null @@ -1,3 +0,0 @@ -若mvn compile时发生protobuf相关错误,请先执行mvn clean - -https://github.com/javahongxi/grpc-spring-boot-starter \ No newline at end of file diff --git a/whatsmars-rpc/whatsmars-rpc-grpc/pom.xml b/whatsmars-rpc/whatsmars-rpc-grpc/pom.xml deleted file mode 100644 index 3d0aeaa1..00000000 --- a/whatsmars-rpc/whatsmars-rpc-grpc/pom.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - 4.0.0 - - - whatsmars-rpc - org.hongxi - Rocket.S4 - - - whatsmars-rpc-grpc - jar - ${project.artifactId} - Grpc demo - - - 1.15.1 - - - - - io.grpc - grpc-netty - ${grpc.version} - - - io.grpc - grpc-protobuf - ${grpc.version} - - - io.grpc - grpc-stub - ${grpc.version} - - - - - - - kr.motd.maven - os-maven-plugin - 1.5.0.Final - - - - - org.xolstice.maven.plugins - protobuf-maven-plugin - 0.5.0 - - com.google.protobuf:protoc:3.0.0:exe:${os.detected.classifier} - grpc-java - io.grpc:protoc-gen-grpc-java:1.0.0:exe:${os.detected.classifier} - - - - - compile - compile-custom - - - - - - - - - diff --git a/whatsmars-rpc/whatsmars-rpc-grpc/src/main/java/org/hongxi/whatsmars/rpc/grpc/client/HelloWorldClient.java b/whatsmars-rpc/whatsmars-rpc-grpc/src/main/java/org/hongxi/whatsmars/rpc/grpc/client/HelloWorldClient.java deleted file mode 100644 index 207d75ba..00000000 --- a/whatsmars-rpc/whatsmars-rpc-grpc/src/main/java/org/hongxi/whatsmars/rpc/grpc/client/HelloWorldClient.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.hongxi.whatsmars.rpc.grpc.client; - -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import org.hongxi.whatsmars.rpc.grpc.service.HelloServiceGrpc; -import org.hongxi.whatsmars.rpc.grpc.service.HelloRequest; -import org.hongxi.whatsmars.rpc.grpc.service.HelloResponse; - -import java.util.concurrent.TimeUnit; - -/** - * Created by shenhongxi on 2017/5/5. - */ -public class HelloWorldClient { - - private final ManagedChannel channel; - private final HelloServiceGrpc.HelloServiceBlockingStub blockingStub; - - public HelloWorldClient(String host,int port){ - channel = ManagedChannelBuilder.forAddress(host, port) - .usePlaintext(true) - .build(); - - blockingStub = HelloServiceGrpc.newBlockingStub(channel); - } - - public void shutdown() throws InterruptedException { - channel.shutdown().awaitTermination(5, TimeUnit.SECONDS); - } - - public void greet(String name){ - HelloRequest request = HelloRequest.newBuilder().setName(name).build(); - HelloResponse response = blockingStub.sayHello(request); - System.out.println(response.getMessage()); - } - - public static void main(String[] args) throws InterruptedException { - HelloWorldClient client = new HelloWorldClient("127.0.0.1", 50051); - for(int i = 0; i < 5; i++) { - client.greet("world:" + i); - } - client.shutdown(); - } -} diff --git a/whatsmars-rpc/whatsmars-rpc-grpc/src/main/java/org/hongxi/whatsmars/rpc/grpc/server/HelloWorldServer.java b/whatsmars-rpc/whatsmars-rpc-grpc/src/main/java/org/hongxi/whatsmars/rpc/grpc/server/HelloWorldServer.java deleted file mode 100644 index ace2794a..00000000 --- a/whatsmars-rpc/whatsmars-rpc-grpc/src/main/java/org/hongxi/whatsmars/rpc/grpc/server/HelloWorldServer.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.hongxi.whatsmars.rpc.grpc.server; - -import io.grpc.Server; -import io.grpc.ServerBuilder; -import io.grpc.stub.StreamObserver; -import org.hongxi.whatsmars.rpc.grpc.service.HelloServiceGrpc; -import org.hongxi.whatsmars.rpc.grpc.service.HelloRequest; -import org.hongxi.whatsmars.rpc.grpc.service.HelloResponse; - -import java.io.IOException; - -/** - * Created by shenhongxi on 2017/5/5. - */ -public class HelloWorldServer { - - private int port = 50051; - private Server server; - - private void start() throws IOException { - server = ServerBuilder.forPort(port) - .addService(new HelloServiceImpl()) - .build() - .start(); - - System.out.println("service start..."); - - Runtime.getRuntime().addShutdownHook(new Thread() { - - @Override - public void run() { - - System.err.println("*** shutting down gRPC server since JVM is shutting down"); - HelloWorldServer.this.stop(); - System.err.println("*** server shut down"); - } - }); - } - - private void stop() { - if (server != null) { - server.shutdown(); - } - } - - // block 一直到退出程序 - private void blockUntilShutdown() throws InterruptedException { - if (server != null) { - server.awaitTermination(); - } - } - - public static void main(String[] args) throws IOException, InterruptedException { - final HelloWorldServer server = new HelloWorldServer(); - server.start(); - server.blockUntilShutdown(); - } - - // 实现 定义一个实现服务接口的类 - private class HelloServiceImpl extends HelloServiceGrpc.HelloServiceImplBase { - - public void sayHello(HelloRequest req, StreamObserver responseObserver) { - System.out.println("service:" + req.getName()); - HelloResponse response = HelloResponse.newBuilder().setMessage(("Hello: " + req.getName())).build(); - responseObserver.onNext(response); - responseObserver.onCompleted(); - } - } -} diff --git a/whatsmars-rpc/whatsmars-rpc-grpc/src/main/proto/helloworld.proto b/whatsmars-rpc/whatsmars-rpc-grpc/src/main/proto/helloworld.proto deleted file mode 100644 index 6e47f595..00000000 --- a/whatsmars-rpc/whatsmars-rpc-grpc/src/main/proto/helloworld.proto +++ /dev/null @@ -1,24 +0,0 @@ -syntax = "proto3"; - -option java_multiple_files = true; -option java_package = "org.hongxi.whatsmars.rpc.grpc.service"; -option java_outer_classname = "HelloWorldProto"; -option objc_class_prefix = "HLW"; - -package helloworld; - -// The greeting service definition. -service HelloService { - // Sends a greeting - rpc sayHello (HelloRequest) returns (HelloResponse) {} -} - -// The request message containing the user's name. -message HelloRequest { - string name = 1; -} - -// The response message containing the greetings -message HelloResponse { - string message = 1; -} \ No newline at end of file