Search in sources :

Example 1 with DubboBootstrap

use of org.apache.dubbo.config.bootstrap.DubboBootstrap 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 DubboBootstrap

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

the class DubboProviderApplication method startWithBootstrap.

private static void startWithBootstrap() {
    ServiceConfig<GreetingsServiceImpl> service = new ServiceConfig<>();
    service.setInterface(GreetingsService.class);
    service.setRef(new GreetingsServiceImpl());
    DubboBootstrap bootstrap = DubboBootstrap.getInstance();
    bootstrap.application(new ApplicationConfig("dubbo-demo-api-provider")).registry(new RegistryConfig("zookeeper://" + ZOOKEEPER_HOST + ":2181")).service(service).start().await();
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap)

Example 3 with DubboBootstrap

use of org.apache.dubbo.config.bootstrap.DubboBootstrap in project dubbo by alibaba.

the class DubboInterfaceConsumerBootstrap method main.

public static void main(String[] args) throws Exception {
    RegistryConfig interfaceRegistry = new RegistryConfig();
    interfaceRegistry.setId("interfaceRegistry");
    interfaceRegistry.setAddress("zookeeper://127.0.0.1:2181");
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application("dubbo-consumer-demo").registry(interfaceRegistry).reference("echo", builder -> builder.interfaceClass(EchoService.class).protocol("dubbo")).reference("user", builder -> builder.interfaceClass(UserService.class).protocol("rest")).start().await();
    EchoService echoService = bootstrap.getCache().get(EchoService.class);
    UserService userService = bootstrap.getCache().get(UserService.class);
    for (int i = 0; i < 500; i++) {
        Thread.sleep(2000L);
        System.out.println(echoService.echo("Hello,World"));
        System.out.println(userService.getUser(1L));
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) RegistryConfig(org.apache.dubbo.config.RegistryConfig) EchoService(org.apache.dubbo.config.bootstrap.EchoService) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) EchoService(org.apache.dubbo.config.bootstrap.EchoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap)

Example 4 with DubboBootstrap

use of org.apache.dubbo.config.bootstrap.DubboBootstrap in project dubbo by alibaba.

the class ConfigTest method testDubboProtocolPortOverride.

@Test
public void testDubboProtocolPortOverride() throws Exception {
    String dubboPort = System.getProperty("dubbo.protocol.dubbo.port");
    int port = 55555;
    System.setProperty("dubbo.protocol.dubbo.port", String.valueOf(port));
    ServiceConfig<DemoService> service = null;
    DubboBootstrap bootstrap = null;
    try {
        ApplicationConfig application = new ApplicationConfig();
        application.setName("dubbo-protocol-port-override");
        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("N/A");
        ProtocolConfig protocol = new ProtocolConfig();
        service = new ServiceConfig<DemoService>();
        service.setInterface(DemoService.class);
        service.setRef(new DemoServiceImpl());
        service.setApplication(application);
        service.setRegistry(registry);
        service.setProtocol(protocol);
        DubboBootstrap.getInstance().application(application).registry(registry).protocol(protocol).service(service).start();
        Assertions.assertEquals(port, service.getExportedUrls().get(0).getPort());
    } finally {
        if (StringUtils.isNotEmpty(dubboPort)) {
            System.setProperty("dubbo.protocol.dubbo.port", dubboPort);
        }
        if (bootstrap != null) {
            bootstrap.stop();
        }
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) Matchers.containsString(org.hamcrest.Matchers.containsString) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 5 with DubboBootstrap

use of org.apache.dubbo.config.bootstrap.DubboBootstrap 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)

Aggregations

DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)22 RegistryConfig (org.apache.dubbo.config.RegistryConfig)20 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)19 Test (org.junit.jupiter.api.Test)16 ServiceConfig (org.apache.dubbo.config.ServiceConfig)14 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)11 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)11 DemoService (org.apache.dubbo.config.spring.api.DemoService)10 GenericService (org.apache.dubbo.rpc.service.GenericService)8 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)7 ArrayList (java.util.ArrayList)5 URL (org.apache.dubbo.common.URL)5 List (java.util.List)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 JavaBeanDescriptor (org.apache.dubbo.common.beanutil.JavaBeanDescriptor)2 HelloService (org.apache.dubbo.config.spring.api.HelloService)2 GenericException (org.apache.dubbo.rpc.service.GenericException)2 ReferenceConfig (com.alibaba.dubbo.config.ReferenceConfig)1 ServiceConfig (com.alibaba.dubbo.config.ServiceConfig)1 GreetingsService (com.pinpoint.test.plugin.api.GreetingsService)1