Skip to content

Commit

Permalink
fixes #33 + docs +version upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Furer committed Feb 6, 2017
1 parent 73dc5b1 commit 5cb0870
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 40 deletions.
21 changes: 1 addition & 20 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public class GreeterService extends GreeterGrpc.GreeterImplBase{

To intercept the `io.grpc.ServerBuilder` instance used to build the `io.grpc.Server`, you can add bean that inherits from `org.lognet.springboot.grpc.GRpcServerBuilderConfigurer` to your context and override the `configure` method. +
By the time of invocation of `configure` method, all discovered services, including theirs interceptors, had been added to the passed builder. +
In your implementation of `configure` method, you can continue with passed instance of `ServerBuilder` by adding your configuration:
In your implementation of `configure` method, you can add your custom configuration:

[source,java]
----
Expand All @@ -145,26 +145,7 @@ public class MyGRpcServerBuilderConfigurer extends GRpcServerBuilderConfigurer()
}
----

or return completely new instance of `ServerBuilder` :

[source,java]
----
@Component
public class MyGRpcServerBuilderConfigurer extends GRpcServerBuilderConfigurer(){
@Override
public ServerBuilder<?> configure(ServerBuilder<?> serverBuilder){
return ServerBuilder.forPort(YOUR PORT)
.executor(YOUR EXECUTOR INSTANCE)
.compressorRegistry(YOUR COMPRESSION REGISTRY)
.decompressorRegistry(YOUR DECOMPRESSION REGISTRY)
.useTransportSecurity(YOUR TRANSPORT SECURITY SETTINGS);
}
};
}
----
[NOTE]
In this case you should also take care about adding the services to the fresh instance of `ServerBuilder`

== License

Expand Down
7 changes: 7 additions & 0 deletions ReleaseNotes.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
== Version 2.0.0
- gRPC version upgraded to 1.1.1
- Spring Boot version upgraded to 1.4.4
- *Breaking API change*: +
`void GRpcServerBuilderConfigurer::configure(ServerBuilder<?> serverBuilder)` methods now returns void and overriding of `ServerBuilder` is not supported +
to prevent potential confusion.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'idea'
buildscript {
ext {
springBootVersion = '1.4.2.RELEASE'
grpcVersion = '1.0.2'
springBootVersion = '1.4.4.RELEASE'
grpcVersion = '1.1.1'
}
repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=1.0.1-SNAPSHOT
version=2.0.0
group=org.lognet
description=Spring Boot starter for Google RPC.
gitHubUrl=https\://github.com/LogNet/grpc-spring-boot-starter
Expand Down
2 changes: 1 addition & 1 deletion grpc-spring-boot-starter-demo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apply plugin: 'com.google.protobuf'
apply plugin: 'spring-boot'
apply plugin: 'org.springframework.boot'

dependencies {
compile "io.grpc:grpc-stub:${grpcVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.0.2)",
value = "by gRPC proto compiler (version 1.1.1)",
comments = "Source: calculator.proto")
public class CalculatorGrpc {

Expand Down Expand Up @@ -61,7 +61,7 @@ public void calculate(io.grpc.examples.CalculatorOuterClass.CalculatorRequest re
asyncUnimplementedUnaryCall(METHOD_CALCULATE, responseObserver);
}

@java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
METHOD_CALCULATE,
Expand Down Expand Up @@ -193,9 +193,28 @@ public io.grpc.stub.StreamObserver<Req> invoke(
}
}

public static io.grpc.ServiceDescriptor getServiceDescriptor() {
return new io.grpc.ServiceDescriptor(SERVICE_NAME,
METHOD_CALCULATE);
private static final class CalculatorDescriptorSupplier implements io.grpc.protobuf.ProtoFileDescriptorSupplier {
@java.lang.Override
public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
return io.grpc.examples.CalculatorOuterClass.getDescriptor();
}
}

private static volatile io.grpc.ServiceDescriptor serviceDescriptor;

public static io.grpc.ServiceDescriptor getServiceDescriptor() {
io.grpc.ServiceDescriptor result = serviceDescriptor;
if (result == null) {
synchronized (CalculatorGrpc.class) {
result = serviceDescriptor;
if (result == null) {
serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
.setSchemaDescriptor(new CalculatorDescriptorSupplier())
.addMethod(METHOD_CALCULATE)
.build();
}
}
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* </pre>
*/
@javax.annotation.Generated(
value = "by gRPC proto compiler (version 1.0.2)",
value = "by gRPC proto compiler (version 1.1.1)",
comments = "Source: greeter.proto")
public class GreeterGrpc {

Expand Down Expand Up @@ -70,7 +70,7 @@ public void sayHello(io.grpc.examples.GreeterOuterClass.HelloRequest request,
asyncUnimplementedUnaryCall(METHOD_SAY_HELLO, responseObserver);
}

@java.lang.Override public io.grpc.ServerServiceDefinition bindService() {
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
METHOD_SAY_HELLO,
Expand Down Expand Up @@ -220,9 +220,28 @@ public io.grpc.stub.StreamObserver<Req> invoke(
}
}

public static io.grpc.ServiceDescriptor getServiceDescriptor() {
return new io.grpc.ServiceDescriptor(SERVICE_NAME,
METHOD_SAY_HELLO);
private static final class GreeterDescriptorSupplier implements io.grpc.protobuf.ProtoFileDescriptorSupplier {
@java.lang.Override
public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
return io.grpc.examples.GreeterOuterClass.getDescriptor();
}
}

private static volatile io.grpc.ServiceDescriptor serviceDescriptor;

public static io.grpc.ServiceDescriptor getServiceDescriptor() {
io.grpc.ServiceDescriptor result = serviceDescriptor;
if (result == null) {
synchronized (GreeterGrpc.class) {
result = serviceDescriptor;
if (result == null) {
serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
.setSchemaDescriptor(new GreeterDescriptorSupplier())
.addMethod(METHOD_SAY_HELLO)
.build();
}
}
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public ServerCall.Listener answer(InvocationOnMock invocation) throws Throwable
public GRpcServerBuilderConfigurer customGrpcServerBuilderConfigurer(){
return new GRpcServerBuilderConfigurer(){
@Override
public ServerBuilder<?> configure(ServerBuilder<?> serverBuilder){
return serverBuilder.executor(command -> {
public void configure(ServerBuilder<?> serverBuilder){
serverBuilder.executor(command -> {
System.out.println(CUSTOM_EXECUTOR_MESSAGE);
command.run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Created by 310242212 on 21-Dec-16.
*/
public class GRpcServerBuilderConfigurer {
public ServerBuilder<?> configure(ServerBuilder<?> serverBuilder){
return serverBuilder;
public void configure(ServerBuilder<?> serverBuilder){

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void run(String... args) throws Exception {

});


server = configurer.configure(serverBuilder).build().start();
configurer.configure(serverBuilder);
server = serverBuilder.build().start();
log.info("gRPC Server started, listening on port {}.", gRpcServerProperties.getPort());
startDaemonAwaitThread();

Expand Down

0 comments on commit 5cb0870

Please sign in to comment.