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


Java RegistryConfig类代码示例

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


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

示例1: getCaller

import com.alibaba.dubbo.config.RegistryConfig; //导入依赖的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: init

import com.alibaba.dubbo.config.RegistryConfig; //导入依赖的package包/类
public void init() {
 //对标签中名字为application的进行解析,这里dubbo使用了统一的DubboBeanDefinitionParser进行解析。
    //DubboBeanDefinitionParser实现了BeanDefinitionParser接口,实现parse方法对标签进行解析。
    //将解析之后的标签变成Spring中的一个Bean对象。
    //application对应一个ApplicationConfig。
    //在执行完init方法之后,spring会得到所有的下面这个10个handler
 registerBeanDefinitionParser("application", new DubboBeanDefinitionParser(ApplicationConfig.class, true));
    registerBeanDefinitionParser("module", new DubboBeanDefinitionParser(ModuleConfig.class, true));
    registerBeanDefinitionParser("registry", new DubboBeanDefinitionParser(RegistryConfig.class, true));
    registerBeanDefinitionParser("monitor", new DubboBeanDefinitionParser(MonitorConfig.class, true));
    registerBeanDefinitionParser("provider", new DubboBeanDefinitionParser(ProviderConfig.class, true));
    registerBeanDefinitionParser("consumer", new DubboBeanDefinitionParser(ConsumerConfig.class, true));
    registerBeanDefinitionParser("protocol", new DubboBeanDefinitionParser(ProtocolConfig.class, true));
    registerBeanDefinitionParser("service", new DubboBeanDefinitionParser(ServiceBean.class, true));
    registerBeanDefinitionParser("reference", new DubboBeanDefinitionParser(ReferenceBean.class, false));
    registerBeanDefinitionParser("annotation", new DubboBeanDefinitionParser(AnnotationBean.class, true));
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:18,代码来源:DubboNamespaceHandler.java

示例3: testXmlOverrideProperties

import com.alibaba.dubbo.config.RegistryConfig; //导入依赖的package包/类
@Test
public void testXmlOverrideProperties() throws Exception {
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/xml-override-properties.xml");
    providerContext.start();
    try {
        ApplicationConfig application = (ApplicationConfig) providerContext.getBean("application");
        assertEquals("demo-provider", application.getName());
        assertEquals("world", application.getOwner());
        
        RegistryConfig registry = (RegistryConfig) providerContext.getBean("registry");
        assertEquals("N/A", registry.getAddress());
        
        ProtocolConfig dubbo = (ProtocolConfig) providerContext.getBean("dubbo");
        assertEquals(20813, dubbo.getPort().intValue());
        
    } finally {
        providerContext.stop();
        providerContext.close();
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:21,代码来源:ConfigTest.java

示例4: testSystemPropertyOverrideReferenceConfig

import com.alibaba.dubbo.config.RegistryConfig; //导入依赖的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", "");
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:24,代码来源:ConfigTest.java

示例5: testGenericServiceConfig

import com.alibaba.dubbo.config.RegistryConfig; //导入依赖的package包/类
@Test
public void testGenericServiceConfig() throws Exception {
    ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
    service.setApplication(new ApplicationConfig("test"));
    service.setRegistry(new RegistryConfig("mock://localhost"));
    service.setInterface(DemoService.class.getName());
    service.setGeneric(Constants.GENERIC_SERIALIZATION_BEAN);
    service.setRef(new GenericService(){

        public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
            return null;
        }
    });
    try {
        service.export();
        Collection<Registry> collection = MockRegistryFactory.getCachedRegistry();
        MockRegistry registry = (MockRegistry)collection.iterator().next();
        URL url = registry.getRegistered().get(0);
        Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
    } finally {
        MockRegistryFactory.cleanCachedRegistry();
        service.unexport();
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:25,代码来源:ConfigTest.java

示例6: getService

import com.alibaba.dubbo.config.RegistryConfig; //导入依赖的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;
}
 
开发者ID:thebeastshop,项目名称:litx,代码行数:19,代码来源:ServiceUtils.java

示例7: fillDubboService

import com.alibaba.dubbo.config.RegistryConfig; //导入依赖的package包/类
public ServiceConfig<GenericService> fillDubboService(MockService mockService, com.tony.test.mock.po.RegistryConfig registryConfig,
        com.tony.test.mock.po.ProtocolConfig protocolConfig, MockGenericService tmpMockservice) {
    ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
    service.setInterface(mockService.getServiceInterface());
    service.setRef(tmpMockservice); // 指向一个通用服务实现 
    RegistryConfig registry = createRegistry(registryConfig.getRegistryAddress(), registryConfig.getRegistryTimeout());
    service.setRegistry(registry);
    service.setProtocols(Lists.newArrayList(new ProtocolConfig(protocolConfig.getProtocolName(), protocolConfig.getProtocolPort())));
    if (!StringUtils.isBlank(mockService.getGroupName())) {
        service.setGroup(mockService.getGroupName());
    }
    service.setTimeout(mockService.getTimeout());
    service.setRetries(mockService.getRetries());
    service.setApplication(new ApplicationConfig(mockService.getApplicationName()));
    return service;
}
 
开发者ID:tonyruiyu,项目名称:dubbo-mock,代码行数:17,代码来源:DubboServiceConfig.java

示例8: main

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

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

    ProtocolConfig protocol = new ProtocolConfig();
    protocol.setName("dubbo");
    protocol.setPort(20882);

    ServiceConfig<DemoService> service = new ServiceConfig<>();
    service.setApplication(application);
    service.setRegistry(registry);
    service.setProtocol(protocol);
    service.setInterface(DemoService.class);
    service.setRef(new DemoServiceImpl2());
    service.setVersion("1.0.0");

    service.export();

    System.in.read(); // press any key to exit
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:24,代码来源:Provider.java

示例9: main

import com.alibaba.dubbo.config.RegistryConfig; //导入依赖的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

示例10: refer

import com.alibaba.dubbo.config.RegistryConfig; //导入依赖的package包/类
private DemoService refer(String url) {
    ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
    reference.setApplication(new ApplicationConfig("consumer"));
    reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    reference.setInterface(DemoService.class);
    reference.setUrl(url);
    return reference.get();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:9,代码来源:ConfigTest.java

示例11: testToString

import com.alibaba.dubbo.config.RegistryConfig; //导入依赖的package包/类
@Test
public void testToString() {
    ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
    reference.setApplication(new ApplicationConfig("consumer"));
    reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    reference.setInterface(DemoService.class);
    reference.setUrl("dubbo://127.0.0.1:20881");
    String str = reference.toString();
    assertTrue(str.startsWith("<dubbo:reference "));
    assertTrue(str.contains(" url=\"dubbo://127.0.0.1:20881\" "));
    assertTrue(str.contains(" interface=\"com.alibaba.dubbo.config.spring.api.DemoService\" "));
    assertTrue(str.endsWith(" />"));
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:14,代码来源:ConfigTest.java

示例12: testDubboProtocolPortOverride

import com.alibaba.dubbo.config.RegistryConfig; //导入依赖的package包/类
@Test
public void testDubboProtocolPortOverride() throws Exception {
    String dubboPort = System.getProperty("dubbo.protocol.dubbo.port");
    int port = 55555;
    System.setProperty("dubbo.protocol.dubbo.port", String.valueOf(port));
    ServiceConfig<DemoService> service = null;
    try {
        ApplicationConfig application = new ApplicationConfig();
        application.setName("dubbo-protocol-port-override");

        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("N/A");

        ProtocolConfig protocol = new ProtocolConfig();

        service = new ServiceConfig<DemoService>();
        service.setInterface(DemoService.class);
        service.setRef(new DemoServiceImpl());
        service.setApplication(application);
        service.setRegistry(registry);
        service.setProtocol(protocol);
        service.export();

        Assert.assertEquals(port, service.getExportedUrls().get(0).getPort());
    } finally {
        if (StringUtils.isNotEmpty(dubboPort)) {
            System.setProperty("dubbo.protocol.dubbo.port", dubboPort);
        }
        if (service != null) {
            service.unexport();
        }
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:34,代码来源:ConfigTest.java

示例13: testProtocolRandomPort

import com.alibaba.dubbo.config.RegistryConfig; //导入依赖的package包/类
@Test
public void testProtocolRandomPort() throws Exception {
    ServiceConfig<DemoService> demoService = null;
    ServiceConfig<HelloService> helloService = null;

    ApplicationConfig application = new ApplicationConfig();
    application.setName("test-protocol-random-port");

    RegistryConfig registry = new RegistryConfig();
    registry.setAddress("N/A");

    ProtocolConfig protocol = new ProtocolConfig();
    protocol.setName("dubbo");
    protocol.setPort(-1);

    demoService = new ServiceConfig<DemoService>();
    demoService.setInterface(DemoService.class);
    demoService.setRef(new DemoServiceImpl());
    demoService.setApplication(application);
    demoService.setRegistry(registry);
    demoService.setProtocol(protocol);

    helloService = new ServiceConfig<HelloService>();
    helloService.setInterface(HelloService.class);
    helloService.setRef(new HelloServiceImpl());
    helloService.setApplication(application);
    helloService.setRegistry(registry);
    helloService.setProtocol(protocol);

    try {
        demoService.export();
        helloService.export();

        Assert.assertEquals(demoService.getExportedUrls().get(0).getPort(),
                            helloService.getExportedUrls().get(0).getPort());
    } finally {
        unexportService(demoService);
        unexportService(helloService);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:41,代码来源:ConfigTest.java

示例14: testReferGenericExport

import com.alibaba.dubbo.config.RegistryConfig; //导入依赖的package包/类
@Test
public void testReferGenericExport() throws Exception {
    ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export");
    RegistryConfig rc = new RegistryConfig();
    rc.setAddress(RegistryConfig.NO_AVAILABLE);

    ServiceConfig<GenericService> sc = new ServiceConfig<GenericService>();
    sc.setApplication(ac);
    sc.setRegistry(rc);
    sc.setInterface(DemoService.class.getName());
    sc.setRef(new GenericService() {

        public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
            return null;
        }
    });

    ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>();
    ref.setApplication(ac);
    ref.setRegistry(rc);
    ref.setInterface(DemoService.class.getName());

    try {
        sc.export();
        ref.get();
        Assert.fail();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        sc.unexport();
        ref.destroy();
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:34,代码来源:ConfigTest.java


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