com.alibaba.dubbo.config.ApplicationConfig Java Examples

The following examples show how to use com.alibaba.dubbo.config.ApplicationConfig. 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: ConfigTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
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, 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 #3
Source File: DubboNamespaceHandlerTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testProviderXml() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider.xml");
    ctx.start();

    ProtocolConfig protocolConfig = ctx.getBean(ProtocolConfig.class);
    assertThat(protocolConfig, not(nullValue()));
    assertThat(protocolConfig.getName(), is("dubbo"));
    assertThat(protocolConfig.getPort(), is(20813));

    ApplicationConfig applicationConfig = ctx.getBean(ApplicationConfig.class);
    assertThat(applicationConfig, not(nullValue()));
    assertThat(applicationConfig.getName(), is("demo-provider"));

    DemoService service = ctx.getBean(DemoService.class);
    assertThat(service, not(nullValue()));
}
 
Example #4
Source File: ConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #5
Source File: DubboServiceConfig.java    From dubbo-mock with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #6
Source File: APIConfigurationLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Before
public void initProvider() {
    ApplicationConfig application = new ApplicationConfig();
    application.setName("demo-provider");
    application.setVersion("1.0");

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

    ServiceConfig<GreetingsService> service = new ServiceConfig<>();
    service.setApplication(application);
    service.setRegistry(registryConfig);
    service.setInterface(GreetingsService.class);
    service.setRef(new GreetingsServiceImpl());

    service.export();
}
 
Example #7
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 #8
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #9
Source File: TestServer.java    From brave with Apache License 2.0 6 votes vote down vote up
TestServer(Propagation.Factory propagationFactory) {
  extractor = propagationFactory.get().extractor(Map::get);
  linkLocalIp = Platform.get().linkLocalIp();
  if (linkLocalIp != null) {
    // avoid dubbo's logic which might pick docker ip
    System.setProperty(Constants.DUBBO_IP_TO_BIND, linkLocalIp);
    System.setProperty(Constants.DUBBO_IP_TO_REGISTRY, linkLocalIp);
  }
  service = new ServiceConfig<>();
  service.setApplication(new ApplicationConfig("bean-provider"));
  service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
  service.setProtocol(new ProtocolConfig("dubbo", PickUnusedPort.get()));
  service.setInterface(GreeterService.class);
  service.setRef((method, parameterTypes, args) -> {
    requestQueue.add(extractor.extract(RpcContext.getContext().getAttachments()));
    return args[0];
  });
}
 
Example #10
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 #11
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 #12
Source File: ConfigTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #13
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 #14
Source File: ConfigTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #15
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 #16
Source File: DefaultDubboConfigBinderTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBinder() {

    ApplicationConfig applicationConfig = new ApplicationConfig();
    dubboConfigBinder.bind("dubbo.application", applicationConfig);
    Assert.assertEquals("hello", applicationConfig.getName());
    Assert.assertEquals("world", applicationConfig.getOwner());

    RegistryConfig registryConfig = new RegistryConfig();
    dubboConfigBinder.bind("dubbo.registry", registryConfig);
    Assert.assertEquals("10.20.153.17", registryConfig.getAddress());

    ProtocolConfig protocolConfig = new ProtocolConfig();
    dubboConfigBinder.bind("dubbo.protocol", protocolConfig);
    Assert.assertEquals(Integer.valueOf(20881), protocolConfig.getPort());

    ConsumerConfig consumerConfig = new ConsumerConfig();
    dubboConfigBinder.bind("dubbo.consumer", consumerConfig);

    Assert.assertEquals(isDefault, consumerConfig.isDefault());
    Assert.assertEquals(client, consumerConfig.getClient());
    Assert.assertEquals(threadPool, consumerConfig.getThreadpool());
    Assert.assertEquals(coreThreads, consumerConfig.getCorethreads());
    Assert.assertEquals(threads, consumerConfig.getThreads());
    Assert.assertEquals(queues, consumerConfig.getQueues());
}
 
Example #17
Source File: EnableDubboConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiple() {

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(TestMultipleConfig.class);
    context.refresh();

    // application
    ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class);
    Assert.assertEquals("dubbo-demo-application", applicationConfig.getName());

    ApplicationConfig applicationBean2 = context.getBean("applicationBean2", ApplicationConfig.class);
    Assert.assertEquals("dubbo-demo-application2", applicationBean2.getName());

    ApplicationConfig applicationBean3 = context.getBean("applicationBean3", ApplicationConfig.class);
    Assert.assertEquals("dubbo-demo-application3", applicationBean3.getName());

}
 
Example #18
Source File: ConfigTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #19
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 #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){
    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 #21
Source File: DubboConfigConfigurationTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiple() {

    context.register(DubboConfigConfiguration.Multiple.class);
    context.refresh();

    // application
    ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class);
    Assert.assertEquals("dubbo-demo-application", applicationConfig.getName());

    ApplicationConfig applicationBean2 = context.getBean("applicationBean2", ApplicationConfig.class);
    Assert.assertEquals("dubbo-demo-application2", applicationBean2.getName());

    ApplicationConfig applicationBean3 = context.getBean("applicationBean3", ApplicationConfig.class);
    Assert.assertEquals("dubbo-demo-application3", applicationBean3.getName());

}
 
Example #22
Source File: DubboConfigConfigurationTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testSingle() throws IOException {

    context.register(DubboConfigConfiguration.Single.class);
    context.refresh();

    // application
    ApplicationConfig applicationConfig = context.getBean("applicationBean", ApplicationConfig.class);
    Assert.assertEquals("dubbo-demo-application", applicationConfig.getName());

    // module
    ModuleConfig moduleConfig = context.getBean("moduleBean", ModuleConfig.class);
    Assert.assertEquals("dubbo-demo-module", moduleConfig.getName());

    // registry
    RegistryConfig registryConfig = context.getBean(RegistryConfig.class);
    Assert.assertEquals("zookeeper://192.168.99.100:32770", registryConfig.getAddress());

    // protocol
    ProtocolConfig protocolConfig = context.getBean(ProtocolConfig.class);
    Assert.assertEquals("dubbo", protocolConfig.getName());
    Assert.assertEquals(Integer.valueOf(20880), protocolConfig.getPort());
}
 
Example #23
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 #24
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #25
Source File: UrlTestBase.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example #26
Source File: ConfigTest.java    From dubbox-hystrix 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: DubboEasyTransRpcConsumerImpl.java    From EasyTransaction with Apache License 2.0 5 votes vote down vote up
public DubboEasyTransRpcConsumerImpl(Optional<ApplicationConfig> applicationConfig, Optional<RegistryConfig> registryConfig,Optional<ProtocolConfig> protocolConfig,Optional<ConsumerConfig> consumerConfig,Optional<ModuleConfig> moduleConfig,Optional<MonitorConfig> monitorConfig, Optional<DubboReferanceCustomizationer> customizationer) {
	super();
	this.applicationConfig = applicationConfig.orElse(null);
	this.registryConfig = registryConfig.orElse(null);
	this.protocolConfig = protocolConfig.orElse(null);
	this.customizationer = customizationer.orElse(null);
	this.consumerConfig = consumerConfig.orElse(null);
	this.moduleConfig = moduleConfig.orElse(null);
	this.monitorConfig = monitorConfig.orElse(null);
}
 
Example #28
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 #29
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #30
Source File: CompensablePrimaryFilter.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("z-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);
	}
}