本文整理汇总了Java中com.alibaba.dubbo.config.RegistryConfig.setAddress方法的典型用法代码示例。如果您正苦于以下问题:Java RegistryConfig.setAddress方法的具体用法?Java RegistryConfig.setAddress怎么用?Java RegistryConfig.setAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.config.RegistryConfig
的用法示例。
在下文中一共展示了RegistryConfig.setAddress方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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"));
}
示例3: initRefConf
import com.alibaba.dubbo.config.RegistryConfig; //导入方法依赖的package包/类
private void initRefConf(){
appConfForConsumer = new ApplicationConfig();
appConfForReference = new ApplicationConfig();
regConfForConsumer = new RegistryConfig();
regConfForReference = new RegistryConfig();
methodConfForReference = new MethodConfig();
refConf = new ReferenceConfig<DemoService>();
consumerConf = new ConsumerConfig();
methodConfForReference.setName("sayName");
regConfForReference.setAddress("127.0.0.1:9090");
regConfForReference.setProtocol("mockregistry");
appConfForReference.setName("ConfigTests");
refConf.setInterface("com.alibaba.dubbo.config.api.DemoService");
refConf.setApplication(appConfForReference);
consumerConf.setApplication(appConfForConsumer);
refConf.setRegistry(regConfForReference);
consumerConf.setRegistry(regConfForConsumer);
refConf.setConsumer(consumerConf);
refConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForReference}));
refConf.setScope(Constants.SCOPE_REMOTE);
}
示例4: 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();
}
}
示例5: 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);
}
}
示例6: initServConf
import com.alibaba.dubbo.config.RegistryConfig; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
protected void initServConf() {
appConfForProvider = new ApplicationConfig();
appConfForService = new ApplicationConfig();
regConfForProvider = new RegistryConfig();
regConfForService = new RegistryConfig();
provConf = new ProviderConfig();
protoConfForProvider = new ProtocolConfig();
protoConfForService = new ProtocolConfig();
methodConfForService = new MethodConfig();
servConf = new ServiceConfig<DemoService>();
provConf.setApplication(appConfForProvider);
servConf.setApplication(appConfForService);
provConf.setRegistry(regConfForProvider);
servConf.setRegistry(regConfForService);
provConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForProvider}));
servConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForService}));
servConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForService}));
servConf.setProvider(provConf);
servConf.setRef(demoService);
servConf.setInterfaceClass(DemoService.class);
methodConfForService.setName("sayName");
regConfForService.setAddress("127.0.0.1:9090");
regConfForService.setProtocol("mockregistry");
appConfForService.setName("ConfigTests");
}
示例7: initDubbo
import com.alibaba.dubbo.config.RegistryConfig; //导入方法依赖的package包/类
private void initDubbo(String host) {
if (host == null || "".equals(host)) {
throw new RuntimeException("------------Zookeeper地址为空!------------");
}
application = new ApplicationConfig();
application.setName("zeratul_config");
// 连接注册中心配置
registry = new RegistryConfig();
registry.setAddress("zookeeper://" + host);
registry.setUsername("zeratul");
}
示例8: 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();
}
}
}
示例9: dubboRegistries
import com.alibaba.dubbo.config.RegistryConfig; //导入方法依赖的package包/类
@Bean
public List<RegistryConfig> dubboRegistries() {
List<RegistryConfig> registrConfigs = new ArrayList<RegistryConfig>();
String zkUrls = dubboProperty.getZkUrls();
if (StringUtils.isNotBlank(zkUrls)) {
String[] zkUrlsArr = zkUrls.split(",");
for (String zkUrl : zkUrlsArr) {
RegistryConfig registry = new RegistryConfig();
registry.setAddress(zkUrl);
registry.setProtocol("zookeeper");
registrConfigs.add(registry);
}
}
return registrConfigs;
}
示例10: testApiOverrideProperties
import com.alibaba.dubbo.config.RegistryConfig; //导入方法依赖的package包/类
@Test
public void testApiOverrideProperties() throws Exception {
ApplicationConfig application = new ApplicationConfig();
application.setName("api-override-properties");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("N/A");
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("dubbo");
protocol.setPort(13123);
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.setApplication(application);
service.setRegistry(registry);
service.setProtocol(protocol);
service.export();
try {
URL url = service.toUrls().get(0);
assertEquals("api-override-properties", url.getParameter("application"));
assertEquals("world", url.getParameter("owner"));
assertEquals(13123, url.getPort());
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:13123");
reference.get();
try {
url = reference.toUrls().get(0);
assertEquals("2000", url.getParameter("timeout"));
} finally {
reference.destroy();
}
} finally {
service.unexport();
}
}
示例11: testSystemPropertyOverrideApi
import com.alibaba.dubbo.config.RegistryConfig; //导入方法依赖的package包/类
@Test
public void testSystemPropertyOverrideApi() throws Exception {
System.setProperty("dubbo.application.name", "sysover");
System.setProperty("dubbo.application.owner", "sysowner");
System.setProperty("dubbo.registry.address", "N/A");
System.setProperty("dubbo.protocol.name", "dubbo");
System.setProperty("dubbo.protocol.port", "20834");
try {
ApplicationConfig application = new ApplicationConfig();
application.setName("aaa");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("127.0.0.1");
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("rmi");
protocol.setPort(1099);
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.setApplication(application);
service.setRegistry(registry);
service.setProtocol(protocol);
service.export();
try {
URL url = service.toUrls().get(0);
assertEquals("sysover", url.getParameter("application"));
assertEquals("sysowner", url.getParameter("owner"));
assertEquals("dubbo", url.getProtocol());
assertEquals(20834, url.getPort());
} finally {
service.unexport();
}
} finally {
System.setProperty("dubbo.application.name", "");
System.setProperty("dubbo.application.owner", "");
System.setProperty("dubbo.registry.address", "");
System.setProperty("dubbo.protocol.name", "");
System.setProperty("dubbo.protocol.port", "");
}
}
示例12: testSystemPropertyOverrideProperties
import com.alibaba.dubbo.config.RegistryConfig; //导入方法依赖的package包/类
@Test
public void testSystemPropertyOverrideProperties() throws Exception {
String portString = System.getProperty( "dubbo.protocol.port");
System.clearProperty("dubbo.protocol.port");
try {
int port = 1234;
System.setProperty("dubbo.protocol.port", String.valueOf(port));
ApplicationConfig application = new ApplicationConfig();
application.setName("aaa");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("N/A");
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("rmi");
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.setApplication(application);
service.setRegistry(registry);
service.setProtocol(protocol);
service.export();
try {
URL url = service.toUrls().get(0);
// from api
assertEquals("aaa", url.getParameter("application"));
// from dubbo.properties
assertEquals("world", url.getParameter("owner"));
// from system property
assertEquals(1234, url.getPort());
} finally {
service.unexport();
}
} finally {
if (portString != null) {
System.setProperty("dubbo.protocol.port", portString);
}
}
}