本文整理汇总了Java中com.alibaba.dubbo.config.ReferenceConfig.setRetries方法的典型用法代码示例。如果您正苦于以下问题:Java ReferenceConfig.setRetries方法的具体用法?Java ReferenceConfig.setRetries怎么用?Java ReferenceConfig.setRetries使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.config.ReferenceConfig
的用法示例。
在下文中一共展示了ReferenceConfig.setRetries方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSystemPropertyOverrideReferenceConfig
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
@Test
public void testSystemPropertyOverrideReferenceConfig() throws Exception {
System.setProperty("dubbo.reference.retries", "5");
try {
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
ProtocolConfig protocolConfig = new ProtocolConfig("injvm");
service.setProtocol(protocolConfig);
service.export();
ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
reference.setInterface(DemoService.class);
reference.setInjvm(true);
reference.setRetries(2);
reference.get();
assertEquals(Integer.valueOf(5), reference.getRetries());
} finally {
System.setProperty("dubbo.reference.retries", "");
}
}
示例2: getService
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
public static <S> S getService(Class<S> c){
ApplicationConfig application = new ApplicationConfig();
application.setName("beast-litx");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("zookeeper://114.55.174.189:2181");
registry.setGroup("dubbo-zhang");
ReferenceConfig<S> reference = new ReferenceConfig<S>();
reference.setApplication(application);
reference.setRegistry(registry);
reference.setInterface(c);
reference.setTimeout(30000);
reference.setRetries(0);
S service = reference.get();
return service;
}
示例3: connectRegistry
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
public void connectRegistry() {
Long s = System.currentTimeMillis();
ReferenceConfig<RegistryService> reference = new ReferenceConfig<RegistryService>();
reference.setApplication(application);
reference.setRegistries(registryList); // 多个注册中心可以用setRegistries()
reference.setInterface(RegistryService.class); // 弱类型接口名
reference.setRetries(0);
reference.setTimeout(5000);
RegistryService registryService = reference.get();
Long t = System.currentTimeMillis() - s;
logger.info("connectRegistry success ,spend time=" + t + "ms");
}
示例4: invoke
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
@Override
public void invoke(RpcContext rpcContext, RpcResult rpcResult) {
try {
String referenceCacheKey = new StringBuilder()
.append(rpcContext.getClassName()).append("-")
.append(rpcContext.getServiceVersion()).toString();
ReferenceConfig<GenericService> reference = REFERENCECONFIG_CACHE
.get(referenceCacheKey);
if (reference == null) {
// 获取泛化引用
reference = new ReferenceConfig<GenericService>();
}
reference.setApplication(application);
reference.setRegistries(registryList); // 多个注册中心可以用setRegistries()
reference.setGeneric(true); // 声明为泛化接口
reference.setInterface(rpcContext.getClassName()); // 弱类型接口名
reference.setVersion(rpcContext.getServiceVersion());
reference.setRetries(0);
Long s = System.currentTimeMillis();
GenericService genericService = reference.get(); // 用com.alibaba.dubbo.rpc.service.GenericService可以替代所有接口引用
Long t = System.currentTimeMillis() - s;
logger.info("reference.get() success ,spend time=" + t + "ms"+","+rpcContext);
if (genericService == null) {
rpcResult
.setWithRpcResultCodeEnum(RpcResultCodeEnum.SERVICE_BEAN_NOT_FOUND_ERROR);
} else {
// 缓存dubbo reference
REFERENCECONFIG_CACHE.put(referenceCacheKey, reference);
if (objectMapper == null) {
objectMapper = new ObjectMapper();
}
List<?> parameters = objectMapper.readValue(rpcContext
.getRpcRequest().getParameters(), ArrayList.class);
// 基本类型以及Date,List,Map等不需要转换,直接调用
Object result = genericService.$invoke(
rpcContext.getMethodName(), null, parameters.toArray());
rpcResult
.setWithRpcResultCodeEnum(RpcResultCodeEnum.SUCCESS);
rpcResult.setData(result);
}
} catch (Exception e) {
logger.error("{}", rpcContext);
logger.error("{}", e);
String messageString = e.getMessage();
if (messageString != null && messageString.contains("ConstraintViolation")) {
rpcResult.setWithRpcResultCodeEnum(RpcResultCodeEnum.VALIDATION_ERROR);
Map<String, String> vaidationResultMap = buildValidationResult(messageString);
rpcResult.setData(vaidationResultMap);
} else {
rpcResult.setWithRpcResultCodeEnum(RpcResultCodeEnum.METHOD_INVOKE_ERROR);
}
}
}