Skip to content

Commit 5457a57

Browse files
committed
Also client
1 parent 24d2b75 commit 5457a57

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/channelfactory/NettyChannelFactory.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131
import io.grpc.netty.GrpcSslContexts;
3232
import io.grpc.netty.NettyChannelBuilder;
33+
import io.netty.channel.epoll.EpollDomainSocketChannel;
34+
import io.netty.channel.epoll.EpollEventLoopGroup;
35+
import io.netty.channel.unix.DomainSocketAddress;
3336
import io.netty.handler.ssl.SslContextBuilder;
3437
import net.devh.boot.grpc.client.config.GrpcChannelProperties;
3538
import net.devh.boot.grpc.client.config.GrpcChannelProperties.Security;
@@ -71,8 +74,15 @@ protected NettyChannelBuilder newChannelBuilder(final String name) {
7174
if (address == null) {
7275
address = URI.create(name);
7376
}
74-
return NettyChannelBuilder.forTarget(address.toString())
75-
.defaultLoadBalancingPolicy(properties.getDefaultLoadBalancingPolicy());
77+
NettyChannelBuilder builder;
78+
if (address.getScheme().equals(GrpcChannelProperties.DOMAIN_SOCKET_ADDRESS_SCHEME)) {
79+
builder = NettyChannelBuilder.forAddress(new DomainSocketAddress(address.getPath()))
80+
.channelType(EpollDomainSocketChannel.class)
81+
.eventLoopGroup(new EpollEventLoopGroup());
82+
} else {
83+
builder = NettyChannelBuilder.forTarget(address.toString());
84+
}
85+
return builder.defaultLoadBalancingPolicy(properties.getDefaultLoadBalancingPolicy());
7686
}
7787

7888
@Override

grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/channelfactory/ShadedNettyChannelFactory.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131
import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts;
3232
import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;
33+
import io.grpc.netty.shaded.io.netty.channel.epoll.EpollDomainSocketChannel;
34+
import io.grpc.netty.shaded.io.netty.channel.epoll.EpollEventLoopGroup;
35+
import io.grpc.netty.shaded.io.netty.channel.unix.DomainSocketAddress;
3336
import io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder;
3437
import net.devh.boot.grpc.client.config.GrpcChannelProperties;
3538
import net.devh.boot.grpc.client.config.GrpcChannelProperties.Security;
@@ -69,8 +72,15 @@ protected NettyChannelBuilder newChannelBuilder(final String name) {
6972
if (address == null) {
7073
address = URI.create(name);
7174
}
72-
return NettyChannelBuilder.forTarget(address.toString())
73-
.defaultLoadBalancingPolicy(properties.getDefaultLoadBalancingPolicy());
75+
NettyChannelBuilder builder;
76+
if (address.getScheme().equals(GrpcChannelProperties.DOMAIN_SOCKET_ADDRESS_SCHEME)) {
77+
builder = NettyChannelBuilder.forAddress(new DomainSocketAddress(address.getPath()))
78+
.channelType(EpollDomainSocketChannel.class)
79+
.eventLoopGroup(new EpollEventLoopGroup());
80+
} else {
81+
builder = NettyChannelBuilder.forTarget(address.toString());
82+
}
83+
return builder.defaultLoadBalancingPolicy(properties.getDefaultLoadBalancingPolicy());
7484
}
7585

7686
@Override

grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/config/GrpcChannelProperties.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
@EqualsAndHashCode
5454
public class GrpcChannelProperties {
5555

56+
/**
57+
* A constant that defines, the scheme of a Unix domain socket address.
58+
*/
59+
public static final String DOMAIN_SOCKET_ADDRESS_SCHEME = "unix";
60+
5661
// --------------------------------------------------
5762
// Target Address
5863
// --------------------------------------------------

0 commit comments

Comments
 (0)