Java Code Examples for com.alibaba.dubbo.config.ReferenceConfig#setUrl()

The following examples show how to use com.alibaba.dubbo.config.ReferenceConfig#setUrl() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceFactory.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
protected T createClient(Class<T> cls, String targetIP, int targetPort, int connectTimeout,int clientNums, String protocol, String serialization){
    ReferenceConfig<T> referenceConfig = new ReferenceConfig<T>();
    referenceConfig.setInterface(cls);
    StringBuilder url = new StringBuilder();
    url.append(protocol);
    url.append("://");
    url.append(targetIP);
    url.append(":");
    url.append(targetPort);
    url.append("/");
    url.append(cls.getName());
    url.append("?optimizer=com.alibaba.dubbo.rpc.benchmark.SerializationOptimizerImpl");
    if (!StringUtils.isEmpty(serialization)) {
        url.append("&serialization=");
        url.append(serialization);
    }
    referenceConfig.setUrl(url.toString());
    // hardcode
    referenceConfig.setConnections(clientNums);
    ApplicationConfig application = new ApplicationConfig();
    application.setName("dubbo_consumer");
    referenceConfig.setApplication(application);
    referenceConfig.setTimeout(connectTimeout);
    return referenceConfig.get();
}
 
Example 2
Source File: ServiceFactory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected T createClient(Class<T> cls, String targetIP, int targetPort, int connectTimeout,int clientNums){
    ReferenceConfig<T> referenceConfig = new ReferenceConfig<T>();
    referenceConfig.setInterface(cls);
    StringBuilder url = new StringBuilder();
    url.append("dubbo://");
    url.append(targetIP);
    url.append(":");
    url.append(targetPort);
    url.append("/");
    url.append(cls.getName());
    referenceConfig.setUrl(url.toString());
    // hardcode
    referenceConfig.setConnections(clientNums);
    ApplicationConfig application = new ApplicationConfig();
    application.setName("dubbo_consumer");
    referenceConfig.setApplication(application);
    referenceConfig.setTimeout(connectTimeout);
    return referenceConfig.get();
}
 
Example 3
Source File: ServiceFactory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected T createClient(Class<T> cls, String targetIP, int targetPort, int connectTimeout,int clientNums){
    ReferenceConfig<T> referenceConfig = new ReferenceConfig<T>();
    referenceConfig.setInterface(cls);
    StringBuilder url = new StringBuilder();
    url.append("dubbo://");
    url.append(targetIP);
    url.append(":");
    url.append(targetPort);
    url.append("/");
    url.append(cls.getName());
    referenceConfig.setUrl(url.toString());
    // hardcode
    referenceConfig.setConnections(clientNums);
    ApplicationConfig application = new ApplicationConfig();
    application.setName("dubbo_consumer");
    referenceConfig.setApplication(application);
    referenceConfig.setTimeout(connectTimeout);
    return referenceConfig.get();
}
 
Example 4
Source File: DubboUtils.java    From java-master with Apache License 2.0 6 votes vote down vote up
private static <T> ReferenceConfig<T> getReferenceConfig(Class<?> interfaceClass, String group, String version,
                                                         String host) {
    String referenceKey = interfaceClass.getName();
    ReferenceConfig<T> referenceConfig = new ReferenceConfig<>();
    referenceConfig.setApplication(application);
    referenceConfig.setRegistry(getRegistryConfig(group, version));
    referenceConfig.setInterface(interfaceClass);
    referenceConfig.setVersion(version);
    referenceConfig.setTimeout(30000);
    referenceConfig.setGeneric(true);
    if (StringUtils.isNotBlank(host)) {
        String url = String.format("dubbo://%s/%s", host, referenceKey);
        referenceConfig.setUrl(url);
    }
    return referenceConfig;
}
 
Example 5
Source File: ServiceFactory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected T createClient(Class<T> cls, String targetIP, int targetPort, int connectTimeout,int clientNums){
    ReferenceConfig<T> referenceConfig = new ReferenceConfig<T>();
    referenceConfig.setInterface(cls);
    StringBuilder url = new StringBuilder();
    url.append("dubbo://");
    url.append(targetIP);
    url.append(":");
    url.append(targetPort);
    url.append("/");
    url.append(cls.getName());
    referenceConfig.setUrl(url.toString());
    // hardcode
    referenceConfig.setConnections(clientNums);
    ApplicationConfig application = new ApplicationConfig();
    application.setName("dubbo_consumer");
    referenceConfig.setApplication(application);
    referenceConfig.setTimeout(connectTimeout);
    return referenceConfig.get();
}
 
Example 6
Source File: ServiceFactory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected T createClient(Class<T> cls, String targetIP, int targetPort, int connectTimeout,int clientNums, String protocol, String serialization){
    ReferenceConfig<T> referenceConfig = new ReferenceConfig<T>();
    referenceConfig.setInterface(cls);
    StringBuilder url = new StringBuilder();
    url.append(protocol);
    url.append("://");
    url.append(targetIP);
    url.append(":");
    url.append(targetPort);
    url.append("/");
    url.append(cls.getName());
    url.append("?optimizer=com.alibaba.dubbo.rpc.benchmark.SerializationOptimizerImpl");
    if (!StringUtils.isEmpty(serialization)) {
        url.append("&serialization=");
        url.append(serialization);
    }
    referenceConfig.setUrl(url.toString());
    // hardcode
    referenceConfig.setConnections(clientNums);
    ApplicationConfig application = new ApplicationConfig();
    application.setName("dubbo_consumer");
    referenceConfig.setApplication(application);
    referenceConfig.setTimeout(connectTimeout);
    return referenceConfig.get();
}
 
Example 7
Source File: ConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 8
Source File: ConfigTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 9
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 10
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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(" />"));
}
 
Example 11
Source File: DubboConsumerBootstrap.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
private void copyConsumer(ConsumerConfig<T> consumerConfig, ReferenceConfig<T> referenceConfig) {
    referenceConfig.setId(consumerConfig.getId());
    referenceConfig.setInterface(consumerConfig.getInterfaceId());
    referenceConfig.setGroup(consumerConfig.getUniqueId());
    referenceConfig.setVersion("1.0");
    referenceConfig.setActives(consumerConfig.getConcurrents());
    referenceConfig.setCluster(consumerConfig.getCluster());
    referenceConfig.setConnections(consumerConfig.getConnectionNum());
    referenceConfig.setRetries(consumerConfig.getRetries());
    referenceConfig.setProxy(consumerConfig.getProxy());
    referenceConfig.setTimeout(consumerConfig.getTimeout());
    referenceConfig.setUrl(consumerConfig.getDirectUrl());
    referenceConfig.setCheck(consumerConfig.isCheck());
    referenceConfig.setLazy(consumerConfig.isLazy());
    referenceConfig.setGeneric(consumerConfig.isGeneric());
    String invokeType = consumerConfig.getInvokeType();
    if (invokeType != null) {
        if (RpcConstants.INVOKER_TYPE_ONEWAY.equals(invokeType)) {
            referenceConfig.setSent(false);
        }
        if (RpcConstants.INVOKER_TYPE_CALLBACK.equals(invokeType)
            || RpcConstants.INVOKER_TYPE_FUTURE.equals(invokeType)) {
            referenceConfig.setAsync(true);
        }
    }
    referenceConfig.setParameters(consumerConfig.getParameters());
}
 
Example 12
Source File: Dubbo26ITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
public static ReferenceConfig<GreeterService> getClient(final String ip, final int port) {
  final ReferenceConfig<GreeterService> client = new ReferenceConfig<>();
  client.setApplication(new ApplicationConfig("test"));
  client.setInterface(GreeterService.class);
  client.setUrl("dubbo://" + ip + ":" + port);
  client.setScope("local");
  client.setInjvm(true);
  return client;
}
 
Example 13
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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(" />"));
}
 
Example 14
Source File: XAResourceDeserializerImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void processInitPhysicalInstanceIfNecessary(RemoteAddr remoteAddr) throws RpcException {
	RemoteCoordinatorRegistry participantRegistry = RemoteCoordinatorRegistry.getInstance();
	TransactionBeanRegistry beanRegistry = TransactionBeanRegistry.getInstance();

	RemoteCoordinator participant = participantRegistry.getPhysicalInstance(remoteAddr);
	if (participant == null) {
		ApplicationConfig applicationConfig = beanRegistry.getBean(ApplicationConfig.class);
		RegistryConfig registryConfig = beanRegistry.getBean(RegistryConfig.class);
		ProtocolConfig protocolConfig = beanRegistry.getBean(ProtocolConfig.class);

		ReferenceConfig<RemoteCoordinator> referenceConfig = new ReferenceConfig<RemoteCoordinator>();
		referenceConfig.setInterface(RemoteCoordinator.class);
		referenceConfig.setTimeout(15000);
		referenceConfig.setCluster("failfast");
		referenceConfig.setLoadbalance("bytejta");
		referenceConfig.setFilter("bytejta");
		referenceConfig.setGroup("org-bytesoft-bytejta");
		referenceConfig.setCheck(false);
		referenceConfig.setRetries(-1);
		referenceConfig.setUrl(String.format("%s:%s", remoteAddr.getServerHost(), remoteAddr.getServerPort()));
		referenceConfig.setScope(Constants.SCOPE_REMOTE);

		referenceConfig.setApplication(applicationConfig);
		if (registryConfig != null) {
			referenceConfig.setRegistry(registryConfig);
		}
		if (protocolConfig != null) {
			referenceConfig.setProtocol(protocolConfig.getName());
		} // end-if (protocolConfig != null)

		RemoteCoordinator reference = referenceConfig.get();
		if (reference == null) {
			throw new RpcException("Cannot get the application name of the remote application.");
		}

		participantRegistry.putPhysicalInstance(remoteAddr, reference);
	}
}
 
Example 15
Source File: ConfigTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@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();
    }
}
 
Example 16
Source File: ConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@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();
    }
}
 
Example 17
Source File: ConfigTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@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();
    }
}
 
Example 18
Source File: ConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@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();
    }
}
 
Example 19
Source File: CompensableLoadBalance.java    From ByteTCC with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void processInitRemoteParticipantIfNecessary(RemoteAddr remoteAddr) throws RpcException {
	RemoteCoordinatorRegistry participantRegistry = RemoteCoordinatorRegistry.getInstance();
	CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	CompensableCoordinator compensableCoordinator = (CompensableCoordinator) beanFactory.getCompensableNativeParticipant();

	RemoteCoordinator participant = participantRegistry.getPhysicalInstance(remoteAddr);
	if (participant == null) {
		ApplicationConfig applicationConfig = beanRegistry.getBean(ApplicationConfig.class);
		RegistryConfig registryConfig = beanRegistry.getBean(RegistryConfig.class);
		ProtocolConfig protocolConfig = beanRegistry.getBean(ProtocolConfig.class);

		ReferenceConfig<RemoteCoordinator> referenceConfig = new ReferenceConfig<RemoteCoordinator>();
		referenceConfig.setInterface(RemoteCoordinator.class);
		referenceConfig.setTimeout(6 * 1000);
		referenceConfig.setCluster("failfast");
		referenceConfig.setFilter("bytetcc");
		referenceConfig.setCheck(false);
		referenceConfig.setRetries(-1);
		referenceConfig.setUrl(String.format("%s:%s", remoteAddr.getServerHost(), remoteAddr.getServerPort()));
		referenceConfig.setScope(Constants.SCOPE_REMOTE);

		if (compensableCoordinator.isStatefully()) {
			referenceConfig.setGroup("x-bytetcc");
		} else {
			referenceConfig.setGroup("z-bytetcc");
		}

		referenceConfig.setApplication(applicationConfig);
		if (registryConfig != null) {
			referenceConfig.setRegistry(registryConfig);
		}
		if (protocolConfig != null) {
			referenceConfig.setProtocol(protocolConfig.getName());
		} // end-if (protocolConfig != null)

		RemoteCoordinator reference = referenceConfig.get();
		if (reference == null) {
			throw new RpcException("Cannot get the application name of the remote application.");
		}

		participantRegistry.putPhysicalInstance(remoteAddr, reference);
	}
}
 
Example 20
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
@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();
    }
}