Search in sources :

Example 1 with EchoService

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

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

the class PublishingServiceDefinitionListenerTest method testOnServiceConfigExportedEvent.

/**
 * Test {@link ServiceConfigExportedEvent} arising
 */
@Test
public void testOnServiceConfigExportedEvent() {
    ServiceConfig<EchoService> serviceConfig = new ServiceConfig<>();
    serviceConfig.setInterface(EchoService.class);
    serviceConfig.setRef(new EchoServiceImpl());
    serviceConfig.setRegistry(new RegistryConfig("N/A"));
    serviceConfig.setProtocol(new ProtocolConfig("dubbo", NetUtils.getAvailablePort(20880 + new Random().nextInt(10000))));
    serviceConfig.export();
    String serviceDefinition = writableMetadataService.getServiceDefinition(EchoService.class.getName());
    ServiceDefinition serviceDefinitionBuild = ServiceDefinitionBuilder.build(serviceConfig.getInterfaceClass());
    assertEquals(serviceDefinition, JSON.toJSONString(serviceDefinitionBuild));
    serviceConfig.unexport();
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) Random(java.util.Random) ServiceConfig(org.apache.dubbo.config.ServiceConfig) EchoService(org.apache.dubbo.config.bootstrap.EchoService) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) EchoServiceImpl(org.apache.dubbo.config.bootstrap.EchoServiceImpl) ServiceDefinition(org.apache.dubbo.metadata.definition.model.ServiceDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

RegistryConfig (org.apache.dubbo.config.RegistryConfig)2 EchoService (org.apache.dubbo.config.bootstrap.EchoService)2 Random (java.util.Random)1 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)1 ServiceConfig (org.apache.dubbo.config.ServiceConfig)1 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)1 EchoServiceImpl (org.apache.dubbo.config.bootstrap.EchoServiceImpl)1 UserService (org.apache.dubbo.config.bootstrap.rest.UserService)1 ServiceDefinition (org.apache.dubbo.metadata.definition.model.ServiceDefinition)1 Test (org.junit.jupiter.api.Test)1