org.apache.dubbo.config.bootstrap.DubboBootstrap Java Examples

The following examples show how to use org.apache.dubbo.config.bootstrap.DubboBootstrap. 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: SslBasicConsumer.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    SslConfig sslConfig = new SslConfig();
    if (args.length > 0) {
        if (args.length != 1 && args.length != 3) {
            System.out.println(
                    "USAGE: BasicConsumer [trustCertCollectionFilePath [certChainFilePath privateKeyFilePath]]\n " +
                            "Specify 'certChainFilePath' and 'privateKeyFilePath' only if you need Mutual TLS.");
            System.exit(0);
        }

        switch (args.length) {
            case 1:
                sslConfig.setClientTrustCertCollectionPath(args[0]);
                break;
            case 3:
                sslConfig.setClientTrustCertCollectionPath(args[0]);
                sslConfig.setClientKeyCertChainPath(args[1]);
                sslConfig.setClientPrivateKeyPath(args[2]);
        }
    }

    DubboBootstrap bootstrap = DubboBootstrap.getInstance()
            .application(new ApplicationConfig("first-dubbo-consumer"))
            .registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
            .ssl(sslConfig);

    ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
    reference.setInterface(DemoService.class);

    bootstrap.reference(reference);

    bootstrap.start();

    DemoService service = bootstrap.getCache().get(reference);
    String message = service.sayHello("dubbo");
    System.out.println(message);
}
 
Example #3
Source File: SslBasicConsumer.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    SslConfig sslConfig = new SslConfig();
    if (args.length > 0) {
        if (args.length != 1 && args.length != 3) {
            System.out.println(
                    "USAGE: BasicConsumer [trustCertCollectionFilePath [certChainFilePath privateKeyFilePath]]\n " +
                            "Specify 'certChainFilePath' and 'privateKeyFilePath' only if you need Mutual TLS.");
            System.exit(0);
        }

        switch (args.length) {
            case 1:
                sslConfig.setClientTrustCertCollectionPath(args[0]);
                break;
            case 3:
                sslConfig.setClientTrustCertCollectionPath(args[0]);
                sslConfig.setClientKeyCertChainPath(args[1]);
                sslConfig.setClientPrivateKeyPath(args[2]);
        }
    }

    DubboBootstrap bootstrap = DubboBootstrap.getInstance()
            .application(new ApplicationConfig("first-dubbo-consumer"))
            .registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
            .ssl(sslConfig);

    ReferenceConfig<IGreeter> reference = new ReferenceConfig<>();
    reference.setInterface(IGreeter.class);

    bootstrap.reference(reference);

    bootstrap.start();

    IGreeter service = bootstrap.getCache().get(reference);
    HelloReply helloReply = service.sayHello(HelloRequest.newBuilder().setName("dubbo").build());
    System.out.println(helloReply.getMessage());
}
 
Example #4
Source File: ITTracingFilter_Consumer.java    From brave with Apache License 2.0 5 votes vote down vote up
@Before public void setup() {
  server.start();

  String url = "dubbo://" + server.ip() + ":" + server.port() + "?scope=remote&generic=bean";
  client = new ReferenceConfig<>();
  client.setGeneric("true");
  client.setFilter("tracing");
  client.setInterface(GreeterService.class);
  client.setUrl(url);

  wrongClient = new ReferenceConfig<>();
  wrongClient.setGeneric("true");
  wrongClient.setFilter("tracing");
  wrongClient.setInterface(GraterService.class);
  wrongClient.setUrl(url);

  DubboBootstrap.getInstance().application(application)
      .reference(client)
      .reference(wrongClient)
      .start();

  init();

  // perform a warmup request to allow CI to fail quicker
  client.get().sayHello("jorge");
  server.takeRequest();
  testSpanHandler.takeRemoteSpan(CLIENT);
}
 
Example #5
Source File: ITTracingFilter_Provider.java    From brave with Apache License 2.0 5 votes vote down vote up
@Before public void setup() {
  server.service.setFilter("tracing");
  server.service.setGeneric("true");
  server.service.setInterface(GreeterService.class);
  server.service.setRef((method, parameterTypes, args) -> {
    String arg = (String) args[0];
    if (arg.equals("bad")) throw new IllegalArgumentException("bad");
    return currentTraceContext.get() != null
        ? currentTraceContext.get().traceIdString()
        : "";
  });
  init();
  server.start();

  String url = "dubbo://" + server.ip() + ":" + server.port() + "?scope=remote&generic=bean";
  client = new ReferenceConfig<>();
  client.setGeneric("true");
  client.setInterface(GreeterService.class);
  client.setUrl(url);

  DubboBootstrap.getInstance().application(application)
      .service(server.service)
      .reference(client)
      .start();

  // perform a warmup request to allow CI to fail quicker
  client.get().sayHello("jorge");
  testSpanHandler.takeRemoteSpan(SERVER);
}
 
Example #6
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 #7
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();
}
 
Example #8
Source File: DubboUtil.java    From jboot with Apache License 2.0 4 votes vote down vote up
public static void stopDubbo() {
    DubboBootstrap.getInstance().stop();
}