本文整理汇总了Java中com.alibaba.dubbo.config.ReferenceConfig.setRegistry方法的典型用法代码示例。如果您正苦于以下问题:Java ReferenceConfig.setRegistry方法的具体用法?Java ReferenceConfig.setRegistry怎么用?Java ReferenceConfig.setRegistry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.config.ReferenceConfig
的用法示例。
在下文中一共展示了ReferenceConfig.setRegistry方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例3: 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;
}
示例4: refer
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的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();
}
示例5: testToString
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的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(" />"));
}
示例6: testReferGenericExport
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的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();
}
}
示例7: testAppendFilter
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
@Test
public void testAppendFilter() throws Exception {
ProviderConfig provider = new ProviderConfig();
provider.setFilter("classloader,monitor");
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setFilter("accesslog,trace");
service.setProvider(provider);
service.setProtocol(new ProtocolConfig("dubbo", 20880));
service.setApplication(new ApplicationConfig("provider"));
service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
try {
service.export();
List<URL> urls = service.toUrls();
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter"));
ConsumerConfig consumer = new ConsumerConfig();
consumer.setFilter("classloader,monitor");
ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
reference.setFilter("accesslog,trace");
reference.setConsumer(consumer);
reference.setApplication(new ApplicationConfig("consumer"));
reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
reference.setInterface(DemoService.class);
reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false");
try {
reference.get();
urls = reference.toUrls();
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter"));
} finally {
reference.destroy();
}
} finally {
service.unexport();
}
}
示例8: testApiOverrideProperties
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的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();
}
}
示例9: 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();
}
示例10: 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> demoServiceReferenceConfig = new ReferenceConfig<>();
demoServiceReferenceConfig.setApplication(dubboApp);
demoServiceReferenceConfig.setRegistry(registryConfig);
demoServiceReferenceConfig.setInterface(DemoService.class);
demoServiceReferenceConfig.setCheck(false);
DemoService demoService = demoServiceReferenceConfig.get();
// resteasy 暴露服务
resources.add(demoService);
deployment.setResources(resources);
nettyJaxrsServer.start();
// TimeUnit.SECONDS.sleep(6);
// nettyJaxrsServer.stop();
// demoServiceReferenceConfig.destroy();
}
示例11: testAppendFilter
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的package包/类
@Test
public void testAppendFilter() throws Exception {
ProviderConfig provider = new ProviderConfig();
provider.setFilter("classloader,monitor");
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setFilter("accesslog,trace");
service.setProvider(provider);
service.setProtocol(new ProtocolConfig("dubbo", 20880));
service.setApplication(new ApplicationConfig("provider"));
service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
try {
service.export();
List<URL> urls = service.toUrls();
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter"));
ConsumerConfig consumer = new ConsumerConfig();
consumer.setFilter("classloader,monitor");
ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
reference.setFilter("accesslog,trace");
reference.setConsumer(consumer);
reference.setApplication(new ApplicationConfig("consumer"));
reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
reference.setInterface(DemoService.class);
reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false");
try {
reference.get();
urls = reference.toUrls();
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter"));
} finally {
reference.destroy();
}
} finally {
service.unexport();
}
}
示例12: testApiOverrideProperties
import com.alibaba.dubbo.config.ReferenceConfig; //导入方法依赖的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();
}
}