com.alibaba.dubbo.config.ReferenceConfig Java Examples

The following examples show how to use com.alibaba.dubbo.config.ReferenceConfig. 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: ReferenceManager.java    From swagger-dubbo with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: APIConfigurationLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenProviderConsumer_whenSayHi_thenGotResponse() {
    ApplicationConfig application = new ApplicationConfig();
    application.setName("demo-consumer");
    application.setVersion("1.0");

    RegistryConfig registryConfig = new RegistryConfig();
    registryConfig.setAddress("multicast://224.1.1.1:9090");

    ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
    reference.setApplication(application);
    reference.setRegistry(registryConfig);
    reference.setInterface(GreetingsService.class);

    GreetingsService greetingsService = reference.get();
    String hiMessage = greetingsService.sayHi("baeldung");

    assertEquals("hi, baeldung", hiMessage);
}
 
Example #3
Source File: ConfigTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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", "");
    }
}
 
Example #4
Source File: ConfigTest.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@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", "");
    }
}
 
Example #5
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@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", "");
    }
}
 
Example #6
Source File: ConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@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", "");
    }
}
 
Example #7
Source File: ReferenceConfigCache.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public String generateKey(ReferenceConfig<?> referenceConfig) {
    String iName = referenceConfig.getInterface();
    if(StringUtils.isBlank(iName)) {
        Class<?> clazz = referenceConfig.getInterfaceClass();
        iName = clazz.getName();
    }
    if(StringUtils.isBlank(iName)) {
        throw new IllegalArgumentException("No interface info in ReferenceConfig" + referenceConfig);
    }

    StringBuilder ret = new StringBuilder();
    if(! StringUtils.isBlank(referenceConfig.getGroup())) {
        ret.append(referenceConfig.getGroup()).append("/");
    }
    ret.append(iName);
    if(! StringUtils.isBlank(referenceConfig.getVersion())) {
        ret.append(":").append(referenceConfig.getVersion());
    }
    return ret.toString();
}
 
Example #8
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 #9
Source File: ReferenceConfigCache.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public String generateKey(ReferenceConfig<?> referenceConfig) {
    String iName = referenceConfig.getInterface();
    if (StringUtils.isBlank(iName)) {
        Class<?> clazz = referenceConfig.getInterfaceClass();
        iName = clazz.getName();
    }
    if (StringUtils.isBlank(iName)) {
        throw new IllegalArgumentException("No interface info in ReferenceConfig" + referenceConfig);
    }

    StringBuilder ret = new StringBuilder();
    if (!StringUtils.isBlank(referenceConfig.getGroup())) {
        ret.append(referenceConfig.getGroup()).append("/");
    }
    ret.append(iName);
    if (!StringUtils.isBlank(referenceConfig.getVersion())) {
        ret.append(":").append(referenceConfig.getVersion());
    }
    return ret.toString();
}
 
Example #10
Source File: ITTracingFilter_Consumer.java    From brave with Apache License 2.0 6 votes vote down vote up
@Before public void setup() {
  init();
  server.start();

  String url = "dubbo://" + server.ip() + ":" + server.port() + "?scope=remote&generic=bean";
  client = new ReferenceConfig<>();
  client.setApplication(new ApplicationConfig("bean-consumer"));
  client.setFilter("tracing");
  client.setInterface(GreeterService.class);
  client.setUrl(url);

  wrongClient = new ReferenceConfig<>();
  wrongClient.setApplication(new ApplicationConfig("bad-consumer"));
  wrongClient.setFilter("tracing");
  wrongClient.setInterface(GraterService.class);
  wrongClient.setUrl(url);
}
 
Example #11
Source File: DubboSinkFunction.java    From alchemy with Apache License 2.0 6 votes vote down vote up
private ReferenceConfig<GenericService> referenceConfig(DubboProperties properties) throws Exception {
    ApplicationConfig application = new ApplicationConfig();
    application.setName(properties.getApplicationName());
    ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
    reference.setApplication(application);
    reference.setRegistry(new RegistryConfig(properties.getRegistryAddr()));
    reference.setInterface(properties.getInterfaceName());
    reference.setVersion(properties.getVersion());
    reference.setGeneric(true);
    reference.setCheck(false);
    reference.setInit(true);
    if(properties.getProperties() != null){
        BeanUtils.copyProperties(reference, properties.getProperties());
    }
    return reference;
}
 
Example #12
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){
    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 #13
Source File: AnnotationBean.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
public void destroy() {

    //  This will only be called for singleton scope bean, and expected to be called by spring shutdown hook when BeanFactory/ApplicationContext destroys.
    //  We will guarantee dubbo related resources being released with dubbo shutdown hook.

    //  for (ServiceConfig<?> serviceConfig : serviceConfigs) {
    //      try {
    //          serviceConfig.unexport();
    //      } catch (Throwable e) {
    //          logger.error(e.getMessage(), e);
    //      }
    //  }

    for (ReferenceConfig<?> referenceConfig : referenceConfigs.values()) {
        try {
            referenceConfig.destroy();
        } catch (Throwable e) {
            logger.error(e.getMessage(), e);
        }
    }
}
 
Example #14
Source File: Consumer.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

         System.out.println("\n\n\nstart to generic invoke");
         ApplicationConfig applicationConfig = new ApplicationConfig();
         ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
         applicationConfig.setName("UserProviderGer");
         reference.setApplication(applicationConfig);
         RegistryConfig registryConfig = new RegistryConfig();
         registryConfig.setAddress("zookeeper://127.0.0.1:2181");
         reference.setRegistry(registryConfig);
         reference.setGeneric(true);
         reference.setInterface("com.ikurento.user.UserProvider");
         GenericService genericService = reference.get();
         Object[] parameterArgs = new Object[]{"A003"};
         Object result = genericService.$invoke("GetUser", null , parameterArgs);
         System.out.println("res: " + result);

         System.out.println("\n\n\nstart to generic invoke1");
         User user = new User();
         user.setName("Patrick");
         user.setId("id");
         user.setAge(10);
         parameterArgs = new Object[]{user};
         Object result1 = genericService.$invoke("queryUser", new String[]{"com.ikurento.user.User"} , parameterArgs);
         System.out.println("res: " + result1);
    }
 
Example #15
Source File: ITTracingFilter_Provider.java    From brave with Apache License 2.0 6 votes vote down vote up
@Before public void setup() {
  server.service.setFilter("tracing");
  server.service.setInterface(GreeterService.class);
  server.service.setRef((method, parameterTypes, args) -> {
    JavaBeanDescriptor arg = (JavaBeanDescriptor) args[0];
    if (arg.getProperty("value").equals("bad")) {
      throw new IllegalArgumentException("bad");
    }
    String value = currentTraceContext.get() != null
        ? currentTraceContext.get().traceIdString()
        : "";
    arg.setProperty("value", value);
    return args[0];
  });
  server.start();

  ReferenceConfig<GreeterService> ref = new ReferenceConfig<>();
  ref.setApplication(new ApplicationConfig("bean-consumer"));
  ref.setInterface(GreeterService.class);
  ref.setUrl("dubbo://" + server.ip() + ":" + server.port() + "?scope=remote&generic=bean");
  client = ref;

  init();
}
 
Example #16
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 #17
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 #18
Source File: ConfigTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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", "");
    }
}
 
Example #19
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 #20
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 #21
Source File: ReferenceConfigCache.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public String generateKey(ReferenceConfig<?> referenceConfig) {
    String iName = referenceConfig.getInterface();
    if(StringUtils.isBlank(iName)) {
        Class<?> clazz = referenceConfig.getInterfaceClass();
        iName = clazz.getName();
    }
    if(StringUtils.isBlank(iName)) {
        throw new IllegalArgumentException("No interface info in ReferenceConfig" + referenceConfig);
    }

    StringBuilder ret = new StringBuilder();
    if(! StringUtils.isBlank(referenceConfig.getGroup())) {
        ret.append(referenceConfig.getGroup()).append("/");
    }
    ret.append(iName);
    if(! StringUtils.isBlank(referenceConfig.getVersion())) {
        ret.append(":").append(referenceConfig.getVersion());
    }
    return ret.toString();
}
 
Example #22
Source File: DubboGenericServiceInvoker.java    From jsongood with Apache License 2.0 5 votes vote down vote up
public void connectRegistry() {
    Long s = System.currentTimeMillis();
    ReferenceConfig<RegistryService> reference = new ReferenceConfig<RegistryService>();
    reference.setApplication(application);
    reference.setRegistries(registryList); // 多个注册中心可以用setRegistries()
    reference.setInterface(RegistryService.class); // 弱类型接口名
    reference.setRetries(0);
    reference.setTimeout(5000);
    RegistryService registryService = reference.get();
    Long t = System.currentTimeMillis() - s;
    logger.info("connectRegistry success ,spend time=" + t + "ms");

}
 
Example #23
Source File: OrderApplication.java    From EasyTransaction with Apache License 2.0 5 votes vote down vote up
/**
 * This is an optional bean, you can modify Dubbo reference here to change the behavior of consumer
 * @return
 */
@Bean
public DubboReferanceCustomizationer dubboConsumerCustomizationer() {
	return new DubboReferanceCustomizationer() {
		
		@Override
		public void customDubboReferance(String appId, String busCode, ReferenceConfig<GenericService> referenceConfig) {
			Logger logger = LoggerFactory.getLogger(getClass());
			logger.info("custom dubbo consumer!");
		}
	};
}
 
Example #24
Source File: ConfigTest.java    From dubbo3 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 #25
Source File: InvokerSideConfigUrlTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #26
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 #27
Source File: CompensableSecondaryFilter.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void processInitRemoteParticipantIfNecessary(RemoteAddr remoteAddr) throws RpcException {
	RemoteCoordinatorRegistry participantRegistry = RemoteCoordinatorRegistry.getInstance();
	CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.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(6 * 1000);
		referenceConfig.setCluster("failfast");
		referenceConfig.setFilter("bytetcc");
		referenceConfig.setGroup("x-bytetcc");
		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 #28
Source File: TransactionServiceFilter.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 #29
Source File: TestBase.java    From dubbo-mock with Apache License 2.0 5 votes vote down vote up
public ReferenceConfig<TestAbcService> getRef(Class<TestAbcService> interfaceClass, RegistryConfig tempRegistry) {
    if (BooleanUtils.isTrue(reference.isInit())) {
        return reference;
    }
    reference.setInterface(interfaceClass); // 弱类型接口名 
    com.alibaba.dubbo.config.RegistryConfig rc = new com.alibaba.dubbo.config.RegistryConfig();
    rc.setProtocol(tempRegistry.getRegistryProtocol());
    rc.setAddress(tempRegistry.getRegistryAddress());
    rc.setTimeout(tempRegistry.getRegistryTimeout());
    reference.setRegistry(rc);
    reference.setApplication(new ApplicationConfig("test"));
    return reference;
}
 
Example #30
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);
	}
}