本文整理汇总了Java中org.apache.curator.x.discovery.ServiceDiscoveryBuilder.builder方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceDiscoveryBuilder.builder方法的具体用法?Java ServiceDiscoveryBuilder.builder怎么用?Java ServiceDiscoveryBuilder.builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.curator.x.discovery.ServiceDiscoveryBuilder
的用法示例。
在下文中一共展示了ServiceDiscoveryBuilder.builder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serviceDiscovery
import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入方法依赖的package包/类
@Bean(name = "rpc-register")
public ServiceDiscovery<RpcPayload> serviceDiscovery() throws Exception {
ServiceDiscoveryBuilder<RpcPayload> builder = ServiceDiscoveryBuilder
.builder(RpcPayload.class);
return builder.client(this.curatorFramework())
.basePath(env.getProperty("rpc.server.service.path"))
.serializer(this.serializer())
.thisInstance(this.serviceInstance()).build();
}
示例2: serverRunner
import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; //导入方法依赖的package包/类
/**
* 这个bean启动后会独占线程,导致其他的bean无法执行。所以必须保证这个bean在最后才能够执行。
* @return
* @throws Exception
*/
@Bean(initMethod = "start", destroyMethod = "stop")
public ServerRunner serverRunner()
throws Exception {
String ip = this.ip;
if (ip == null)
ip = new IpPortResolver().getIpV4Address();
String instanceId = this.ip + ":" + this.port;
CuratorFramework curatorFramework =CuratorFrameworkFactory.builder()
.connectString(this.connectString)
.sessionTimeoutMs(this.sessionTimeoutMs)
.connectionTimeoutMs(this.connectionTimeoutMs)
.retryPolicy(this.retryPolicy())
.aclProvider(this.aclProvider()).authorization(this.authInfo())
.build();
InstanceSerializer<RpcPayload> serializer = new JsonSerializer();
TServerTransport transport = new TServerSocket(this.port);
TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport);
args.transportFactory(new TTransportFactory());
args.protocolFactory(new TBinaryProtocol.Factory());
TProcessor processor= new TProtobufProcessor();
args.processor(processor);
args.executorService(new ThreadPoolExecutor(this.minTheads,
this.maxTheads, this.keepAliveTime, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>()));
TServer server = new TThreadPoolServer(args);
ServiceInstanceBuilder<RpcPayload> instanceBuilder = ServiceInstance
.builder();
instanceBuilder.name(this.serviceName)
.uriSpec(new UriSpec(this.uriSpec)).payload(this.payload())
.port(port).id(instanceId).address(ip);
ServiceDiscoveryBuilder<RpcPayload> discoveryBuilder = ServiceDiscoveryBuilder
.builder(RpcPayload.class);
discoveryBuilder.client(curatorFramework).basePath(zkBasePath)
.serializer(serializer).thisInstance(instanceBuilder.build())
.build();
return ServerRunner
.newBuilder()
.server(server)
.curatorFramework(curatorFramework)
.serviceDiscovery(discoveryBuilder.build())
.zookeeperDeferRegisterPeriod(this.zookeeperDeferRegisterPeriod)
.zookeeperUnregisterPeriod(this.zookeeperUnregisterPeriod).build();
}