当前位置: 首页>>代码示例>>Java>>正文


Java ReferenceConfig.setVersion方法代码示例

本文整理汇总了Java中com.alibaba.dubbo.config.ReferenceConfig.setVersion方法的典型用法代码示例。如果您正苦于以下问题:Java ReferenceConfig.setVersion方法的具体用法?Java ReferenceConfig.setVersion怎么用?Java ReferenceConfig.setVersion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.dubbo.config.ReferenceConfig的用法示例。


在下文中一共展示了ReferenceConfig.setVersion方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCaller

import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
private GenericService getCaller(String appId, String busCode,EasyTransRequest<?,?> request) {
	GenericService genericService = mapRef.get(getTargetKey(appId,busCode));
	if(genericService == null){
		
		List<Class<?>> typeArguments = ReflectUtil.getTypeArguments(EasyTransRequest.class, request.getClass());
		Class<?> executorCLass = typeArguments.get(1);
		RelativeInterface annotation = executorCLass.getAnnotation(RelativeInterface.class);
		Class<?> value = annotation.value();
		ReferenceConfig<GenericService> referenceConfig = new ReferenceConfig<GenericService>();
		referenceConfig.setInterface(value.getName()); // 弱类型接口名 
		referenceConfig.setVersion("1.0.0"); 
		referenceConfig.setGeneric(true); // 声明为泛化接口 
		referenceConfig.setApplication(new ApplicationConfig(applicationName));
		referenceConfig.setRegistry(new RegistryConfig(dubboZkUrl));
		referenceConfig.setGroup(appId + "-" + busCode);
		referenceConfig.setCheck(false);
		referenceConfig.setSticky(true);//设置粘滞连接以优化级联事务的级联提交性能
		genericService = referenceConfig.get();
		mapRef.put(getTargetKey(appId,busCode), genericService);
	}
	return genericService;
}
 
开发者ID:QNJR-GROUP,项目名称:EasyTransaction,代码行数:23,代码来源:DubboEasyTransRpcConsumerImpl.java

示例2: getProxy

import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
public Object getProxy(String interfaceClass) {
    Set<Entry<Class<?>, Object>> entrySet = interfaceMapProxy.entrySet();
    for (Entry<Class<?>, Object> entry : entrySet) {
        if (entry.getKey().getName().equals(interfaceClass)) { return entry.getValue(); }
    }

    for (ServiceBean<?> service : services) {
        if (interfaceClass.equals(service.getInterfaceClass().getName())) {
            ReferenceConfig<Object> reference = new ReferenceConfig<Object>();
            reference.setApplication(service.getApplication());
            reference.setRegistry(service.getRegistry());
            reference.setRegistries(service.getRegistries());
            reference.setInterface(service.getInterfaceClass());
            reference.setVersion(service.getVersion());
            interfaceMapProxy.put(service.getInterfaceClass(), reference.get());
            return reference.get();
        }
    }
    return null;
}
 
开发者ID:Sayi,项目名称:swagger-dubbo,代码行数:21,代码来源:ReferenceManager.java

示例3: main

import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
public static void main(String[] args) {
    ApplicationConfig application = new ApplicationConfig();
    application.setName("demo-consumer");

    RegistryConfig registry = new RegistryConfig();
    registry.setAddress("zookeeper://127.0.0.1:2181");

    ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
    reference.setApplication(application);
    reference.setRegistry(registry);
    reference.setInterface(DemoService.class);
    reference.setVersion("1.0.0");

    DemoService demoService = reference.get();
    System.out.println(demoService.sayHello("hongxi"));
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:17,代码来源:Consumer.java

示例4: getRemoteService

import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
/**
 * 从远程注册中心获取服务
 *
 * @param clazz   接口Class对象
 * @param version 服务版本
 * @param <T>     T
 * @return        对应服务
 */
private <T> T getRemoteService(Class<T> clazz, String... version) {
    // 引用远程服务
    ReferenceConfig<T> reference = new ReferenceConfig<>();
    reference.setApplication(application);
    reference.setRegistry(registry);
    if (version != null && version.length != 0) {
        reference.setVersion(version[0]);
    }
    reference.setTimeout(10000);
    reference.setInterface(clazz);
    return reference.get();
}
 
开发者ID:DreamYa0,项目名称:zeratul,代码行数:21,代码来源:DubboService.java

示例5: getServiceByUrl

import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
/**
 * 获取点对点直连的service
 * @param clazz   接口Class对象
 * @param url     URL地址
 * @param version 服务版本
 * @param <T>     T
 * @return        对象
 */
private  <T> T getServiceByUrl(Class<T> clazz, String url, String... version) {
    ReferenceConfig<T> reference = new ReferenceConfig<T>();
    reference.setApplication(application);
    reference.setUrl(url);
    reference.setInterface(clazz);
    reference.setTimeout(10000);
    if (version != null && version.length != 0) {
        reference.setVersion(version[0]);
    }
    return reference.get();
}
 
开发者ID:DreamYa0,项目名称:zeratul,代码行数:20,代码来源:DubboService.java

示例6: main

import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
/**
 * @param args
 * @throws InterruptedException
 */
public static void main(String[] args) throws InterruptedException {

    String hostname = "0.0.0.0";
    int port = 8889;
    SecurityDomain securityDomain = null;
    String rootResourcePath = "/";
    int ioWorkerCount = Runtime.getRuntime().availableProcessors() * 2;
    int executorThreadCount = 12;

    NettyJaxrsServer nettyJaxrsServer = new NettyJaxrsServer();

    nettyJaxrsServer.setHostname(hostname);
    nettyJaxrsServer.setPort(port);
    nettyJaxrsServer.setSecurityDomain(securityDomain);
    nettyJaxrsServer.setRootResourcePath(rootResourcePath);

    nettyJaxrsServer.setIoWorkerCount(ioWorkerCount);
    nettyJaxrsServer.setExecutorThreadCount(executorThreadCount);
    Map<ChannelOption, Object> channelOptions = new HashMap<ChannelOption, Object>();
    channelOptions.put(ChannelOption.CONNECT_TIMEOUT_MILLIS, 100);
    nettyJaxrsServer.setChannelOptions(channelOptions);
    nettyJaxrsServer.setChildChannelOptions(channelOptions);

    ResteasyDeployment deployment = nettyJaxrsServer.getDeployment();

    List<Object> resources = new ArrayList<>();

    // dubo 消费远程服务:当前应用配置
    ApplicationConfig dubboApp = new ApplicationConfig();
    dubboApp.setName("dubboAppClient");
    // 注册中心配置
    RegistryConfig registryConfig = new RegistryConfig();
    registryConfig.setAddress("127.0.0.1:2181");
    registryConfig.setProtocol("zookeeper");
    registryConfig.setClient("curator");
    registryConfig.setGroup("dubbo");

    ReferenceConfig<DemoService> demoServiceReferenceConfig1 = new ReferenceConfig<>();
    demoServiceReferenceConfig1.setApplication(dubboApp);
    demoServiceReferenceConfig1.setRegistry(registryConfig);
    demoServiceReferenceConfig1.setInterface(DemoService.class);
    demoServiceReferenceConfig1.setVersion("1.0");
    demoServiceReferenceConfig1.setCheck(false);
    DemoService demoService1 = demoServiceReferenceConfig1.get();

    ReferenceConfig<DemoService> demoServiceReferenceConfig2 = new ReferenceConfig<>();
    demoServiceReferenceConfig2.setApplication(dubboApp);
    demoServiceReferenceConfig2.setRegistry(registryConfig);
    demoServiceReferenceConfig2.setInterface(DemoService.class);
    demoServiceReferenceConfig2.setVersion("2.0");
    demoServiceReferenceConfig2.setCheck(false);

    DemoService demoService2 = demoServiceReferenceConfig2.get();
    deployment.setResources(resources);

    nettyJaxrsServer.start();

    // resteasy 暴露服务
    deployment.getProviderFactory().register(MyContainerRequestFilter.class);
    deployment.getRegistry().addSingletonResource(demoService1, "1.0");
    deployment.getRegistry().addSingletonResource(demoService2, "2.0");
    // TimeUnit.SECONDS.sleep(6);
    // nettyJaxrsServer.stop();
    // demoServiceReferenceConfig.destroy();

}
 
开发者ID:sdcuike,项目名称:book-reading,代码行数:71,代码来源:DubboDemoClient2Version.java

示例7: 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);
        }


    }

}
 
开发者ID:jessyZu,项目名称:jsongood,代码行数:62,代码来源:DubboGenericServiceInvoker.java


注:本文中的com.alibaba.dubbo.config.ReferenceConfig.setVersion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。