Search in sources :

Example 1 with UserService

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

the class DubboServiceProviderBootstrap method multipleRegistries.

private static void multipleRegistries() {
    ProtocolConfig restProtocol = new ProtocolConfig();
    restProtocol.setName("rest");
    restProtocol.setId("rest");
    restProtocol.setPort(-1);
    RegistryConfig interfaceRegistry = new RegistryConfig();
    interfaceRegistry.setId("interfaceRegistry");
    interfaceRegistry.setAddress("zookeeper://127.0.0.1:2181");
    RegistryConfig serviceRegistry = new RegistryConfig();
    serviceRegistry.setId("serviceRegistry");
    serviceRegistry.setAddress("zookeeper://127.0.0.1:2181?registry-type=service");
    ServiceConfig<EchoService> echoService = new ServiceConfig<>();
    echoService.setInterface(EchoService.class.getName());
    echoService.setRef(new EchoServiceImpl());
    // echoService.setRegistries(Arrays.asList(interfaceRegistry, serviceRegistry));
    ServiceConfig<UserService> userService = new ServiceConfig<>();
    userService.setInterface(UserService.class.getName());
    userService.setRef(new UserServiceImpl());
    userService.setProtocol(restProtocol);
    // userService.setRegistries(Arrays.asList(interfaceRegistry, serviceRegistry));
    ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-provider-demo");
    applicationConfig.setMetadataType("remote");
    DubboBootstrap.getInstance().application(applicationConfig).registries(Arrays.asList(interfaceRegistry, serviceRegistry)).protocol(builder -> builder.port(-1).name("dubbo")).metadataReport(new MetadataReportConfig("zookeeper://127.0.0.1:2181")).service(echoService).service(userService).start().await();
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) Arrays(java.util.Arrays) UserServiceImpl(org.apache.dubbo.config.bootstrap.rest.UserServiceImpl) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) RegistryConfig(org.apache.dubbo.config.RegistryConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) MetadataReportConfig(org.apache.dubbo.config.MetadataReportConfig) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) ServiceConfig(org.apache.dubbo.config.ServiceConfig) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) UserServiceImpl(org.apache.dubbo.config.bootstrap.rest.UserServiceImpl) MetadataReportConfig(org.apache.dubbo.config.MetadataReportConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Example 2 with UserService

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

the class EtcdDubboServiceProviderBootstrap method multipleRegistries.

private static void multipleRegistries() {
    ProtocolConfig restProtocol = new ProtocolConfig();
    restProtocol.setName("rest");
    restProtocol.setId("rest");
    restProtocol.setPort(-1);
    RegistryConfig interfaceRegistry = new RegistryConfig();
    interfaceRegistry.setId("interfaceRegistry");
    interfaceRegistry.setAddress("etcd3://127.0.0.1:2379");
    RegistryConfig serviceRegistry = new RegistryConfig();
    serviceRegistry.setId("serviceRegistry");
    serviceRegistry.setAddress("etcd3://127.0.0.1:2379?registry-type=service");
    ServiceConfig<EchoService> echoService = new ServiceConfig<>();
    echoService.setInterface(EchoService.class.getName());
    echoService.setRef(new EchoServiceImpl());
    // echoService.setRegistries(Arrays.asList(interfaceRegistry, serviceRegistry));
    ServiceConfig<UserService> userService = new ServiceConfig<>();
    userService.setInterface(UserService.class.getName());
    userService.setRef(new UserServiceImpl());
    userService.setProtocol(restProtocol);
    // userService.setRegistries(Arrays.asList(interfaceRegistry, serviceRegistry));
    ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-provider-demo");
    // applicationConfig.setMetadataType("remote");
    DubboBootstrap.getInstance().application(applicationConfig).registries(Arrays.asList(interfaceRegistry, serviceRegistry)).protocol(builder -> builder.port(-1).name("dubbo")).service(echoService).service(userService).start().await();
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) UserServiceImpl(org.apache.dubbo.config.bootstrap.rest.UserServiceImpl) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Example 3 with UserService

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

the class ZookeeperDubboServiceConsumerBootstrap method main.

public static void main(String[] args) throws Exception {
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application("zookeeper-dubbo-consumer", app -> app.metadata(COMPOSITE_METADATA_STORAGE_TYPE)).registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181").parameter(REGISTRY_TYPE_KEY, SERVICE_REGISTRY_TYPE).useAsConfigCenter(true).useAsMetadataCenter(true)).reference("echo", builder -> builder.interfaceClass(EchoService.class).protocol("dubbo").services("zookeeper-dubbo-provider")).reference("user", builder -> builder.interfaceClass(UserService.class).protocol("rest")).start();
    EchoService echoService = bootstrap.getCache().get(EchoService.class);
    UserService userService = bootstrap.getCache().get(UserService.class);
    for (int i = 0; i < 5; i++) {
        Thread.sleep(2000L);
        System.out.println(echoService.echo("Hello,World"));
        System.out.println(userService.getUser(i * 1L));
    }
    bootstrap.stop();
}
Also used : COMPOSITE_METADATA_STORAGE_TYPE(org.apache.dubbo.common.constants.CommonConstants.COMPOSITE_METADATA_STORAGE_TYPE) REGISTRY_TYPE_KEY(org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_TYPE_KEY) SERVICE_REGISTRY_TYPE(org.apache.dubbo.common.constants.RegistryConstants.SERVICE_REGISTRY_TYPE) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) UserService(org.apache.dubbo.config.bootstrap.rest.UserService)

Example 4 with UserService

use of org.apache.dubbo.config.bootstrap.rest.UserService 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 5 with UserService

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

the class NacosDubboServiceConsumerBootstrap method main.

public static void main(String[] args) throws Exception {
    ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-nacos-consumer-demo");
    applicationConfig.setMetadataType(REMOTE_METADATA_STORAGE_TYPE);
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(applicationConfig).registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry-type=service").useAsConfigCenter(true).useAsMetadataCenter(true)).reference("echo", builder -> builder.interfaceClass(EchoService.class).protocol("dubbo")).reference("user", builder -> builder.interfaceClass(UserService.class).protocol("rest")).start();
    EchoService echoService = bootstrap.getCache().get(EchoService.class);
    UserService userService = bootstrap.getCache().get(UserService.class);
    for (int i = 0; i < 5; i++) {
        Thread.sleep(2000L);
        System.out.println(echoService.echo("Hello,World"));
        System.out.println(userService.getUser(i * 1L));
    }
}
Also used : REMOTE_METADATA_STORAGE_TYPE(org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) UserService(org.apache.dubbo.config.bootstrap.rest.UserService) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) UserService(org.apache.dubbo.config.bootstrap.rest.UserService)

Aggregations

UserService (org.apache.dubbo.config.bootstrap.rest.UserService)6 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)3 RegistryConfig (org.apache.dubbo.config.RegistryConfig)3 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)2 ServiceConfig (org.apache.dubbo.config.ServiceConfig)2 UserServiceImpl (org.apache.dubbo.config.bootstrap.rest.UserServiceImpl)2 Arrays (java.util.Arrays)1 COMPOSITE_METADATA_STORAGE_TYPE (org.apache.dubbo.common.constants.CommonConstants.COMPOSITE_METADATA_STORAGE_TYPE)1 DEFAULT_METADATA_STORAGE_TYPE (org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE)1 REMOTE_METADATA_STORAGE_TYPE (org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE)1 REGISTRY_TYPE_KEY (org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_TYPE_KEY)1 SERVICE_REGISTRY_TYPE (org.apache.dubbo.common.constants.RegistryConstants.SERVICE_REGISTRY_TYPE)1 MetadataReportConfig (org.apache.dubbo.config.MetadataReportConfig)1 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)1 EchoService (org.apache.dubbo.config.bootstrap.EchoService)1