Search in sources :

Example 6 with ReferenceConfig

use of org.apache.dubbo.config.ReferenceConfig in project dubbo by alibaba.

the class ConfigTest method testSystemPropertyOverrideReferenceConfig.

@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());
        ProtocolConfig protocolConfig = new ProtocolConfig("injvm");
        ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
        reference.setInterface(DemoService.class);
        reference.setInjvm(true);
        reference.setRetries(2);
        DubboBootstrap.getInstance().application(new ApplicationConfig("testSystemPropertyOverrideReferenceConfig")).registry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)).protocol(protocolConfig).service(service).reference(reference).start();
        assertEquals(Integer.valueOf(5), reference.getRetries());
    } finally {
        System.setProperty("dubbo.reference.retries", "");
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 7 with ReferenceConfig

use of org.apache.dubbo.config.ReferenceConfig in project dubbo by alibaba.

the class ConfigTest method testServiceAnnotation.

@Test
public void testServiceAnnotation() {
    AnnotationConfigApplicationContext providerContext = new AnnotationConfigApplicationContext();
    providerContext.register(ProviderConfiguration.class);
    providerContext.refresh();
    ReferenceConfig<HelloService> reference = new ReferenceConfig<HelloService>();
    reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    reference.setInterface(HelloService.class);
    reference.setUrl("dubbo://127.0.0.1:12345");
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(new ApplicationConfig("consumer")).reference(reference).start();
    HelloService helloService = bootstrap.getCache().get(reference);
    String hello = helloService.sayHello("hello");
    assertEquals("Hello, hello", hello);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) HelloService(org.apache.dubbo.config.spring.api.HelloService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 8 with ReferenceConfig

use of org.apache.dubbo.config.ReferenceConfig in project dubbo by alibaba.

the class ConfigTest method testReferGenericExport.

@Test
public void testReferGenericExport() throws Exception {
    RegistryConfig rc = new RegistryConfig();
    rc.setAddress(RegistryConfig.NO_AVAILABLE);
    ServiceConfig<GenericService> sc = new ServiceConfig<GenericService>();
    sc.setRegistry(rc);
    sc.setInterface(DemoService.class.getName());
    sc.setRef((method, parameterTypes, args) -> null);
    ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>();
    ref.setRegistry(rc);
    ref.setInterface(DemoService.class.getName());
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(new ApplicationConfig("test-refer-generic-export")).service(sc).reference(ref);
    try {
        bootstrap.start();
        Assertions.fail();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        bootstrap.stop();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) GenericService(org.apache.dubbo.rpc.service.GenericService) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) BeanCreationException(org.springframework.beans.factory.BeanCreationException) RpcException(org.apache.dubbo.rpc.RpcException) Test(org.junit.jupiter.api.Test)

Example 9 with ReferenceConfig

use of org.apache.dubbo.config.ReferenceConfig in project dubbo by alibaba.

the class Application method runWithRefer.

private static void runWithRefer() {
    ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
    reference.setApplication(new ApplicationConfig("dubbo-demo-api-consumer"));
    reference.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
    reference.setInterface(DemoService.class);
    DemoService service = reference.get();
    String message = service.sayHello("dubbo");
    System.out.println(message);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.demo.DemoService)

Example 10 with ReferenceConfig

use of org.apache.dubbo.config.ReferenceConfig in project dubbo by alibaba.

the class Application method runWithBootstrap.

private static void runWithBootstrap() {
    ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
    reference.setInterface(DemoService.class);
    reference.setGeneric("true");
    DubboBootstrap bootstrap = DubboBootstrap.getInstance();
    bootstrap.application(new ApplicationConfig("dubbo-demo-api-consumer")).registry(new RegistryConfig("zookeeper://127.0.0.1:2181")).reference(reference).start();
    DemoService demoService = ReferenceConfigCache.getCache().get(reference);
    String message = demoService.sayHello("dubbo");
    System.out.println(message);
    // generic invoke
    GenericService genericService = (GenericService) demoService;
    Object genericInvokeResult = genericService.$invoke("sayHello", new String[] { String.class.getName() }, new Object[] { "dubbo generic invoke" });
    System.out.println(genericInvokeResult);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) GenericService(org.apache.dubbo.rpc.service.GenericService) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.demo.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap)

Aggregations

ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)19 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)16 RegistryConfig (org.apache.dubbo.config.RegistryConfig)16 Test (org.junit.jupiter.api.Test)12 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)11 ServiceConfig (org.apache.dubbo.config.ServiceConfig)9 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)8 DemoService (org.apache.dubbo.config.spring.api.DemoService)7 GenericService (org.apache.dubbo.rpc.service.GenericService)7 ArrayList (java.util.ArrayList)4 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 List (java.util.List)2 URL (org.apache.dubbo.common.URL)2 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)2 MethodConfig (org.apache.dubbo.config.MethodConfig)2 DemoService (org.apache.dubbo.demo.DemoService)2 GreetingsService (com.pinpoint.test.plugin.api.GreetingsService)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1