Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
hs_err_pid*
.gradle
gradle/
.idea
.idea
build/
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}

protobuf {
/*protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.4.0'
}
Expand All @@ -55,7 +55,7 @@ protobuf {
grpc {}
}
}
}
}*/

//// Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code.
sourceSets {
Expand Down
48 changes: 48 additions & 0 deletions client/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
plugins {
id 'java'
id "com.google.protobuf"
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
mavenCentral()
}

dependencies {
protobuf project(':proto')
compile "com.google.api.grpc:proto-google-common-protos:0.1.9"
compile "io.grpc:grpc-netty:${grpcVersion}"
compile "io.grpc:grpc-protobuf:${grpcVersion}"
compile "io.grpc:grpc-stub:${grpcVersion}"
compile "io.netty:netty-tcnative-boringssl-static:${nettyTcNativeVersion}"
compile "org.bouncycastle:bcmail-jdk15:1.46"
testCompile group: 'junit', name: 'junit', version: '4.12'
}

protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.4.0'
}
plugins {
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
}
}

//// Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code.
sourceSets {
main {
java {
srcDirs 'build/generated/source/proto/main/grpc'
srcDirs 'build/generated/source/proto/main/java'
}
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package com.grpc.sample.client;
package com.grpc.client;

import com.google.common.base.Stopwatch;
import com.grpc.sample.HelloRequest;
import com.grpc.sample.HelloResponse;
import com.grpc.sample.HelloServiceGrpc;
import com.grpc.sample.server.GRPCServer;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.NettyChannelBuilder;

import javax.net.ssl.SSLException;
import java.io.File;
import java.util.concurrent.TimeUnit;

public class GRPCClient {
public static void main(String[] args) throws SSLException {
Stopwatch watch = Stopwatch.createStarted();
File cert = new File(GRPCServer.class.getClassLoader().getResource("certs/cert.pem").getFile());
// File cert = new File(GRPCClient.class.getClassLoader().getResource("certs/cert.pem").getFile());
// ManagedChannel channel = NettyChannelBuilder.forAddress("localhost", 9002)
// .sslContext(GrpcSslContexts.forClient()
// .trustManager(cert).build())
// .build();

ManagedChannel channel = NettyChannelBuilder.forAddress("localhost", 9002)
.sslContext(GrpcSslContexts.forClient()
.trustManager(cert).build())
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 9002)
.usePlaintext(true)
.build();
HelloServiceGrpc.HelloServiceBlockingStub stub
= HelloServiceGrpc.newBlockingStub(channel);
Expand Down
23 changes: 23 additions & 0 deletions proto/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
mavenCentral()
}

dependencies {

testCompile group: 'junit', name: 'junit', version: '4.12'
}

sourceSets {
main {
resources {
srcDirs "src/main/proto"
}
}
}
49 changes: 49 additions & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
plugins {
id 'java'
id "com.google.protobuf"
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
mavenCentral()
}

dependencies {
protobuf project(':proto')
compile "com.google.api.grpc:proto-google-common-protos:0.1.9"
compile "io.grpc:grpc-netty:${grpcVersion}"
compile "io.grpc:grpc-protobuf:${grpcVersion}"
compile "io.grpc:grpc-stub:${grpcVersion}"
compile "io.netty:netty-tcnative-boringssl-static:${nettyTcNativeVersion}"
compile "org.bouncycastle:bcmail-jdk15:1.46"

testCompile group: 'junit', name: 'junit', version: '4.12'
}

protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.4.0'
}
plugins {
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
}
}

//// Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code.
sourceSets {
main {
java {
srcDirs 'build/generated/source/proto/main/grpc'
srcDirs 'build/generated/source/proto/main/java'
}
}
}
34 changes: 34 additions & 0 deletions server/src/main/java/com/grpc/server/GRPCServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.grpc.server;

import com.grpc.server.api.HelloServiceImpl;
import io.grpc.Server;
import io.grpc.ServerBuilder;

import java.io.File;
import java.io.IOException;

public class GRPCServer {

public static void main(String[] args) throws IOException, InterruptedException {

// File cert = new File(GRPCServer.class.getClassLoader().getResource("certs/cert.pem").getFile());
// File key = new File(GRPCServer.class.getClassLoader().getResource("certs/key.pem").getFile());

// System.out.println("Certificate: "+cert.getAbsolutePath());
// System.out.println("Key: "+key.getAbsolutePath());
Server server = ServerBuilder.forPort(9002)
// .useTransportSecurity(cert,key)
.addService(new HelloServiceImpl()).build();
System.out.println("Starting server..."+server);
server.start();
System.out.println("Server started...");
server.awaitTermination();







}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.grpc.sample.server.api;
package com.grpc.server.api;

import com.grpc.sample.HelloRequest;
import com.grpc.sample.HelloResponse;
Expand Down
3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
rootProject.name = 'GRPC'
include 'proto'
include 'client'
include 'server'

37 changes: 0 additions & 37 deletions src/main/java/com/grpc/sample/server/GRPCServer.java

This file was deleted.

17 changes: 0 additions & 17 deletions src/main/resources/certs/cert.pem

This file was deleted.

28 changes: 0 additions & 28 deletions src/main/resources/certs/key.pem

This file was deleted.