Search in sources :

Example 1 with ReferenceConfig

use of org.apache.dubbo.config.ReferenceConfig in project pinpoint by naver.

the class DubboConsumerPluginTestController method sayHi.

@RequestMapping(value = "/sayHi", method = RequestMethod.GET)
@ResponseBody
public String sayHi() {
    ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
    reference.setInterface(GreetingsService.class);
    reference.setGeneric("true");
    DubboBootstrap bootstrap = DubboBootstrap.getInstance();
    bootstrap.application(new ApplicationConfig("dubbo-demo-api-consumer")).registry(new RegistryConfig("zookeeper://" + ZOOKEEPER_HOST + ":2181")).reference(reference).start();
    GreetingsService demoService = ReferenceConfigCache.getCache().get(reference);
    String message = demoService.sayHi("dubbo");
    return message;
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) GreetingsService(com.pinpoint.test.plugin.api.GreetingsService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with ReferenceConfig

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

the class ReferenceBuilderTest method build.

@Test
void build() {
    ConsumerConfig consumer = new ConsumerConfig();
    MethodConfig method = new MethodConfig();
    ReferenceBuilder<DemoService> builder = new ReferenceBuilder<>();
    builder.id("id").interfaceClass(DemoService.class).protocol("protocol").client("client").url("url").consumer(consumer).addMethod(method).services("test-service", "test-service2");
    ReferenceConfig config = builder.build();
    ReferenceConfig config2 = builder.build();
    Assertions.assertEquals("org.apache.dubbo.config.api.DemoService", config.getInterface());
    Assertions.assertEquals(DemoService.class, config.getInterfaceClass());
    Assertions.assertEquals("protocol", config.getProtocol());
    Assertions.assertEquals("client", config.getClient());
    Assertions.assertEquals("url", config.getUrl());
    Assertions.assertEquals(consumer, config.getConsumer());
    Assertions.assertEquals("test-service,test-service2", config.getServices());
    Assertions.assertEquals(ofSet("test-service", "test-service2"), config.getSubscribedServices());
    Assertions.assertTrue(config.getMethods().contains(method));
    Assertions.assertEquals(1, config.getMethods().size());
    Assertions.assertNotSame(config, config2);
}
Also used : MethodConfig(org.apache.dubbo.config.MethodConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.config.api.DemoService) ConsumerConfig(org.apache.dubbo.config.ConsumerConfig) Test(org.junit.jupiter.api.Test)

Example 3 with ReferenceConfig

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

the class ConfigTest method testForks.

@Test
public void testForks() {
    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");
    int forks = 10;
    reference.setForks(forks);
    String str = reference.toString();
    assertTrue(str.contains("forks=\"" + forks + "\""));
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 4 with ReferenceConfig

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

the class ConfigTest method testAppendFilter.

@Test
public void testAppendFilter() throws Exception {
    ApplicationConfig application = new ApplicationConfig("provider");
    ProviderConfig provider = new ProviderConfig();
    provider.setFilter("classloader,monitor");
    ConsumerConfig consumer = new ConsumerConfig();
    consumer.setFilter("classloader,monitor");
    ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
    service.setFilter("accesslog,trace");
    service.setProvider(provider);
    service.setProtocol(new ProtocolConfig("dubbo", 20880));
    service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    service.setInterface(DemoService.class);
    service.setRef(new DemoServiceImpl());
    ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
    reference.setFilter("accesslog,trace");
    reference.setConsumer(consumer);
    reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    reference.setInterface(DemoService.class);
    reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false");
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(application).provider(provider).service(service).reference(reference).start();
    try {
        List<URL> urls = service.getExportedUrls();
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter"));
        urls = reference.getExportedUrls();
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter"));
    } finally {
        bootstrap.stop();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ProviderConfig(org.apache.dubbo.config.ProviderConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) URL(org.apache.dubbo.common.URL) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) ConsumerConfig(org.apache.dubbo.config.ConsumerConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 5 with ReferenceConfig

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

the class ConfigTest method refer.

private DemoService refer(String url) {
    ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
    reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    reference.setInterface(DemoService.class);
    reference.setUrl(url);
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(new ApplicationConfig("consumer")).reference(reference).start();
    return bootstrap.getCache().get(reference);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) 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)

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