Skip to content

Commit

Permalink
Merge pull request #46 from yidongnan/1.2.0
Browse files Browse the repository at this point in the history
RELEASE 1.2.0
  • Loading branch information
yidongnan authored Jun 30, 2017
2 parents 9ec5932 + 4dfe97d commit d6ff3cb
Show file tree
Hide file tree
Showing 28 changed files with 214 additions and 80 deletions.
9 changes: 5 additions & 4 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ Java技术交流群:294712648 <a target="_blank" href="http://shang.qq.com/wpa
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-server-spring-boot-starter</artifactId>
<version>1.1.1.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
````

添加依赖如果使用的是Gradle

````
dependencies {
compile 'net.devh:grpc-server-spring-boot-starter:1.1.1.RELEASE'
compile 'net.devh:grpc-server-spring-boot-starter:1.2.0.RELEASE'
}
````

Expand Down Expand Up @@ -70,15 +70,15 @@ grpc.server.host=
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-client-spring-boot-starter</artifactId>
<version>1.1.1.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
````

添加依赖如果使用的是Gradle

````
dependencies {
compile 'net.devh:grpc-client-spring-boot-starter:1.1.1.RELEASE'
compile 'net.devh:grpc-client-spring-boot-starter:1.2.0.RELEASE'
}
````

Expand Down Expand Up @@ -109,6 +109,7 @@ grpc.client.(gRPC server name).port[0]=
| Project Version | gRPC-java Version |
| ---------------- | ------------------ |
| 1.2.0.RELEASE | 1.3.0 |
| 1.1.1.RELEASE | 1.2.0 |
| 1.0.1.RELEASE | 1.1.2 |
| 1.0.0.RELEASE | 1.0.3 |
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ To add a dependency using Maven, use the following:
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-server-spring-boot-starter</artifactId>
<version>1.1.1.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
````

To add a dependency using Gradle:

````
dependencies {
compile 'net.devh:grpc-server-spring-boot-starter:1.1.1.RELEASE'
compile 'net.devh:grpc-server-spring-boot-starter:1.2.0.RELEASE'
}
````

Expand All @@ -61,15 +61,15 @@ To add a dependency using Maven, use the following:
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-client-spring-boot-starter</artifactId>
<version>1.1.1.RELEASE</version>
<version>1.2.0.RELEASE</version>
</dependency>
````

To add a dependency using Gradle:

````
dependencies {
compile 'net.devh:grpc-client-spring-boot-starter:1.1.1.RELEASE'
compile 'net.devh:grpc-client-spring-boot-starter:1.2.0.RELEASE'
}
````

Expand Down Expand Up @@ -107,6 +107,7 @@ grpc.client.(gRPC server name).port[0]=
| Project Version | gRPC-java Version |
| ---------------- | ------------------ |
| 1.2.0.RELEASE | 1.3.0 |
| 1.1.1.RELEASE | 1.2.0 |
| 1.0.1.RELEASE | 1.1.2 |
| 1.0.0.RELEASE | 1.0.3 |
Expand Down
19 changes: 10 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
}
ext {
projectVersion = '1.1.1.RELEASE'
projectVersion = '1.2.0.RELEASE'

grpcVersion = '1.2.0'
grpcVersion = '1.3.0'
protobufVersion = '3.2.0'
protobufGradlePluginVersion = '0.8.0'

springBootVersion = '1.4.5.RELEASE'
springSleuthVersion = '1.1.3.RELEASE'
springCloudVersion = 'Camden.SR6'
springCloudConsulVersion = '1.1.3.RELEASE'
springCloudEurekaVersion = '1.2.6.RELEASE'
springBootVersion = '1.5.2.RELEASE'
springSleuthVersion = '1.2.0.RELEASE'
springCloudVersion = 'Dalston.RELEASE'
springCloudConsulVersion = '1.2.0.RELEASE'
springCloudEurekaVersion = '1.3.0.RELEASE'
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:0.6.1.RELEASE"
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}

Expand All @@ -34,8 +35,8 @@ allprojects {
apply plugin: "io.spring.dependency-management"

compileJava {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
options.encoding = 'UTF-8'
}

Expand Down
10 changes: 8 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ visit http://localhost:8080/ can see result.
./gradlew :example:cloud-eureka-server:bootRun
````
2. In a different terminal window run:
2. Try the cloud-zipkin-server example first run:
````
./gradlew :example:cloud-grpc-server:bootRun
./gradlew :example:cloud-zipkin-server:bootRun
````
3. In a different terminal window run:
````
./gradlew :example:cloud-grpc-server:bootRun
````
4. In a different terminal window run:
````
./gradlew :example:cloud-grpc-client:bootRun
````
Expand Down
1 change: 1 addition & 0 deletions examples/cloud-grpc-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apply plugin: 'org.springframework.boot'
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-eureka')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.cloud:spring-cloud-starter-zipkin')
compile project(':grpc-client-spring-boot-starter') // replace to compile("net.devh:grpc-client-spring-boot-starter:${springBootGrpcVersion}")
compile project(':examples:grpc-lib')
}
Expand Down
3 changes: 3 additions & 0 deletions examples/cloud-grpc-client/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ server:
spring:
application:
name: cloud-grpc-client
sleuth:
sampler:
percentage: 1
eureka:
client:
register-with-eureka: true
Expand Down
1 change: 1 addition & 0 deletions examples/cloud-grpc-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apply plugin: 'org.springframework.boot'
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-eureka')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.cloud:spring-cloud-starter-zipkin')
compile project(':grpc-server-spring-boot-starter') // replace to compile("net.devh:grpc-server-spring-boot-starter:${springBootGrpcVersion}")
compile project(':examples:grpc-lib')
}
Expand Down
3 changes: 3 additions & 0 deletions examples/cloud-grpc-server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
spring:
application:
name: cloud-grpc-server
sleuth:
sampler:
percentage: 1
server:
port: 0
grpc:
Expand Down
18 changes: 18 additions & 0 deletions examples/cloud-zipkin-server/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apply plugin: 'org.springframework.boot'

dependencies {
compile('org.springframework.boot:spring-boot-starter')
compile('io.zipkin.java:zipkin-server')
compile('io.zipkin.java:zipkin-autoconfigure-ui')
}

buildscript {
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.devh.examples.zipkin;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import zipkin.server.EnableZipkinServer;

/**
* User: Michael
* Email: [email protected]
* Date: 17-5-14
*/
@SpringBootApplication
@EnableZipkinServer
public class ZipkinApplication {

public static void main(String[] args) {
SpringApplication.run(ZipkinApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
spring:
application:
name: cloud-zipkin-server
server:
port: 9411
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ grpc:
host:
- 127.0.0.1
port:
- 9898
- 9898
enableKeepAlive: true
keepAliveWithoutCalls: true
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.devh.springboot.autoconfigure.grpc.client;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -40,14 +40,19 @@ public Channel createChannel(String name) {
@Override
public Channel createChannel(String name, List<ClientInterceptor> interceptors) {
GrpcChannelProperties channelProperties = properties.getChannel(name);
Channel channel = NettyChannelBuilder.forTarget(name)
NettyChannelBuilder builder = NettyChannelBuilder.forTarget(name)
.loadBalancerFactory(loadBalancerFactory)
.nameResolverFactory(nameResolverFactory)
.usePlaintext(channelProperties.isPlaintext())
.enableKeepAlive(channelProperties.isEnableKeepAlive(), channelProperties.getKeepAliveDelay(), TimeUnit.SECONDS, channelProperties.getKeepAliveTimeout(), TimeUnit.SECONDS)
.build();
.usePlaintext(channelProperties.isPlaintext());
if (channelProperties.isEnableKeepAlive()) {
builder.keepAliveWithoutCalls(channelProperties.isKeepAliveWithoutCalls())
.keepAliveTime(channelProperties.getKeepAliveTime(), TimeUnit.SECONDS)
.keepAliveTimeout(channelProperties.getKeepAliveTimeout(), TimeUnit.SECONDS);
}
Channel channel = builder.build();

List<ClientInterceptor> globalInterceptorList = globalClientInterceptorRegistry.getClientInterceptors();
Set<ClientInterceptor> interceptorSet = new HashSet<>();
Set<ClientInterceptor> interceptorSet = Sets.newHashSet();
if (globalInterceptorList != null && !globalInterceptorList.isEmpty()) {
interceptorSet.addAll(globalInterceptorList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import javax.annotation.concurrent.GuardedBy;

import io.grpc.Attributes;
import io.grpc.EquivalentAddressGroup;
import io.grpc.NameResolver;
import io.grpc.ResolvedServerInfo;
import io.grpc.ResolvedServerInfoGroup;
import io.grpc.Status;
import io.grpc.internal.SharedResourceHolder;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -100,16 +99,15 @@ public void run() {
return;
}

List<ResolvedServerInfoGroup> resolvedServerInfoGroupList = Lists.newArrayList();
List<EquivalentAddressGroup> equivalentAddressGroups = Lists.newArrayList();
for (int i = 0; i < properties.getHost().size(); i++) {
String host = properties.getHost().get(i);
Integer port = properties.getPort().get(i);
log.info("Found gRPC server {} {}:{}", name, host, port);
ResolvedServerInfoGroup.Builder servers = ResolvedServerInfoGroup.builder();
ResolvedServerInfo resolvedServerInfo = new ResolvedServerInfo(new InetSocketAddress(host, port), Attributes.EMPTY);
resolvedServerInfoGroupList.add(servers.add(resolvedServerInfo).build());
EquivalentAddressGroup addressGroup = new EquivalentAddressGroup(new InetSocketAddress(host, port), Attributes.EMPTY);
equivalentAddressGroups.add(addressGroup);
}
savedListener.onUpdate(resolvedServerInfoGroupList, Attributes.EMPTY);
savedListener.onAddresses(equivalentAddressGroups, Attributes.EMPTY);
} finally {
synchronized (AddressChannelNameResolver.this) {
resolving = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.devh.springboot.autoconfigure.grpc.client;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import org.springframework.cloud.client.discovery.DiscoveryClient;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -42,14 +42,19 @@ public Channel createChannel(String name) {
@Override
public Channel createChannel(String name, List<ClientInterceptor> interceptors) {
GrpcChannelProperties channelProperties = properties.getChannel(name);
Channel channel = NettyChannelBuilder.forTarget(name)
NettyChannelBuilder builder = NettyChannelBuilder.forTarget(name)
.loadBalancerFactory(loadBalancerFactory)
.nameResolverFactory(new DiscoveryClientResolverFactory(client))
.usePlaintext(properties.getChannel(name).isPlaintext())
.enableKeepAlive(channelProperties.isEnableKeepAlive(), channelProperties.getKeepAliveDelay(), TimeUnit.SECONDS, channelProperties.getKeepAliveTimeout(), TimeUnit.SECONDS)
.build();
.usePlaintext(properties.getChannel(name).isPlaintext());
if (channelProperties.isEnableKeepAlive()) {
builder.keepAliveWithoutCalls(channelProperties.isKeepAliveWithoutCalls())
.keepAliveTime(channelProperties.getKeepAliveTime(), TimeUnit.SECONDS)
.keepAliveTimeout(channelProperties.getKeepAliveTimeout(), TimeUnit.SECONDS);
}
Channel channel = builder.build();

List<ClientInterceptor> globalInterceptorList = globalClientInterceptorRegistry.getClientInterceptors();
Set<ClientInterceptor> interceptorSet = new HashSet<>();
Set<ClientInterceptor> interceptorSet = Sets.newHashSet();
if (globalInterceptorList != null && !globalInterceptorList.isEmpty()) {
interceptorSet.addAll(globalInterceptorList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
import javax.annotation.concurrent.GuardedBy;

import io.grpc.Attributes;
import io.grpc.EquivalentAddressGroup;
import io.grpc.NameResolver;
import io.grpc.ResolvedServerInfo;
import io.grpc.ResolvedServerInfoGroup;
import io.grpc.Status;
import io.grpc.internal.LogExceptionRunnable;
import io.grpc.internal.SharedResourceHolder;
Expand Down Expand Up @@ -116,20 +115,19 @@ public void run() {
} else {
return;
}
List<ResolvedServerInfoGroup> resolvedServerInfoGroupList = Lists.newArrayList();
List<EquivalentAddressGroup> equivalentAddressGroups = Lists.newArrayList();
for (ServiceInstance serviceInstance : serviceInstanceList) {
ResolvedServerInfoGroup.Builder servers = ResolvedServerInfoGroup.builder();
Map<String, String> metadata = serviceInstance.getMetadata();
if (metadata.get("gRPC") != null) {
Integer port = Integer.valueOf(metadata.get("gRPC"));
log.info("Found gRPC server {} {}:{}", name, serviceInstance.getHost(), port);
ResolvedServerInfo resolvedServerInfo = new ResolvedServerInfo(new InetSocketAddress(serviceInstance.getHost(), port), Attributes.EMPTY);
resolvedServerInfoGroupList.add(servers.add(resolvedServerInfo).build());
EquivalentAddressGroup addressGroup = new EquivalentAddressGroup(new InetSocketAddress(serviceInstance.getHost(), port), Attributes.EMPTY);
equivalentAddressGroups.add(addressGroup);
} else {
log.error("Can not found gRPC server {}", name);
}
}
savedListener.onUpdate(resolvedServerInfoGroupList, Attributes.EMPTY);
savedListener.onAddresses(equivalentAddressGroups, Attributes.EMPTY);
} else {
savedListener.onError(Status.UNAVAILABLE.withCause(new RuntimeException("UNAVAILABLE: NameResolver returned an empty list")));
}
Expand Down
Loading

0 comments on commit d6ff3cb

Please sign in to comment.