Java Code Examples for org.apache.dubbo.config.ServiceConfig#setRef()

The following examples show how to use org.apache.dubbo.config.ServiceConfig#setRef() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Application.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ServiceConfig<UserService> service = new ServiceConfig<>();
    service.setInterface(UserService.class);
    service.setRef(new UserServiceImpl());

    ProtocolConfig protocolConfig = new ProtocolConfig("rest");
    protocolConfig.setPort(8090);

    DubboBootstrap bootstrap = DubboBootstrap.getInstance();
    bootstrap.application(new ApplicationConfig("dubbo-provider-for-sc"))
            .registry(new RegistryConfig("consul://127.0.0.1:8500?registry-type=service"))
            .protocol(protocolConfig)
            .service(service)
            .start()
            .await();
}
 
Example 2
Source File: Provider2.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ServiceConfig<GreetingsService> greetingsService = new ServiceConfig<>();
    greetingsService.setApplication(application);
    greetingsService.setConfigCenter(configCenter);
    greetingsService.setRegistry(registry);
    greetingsService.setInterface(GreetingsService.class);
    greetingsService.setRef(new GreetingsServiceImpl());
    greetingsService.export();

    ServiceConfig<DemoService> demoService = new ServiceConfig<>();
    demoService.setApplication(application);
    demoService.setConfigCenter(configCenter);
    demoService.setInterface(DemoService.class);
    demoService.setRegistry(registry);
    demoService.setRef(new DemoServiceImpl());
    demoService.export();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}
 
Example 3
Source File: GenericImplProvider.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    new EmbeddedZooKeeper(2181, false).start();

    ApplicationConfig applicationConfig = new ApplicationConfig();
    applicationConfig.setName("generic-impl-provider");
    RegistryConfig registryConfig = new RegistryConfig();
    registryConfig.setAddress(zookeeperAddress);

    GenericService helloService = new GenericImplOfHelloService();
    ServiceConfig<GenericService> service = new ServiceConfig<>();
    service.setApplication(applicationConfig);
    service.setRegistry(registryConfig);
    service.setInterface("org.apache.dubbo.samples.generic.call.api.HelloService");
    service.setRef(helloService);
    service.setGeneric("true");
    service.export();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}
 
Example 4
Source File: JbootDubborpc.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public <T> boolean serviceExport(Class<T> interfaceClass, Object object, JbootrpcServiceConfig config) {
    ServiceConfig<T> service = DubboUtil.toServiceConfig(config);
    service.setInterface(interfaceClass);
    service.setRef((T) object);

    String provider = rpcConfig.getProvider(interfaceClass.getName());
    if (provider != null) {
        service.setProvider(DubboUtil.getProvider(provider));
    }

    if (service.getGroup() == null) {
        service.setGroup(rpcConfig.getGroup(interfaceClass.getName()));
    }

    if (service.getVersion() == null) {
        service.setVersion(rpcConfig.getVersion(interfaceClass.getName()));
    }

    service.export();
    return true;
}
 
Example 5
Source File: ChronusAutoConfiguration.java    From chronus with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnBean({ApplicationConfig.class, RegistryConfig.class})
public ChronusSdkProcessor chronusSdkFacade() {
    ChronusSdkProcessor chronusClientFacade = new AbstractSdkService(){};
    ServiceConfig<ChronusSdkProcessor> serviceConfig = new ServiceConfig<>();
    serviceConfig.setApplication(applicationConfig);
    serviceConfig.setRegistry(registryConfig);
    serviceConfig.setInterface(ChronusSdkProcessor.class);
    serviceConfig.setRef(chronusClientFacade);
    serviceConfig.setPath("/" + applicationConfig.getName() + "/" + ChronusSdkProcessor.class.getName());
    //serviceConfig.setGroup(applicationConfig.getName());
    serviceConfig.export();
    return chronusClientFacade;
}
 
Example 6
Source File: DubboProvider.java    From alibabacloud-microservice-demo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ServiceConfig<GreetingsService> service = new ServiceConfig<>();
    service.setApplication(new ApplicationConfig("dubbo-provider"));
    service.setRegistry(new RegistryConfig("nacos://127.0.0.1:8848"));
    service.setInterface(GreetingsService.class);
    service.setRef(new GreetingsServiceImpl());
    service.export();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}
 
Example 7
Source File: Dubbo27ITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private static ServiceConfig<GreeterService> getService() {
  final ServiceConfig<GreeterService> service = new ServiceConfig<>();
  service.setApplication(new ApplicationConfig("test"));
  service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
  service.setProtocol(new ProtocolConfig("dubbo", TestUtil.nextFreePort()));
  service.setInterface(GreeterService.class);
  service.setRef(new GreeterServiceImpl());
  return service;
}
 
Example 8
Source File: Application.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ServiceConfig<GreetingsService> service = new ServiceConfig<>();
    service.setApplication(new ApplicationConfig("first-dubbo-provider"));
    service.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181"));
    service.setInterface(GreetingsService.class);
    service.setRef(new GreetingsServiceImpl());
    service.export();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}
 
Example 9
Source File: MonitorServiceIT.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Before
    public void setUp() throws Exception {
        ServiceConfig<MonitorService> service = new ServiceConfig<>();
        // FIXME: has to set application name to "demo-consumer"
        service.setApplication(new ApplicationConfig("demo-consumer"));
        service.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181"));
//        MonitorConfig monitorConfig = new MonitorConfig();
//        monitorConfig.setProtocol("registry");
//        monitorConfig.setInterval("100");
//        service.setMonitor(monitorConfig);
        service.setInterface(MonitorService.class);
        service.setFilter("-monitor");
        service.setRef(new MonitorServiceImpl());
        service.export();
    }
 
Example 10
Source File: Provider1.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ServiceConfig<GreetingsService> service = new ServiceConfig<>();
    service.setApplication(applicationConfig);
    service.setConfigCenter(configCenter);
    service.setInterface(GreetingsService.class);
    service.setRef(new GreetingsServiceImpl());
    service.export();
    System.out.println("dubbo service started");
    System.in.read();
}
 
Example 11
Source File: Provider.java    From rpcx-benchmark with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
    service.setApplication(new ApplicationConfig("dubbo-demo-api-provider"));
    String zk = "zookeeper://127.0.0.1:2181";
    if (args.length > 0) {
        zk = args[0];
    }
    service.setRegistry(new RegistryConfig(zk));
    service.setInterface(DemoService.class);
    service.setRef(new DemoServiceImpl());
    service.export();

    Thread.sleep(24 * 3600 * 1000);

}
 
Example 12
Source File: Application.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "unexport")
public ServiceConfig<GreetService> service() {
    ServiceConfig<GreetService> serviceConfig = new ServiceConfig<>();
    serviceConfig.setApplication(applicationConfig);
    serviceConfig.setRegistry(registryConfig);
    serviceConfig.setProtocol(protocolConfig);
    serviceConfig.setInterface(GreetService.class);
    serviceConfig.setRef(new GreetServiceImpl());
    serviceConfig.setTimeout(5000);
    serviceConfig.export();
    return serviceConfig;
}
 
Example 13
Source File: SslBasicProvider.java    From dubbo-samples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    new EmbeddedZooKeeper(2181, false).start();
    // wait for embedded zookeeper start completely.
    Thread.sleep(1000);

    SslConfig sslConfig = new SslConfig();
    if (args.length > 0) {
        if (args.length < 2 || args.length > 3) {
            System.out.println(
                    "USAGE: BasicProvider certChainFilePath privateKeyFilePath " +
                            "[trustCertCollectionFilePath]\n Specify 'trustCertCollectionFilePath' only if you want " +
                            "need Mutual TLS.");
            System.exit(0);
        }


        sslConfig.setServerKeyCertChainPath(args[0]);
        sslConfig.setServerPrivateKeyPath(args[1]);
        if (args.length == 3) {
            sslConfig.setServerTrustCertCollectionPath(args[2]);
        }
    }

    ProtocolConfig protocolConfig = new ProtocolConfig("dubbo");
    protocolConfig.setSslEnabled(true);

    DubboBootstrap bootstrap = DubboBootstrap.getInstance();
    bootstrap.application(new ApplicationConfig("ssl-provider"))
             .registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
             .protocol(protocolConfig)
             .ssl(sslConfig);

    ServiceConfig<DemoService> service = new ServiceConfig<>();
    service.setInterface(DemoService.class);
    service.setRef(new DemoServiceImpl());

    bootstrap.service(service);
    bootstrap.start();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}
 
Example 14
Source File: SslBasicProvider.java    From dubbo-samples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    new EmbeddedZooKeeper(2181, false).start();
    // wait for embedded zookeeper start completely.
    Thread.sleep(1000);

    SslConfig sslConfig = new SslConfig();
    if (args.length > 0) {
        if (args.length < 2 || args.length > 3) {
            System.out.println(
                    "USAGE: BasicProvider certChainFilePath privateKeyFilePath " +
                            "[trustCertCollectionFilePath]\n Specify 'trustCertCollectionFilePath' only if you want " +
                            "need Mutual TLS.");
            System.exit(0);
        }


        sslConfig.setServerKeyCertChainPath(args[0]);
        sslConfig.setServerPrivateKeyPath(args[1]);
        if (args.length == 3) {
            sslConfig.setServerTrustCertCollectionPath(args[2]);
        }
    }

    ProtocolConfig protocolConfig = new ProtocolConfig("grpc");
    protocolConfig.setSslEnabled(true);

    DubboBootstrap bootstrap = DubboBootstrap.getInstance();
    bootstrap.application(new ApplicationConfig("ssl-provider"))
             .registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
             .protocol(protocolConfig)
             .ssl(sslConfig);

    ServiceConfig<IGreeter> service = new ServiceConfig<>();
    service.setInterface(IGreeter.class);
    service.setRef(new GrpcGreeterImpl());

    bootstrap.service(service);
    bootstrap.start();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}