Hi All,
I'm trying to use name resolution and lb feature of gRPC for client side load balancing. However, it is not working properly.
Below is the construction of name resolution factory.
public Factory getNameResolverFactory() {
final Attributes NAME_RESOLVER_PARAMS = Attributes.newBuilder()
.set(GrpcNameResolutionLBConstant.RESOLUTION_ATTR, "yeah")
.build();
Attributes attrs = Attributes.newBuilder()
.set(GrpcNameResolutionLBConstant.ATTR_LB_ADDR_AUTHORITY, Constant.HOST + ":" + Constant.PORT)
.build();
final ArrayList EAG = new ArrayList();
SocketAddress addr = new InetSocketAddress(Constant.HOST, Constant.PORT);
EquivalentAddressGroup addrgrp = new EquivalentAddressGroup(addr, attrs);
EAG.add(addrgrp);
final NameResolver.Listener nrlistener = null;
Factory nameResolverFactory = new NameResolver.Factory() {
@Override
public NameResolver newNameResolver(URI targetUri, Attributes params) {
try {
targetUri = URI.create(Constant.HOST + ":" + Constant.PORT);
params = NAME_RESOLVER_PARAMS;
} catch (Exception e) {
logger.log(Level.SEVERE, "Error: " + e);
}
NameResolver nrslvr = new NameResolver() {
@Override
public String getServiceAuthority() {
return Constant.HOST + ":" + Constant.PORT;
}
@Override
public void start(NameResolver.Listener listener) {
listener = new NameResolver.Listener() {
public void onUpdate(List<ResolvedServerInfoGroup> servers, Attributes attributes) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void onAddresses(List<EquivalentAddressGroup> servers, Attributes attributes) {
servers = EAG;
attributes = NAME_RESOLVER_PARAMS;
}
public void onError(Status error) {
logger.log(Level.SEVERE, "onError called: " + error);
}
};
listener.onAddresses(EAG, NAME_RESOLVER_PARAMS);
}
@Override
public void shutdown() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
};
nrslvr.start(nrlistener);
return nrslvr;
}
@Override
public String getDefaultScheme() {
return "defaultscheme";
}
};
return nameResolverFactory;
}
Alongwith name resolution, using rrlb for load balancing.
RoundRobinLoadBalancerFactory.getInstance()
Things are working fine when I exclude nameResolverFactory.
Can someone help me?
P.S. Using NettyChannelBuilder.