org.apache.dubbo.config.ProtocolConfig Java Examples

The following examples show how to use org.apache.dubbo.config.ProtocolConfig. 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: TestServer.java    From brave with Apache License 2.0 6 votes vote down vote up
TestServer(Propagation.Factory propagationFactory, ApplicationConfig application) {
  extractor = propagationFactory.get().extractor(Map::get);
  linkLocalIp = Platform.get().linkLocalIp();
  if (linkLocalIp != null) {
    // avoid dubbo's logic which might pick docker ip
    System.setProperty(CommonConstants.DUBBO_IP_TO_BIND, linkLocalIp);
    System.setProperty(Constants.DUBBO_IP_TO_REGISTRY, linkLocalIp);
  }
  service = new ServiceConfig<>();
  service.setApplication(application);
  service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
  service.setProtocol(new ProtocolConfig("dubbo", PickUnusedPort.get()));
  service.setInterface(GreeterService.class);
  service.setRef((method, parameterTypes, args) -> {
    requestQueue.add(extractor.extract(RpcContext.getContext().getAttachments()));
    return args[0];
  });
}
 
Example #2
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 #3
Source File: BinderDubboConfigBinderTest.java    From dubbo-spring-boot-project with Apache License 2.0 6 votes vote down vote up
@Test
public void testBinder() {

    ApplicationConfig applicationConfig = new ApplicationConfig();
    Map<String, Object> properties = getSubProperties(environment.getPropertySources(), "dubbo.application");
    dubboConfigBinder.bind(properties, true, true, applicationConfig);
    Assert.assertEquals("hello", applicationConfig.getName());
    Assert.assertEquals("world", applicationConfig.getOwner());

    RegistryConfig registryConfig = new RegistryConfig();
    properties = getSubProperties(environment.getPropertySources(), "dubbo.registry");
    dubboConfigBinder.bind(properties, true, true, registryConfig);
    Assert.assertEquals("10.20.153.17", registryConfig.getAddress());

    ProtocolConfig protocolConfig = new ProtocolConfig();
    properties = getSubProperties(environment.getPropertySources(), "dubbo.protocol");
    dubboConfigBinder.bind(properties, true, true, protocolConfig);
    Assert.assertEquals(Integer.valueOf(20881), protocolConfig.getPort());
}
 
Example #4
Source File: DubboConfigsMetadata.java    From dubbo-spring-boot-project with Apache License 2.0 6 votes vote down vote up
public Map<String, Map<String, Map<String, Object>>> configs() {

        Map<String, Map<String, Map<String, Object>>> configsMap = new LinkedHashMap<>();

        addDubboConfigBeans(ApplicationConfig.class, configsMap);
        addDubboConfigBeans(ConsumerConfig.class, configsMap);
        addDubboConfigBeans(MethodConfig.class, configsMap);
        addDubboConfigBeans(ModuleConfig.class, configsMap);
        addDubboConfigBeans(MonitorConfig.class, configsMap);
        addDubboConfigBeans(ProtocolConfig.class, configsMap);
        addDubboConfigBeans(ProviderConfig.class, configsMap);
        addDubboConfigBeans(ReferenceConfig.class, configsMap);
        addDubboConfigBeans(RegistryConfig.class, configsMap);
        addDubboConfigBeans(ServiceConfig.class, configsMap);

        return configsMap;

    }
 
Example #5
Source File: RelaxedDubboConfigBinderTest.java    From dubbo-spring-boot-project with Apache License 2.0 6 votes vote down vote up
@Test
public void testBinder() {

    ApplicationConfig applicationConfig = new ApplicationConfig();
    Map<String, Object> properties = getSubProperties(environment.getPropertySources(), "dubbo.application");
    dubboConfigBinder.bind(properties, true, true, applicationConfig);
    Assert.assertEquals("hello", applicationConfig.getName());
    Assert.assertEquals("world", applicationConfig.getOwner());

    RegistryConfig registryConfig = new RegistryConfig();
    properties = getSubProperties(environment.getPropertySources(), "dubbo.registry");
    dubboConfigBinder.bind(properties, true, true,  registryConfig);
    Assert.assertEquals("10.20.153.17", registryConfig.getAddress());

    ProtocolConfig protocolConfig = new ProtocolConfig();
    properties = getSubProperties(environment.getPropertySources(), "dubbo.protocol");
    dubboConfigBinder.bind(properties, true, true,  protocolConfig);
    Assert.assertEquals(Integer.valueOf(20881), protocolConfig.getPort());

}
 
Example #6
Source File: MockServer.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
MockServer() {
  linkLocalIp = NetUtils.getLocalAddress().getHostAddress();
  if (linkLocalIp != null) {
    // avoid dubbo's logic which might pick docker ip
    System.setProperty(Constants.DUBBO_IP_TO_BIND, linkLocalIp);
    System.setProperty(Constants.DUBBO_IP_TO_REGISTRY, linkLocalIp);
  }

  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());
}
 
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: DubboConfigurationProperties.java    From dubbo-spring-boot-project with Apache License 2.0 4 votes vote down vote up
public Map<String, ProtocolConfig> getProtocols() {
    return protocols;
}
 
Example #9
Source File: DubboConfigurationProperties.java    From dubbo-spring-boot-project with Apache License 2.0 4 votes vote down vote up
public void setProtocols(Map<String, ProtocolConfig> protocols) {
    this.protocols = protocols;
}
 
Example #10
Source File: DubboAutoConfigurationOnMultipleConfigTest.java    From dubbo-spring-boot-project with Apache License 2.0 4 votes vote down vote up
@Test
public void testApplicationContext() {

    /**
     * Multiple {@link ApplicationConfig}
     */
    Map<String, ApplicationConfig> applications = beansOfTypeIncludingAncestors(applicationContext, ApplicationConfig.class);

    Assert.assertEquals(1, applications.size());

    /**
     * Multiple {@link ModuleConfig}
     */
    Map<String, ModuleConfig> modules = beansOfTypeIncludingAncestors(applicationContext, ModuleConfig.class);

    Assert.assertEquals(1, modules.size());

    /**
     * Multiple {@link RegistryConfig}
     */
    Map<String, RegistryConfig> registries = beansOfTypeIncludingAncestors(applicationContext, RegistryConfig.class);

    Assert.assertEquals(1, registries.size());

    /**
     * Multiple {@link ProtocolConfig}
     */
    Map<String, ProtocolConfig> protocols = beansOfTypeIncludingAncestors(applicationContext, ProtocolConfig.class);

    Assert.assertEquals(1, protocols.size());

    /**
     * Multiple {@link MonitorConfig}
     */
    Map<String, MonitorConfig> monitors = beansOfTypeIncludingAncestors(applicationContext, MonitorConfig.class);

    Assert.assertEquals(1, monitors.size());

    /**
     * Multiple {@link ProviderConfig}
     */
    Map<String, ProviderConfig> providers = beansOfTypeIncludingAncestors(applicationContext, ProviderConfig.class);

    Assert.assertEquals(1, providers.size());

    /**
     * Multiple {@link ConsumerConfig}
     */
    Map<String, ConsumerConfig> consumers = beansOfTypeIncludingAncestors(applicationContext, ConsumerConfig.class);

    Assert.assertEquals(1, consumers.size());

}
 
Example #11
Source File: DubboConfigurationProperties.java    From dubbo-spring-boot-project with Apache License 2.0 4 votes vote down vote up
public void setProtocol(ProtocolConfig protocol) {
    this.protocol = protocol;
}
 
Example #12
Source File: DubboHealthIndicator.java    From dubbo-spring-boot-project with Apache License 2.0 4 votes vote down vote up
private Map<String, String> resolveStatusCheckerNamesMapFromProtocolConfigs() {

        Map<String, String> statusCheckerNamesMap = new LinkedHashMap<>();

        for (Map.Entry<String, ProtocolConfig> entry : protocolConfigs.entrySet()) {

            String beanName = entry.getKey();

            ProtocolConfig protocolConfig = entry.getValue();

            Set<String> statusCheckerNames = getStatusCheckerNames(protocolConfig);

            for (String statusCheckerName : statusCheckerNames) {

                String source = buildSource(beanName, protocolConfig);

                statusCheckerNamesMap.put(statusCheckerName, source);

            }

        }

        return statusCheckerNamesMap;

    }
 
Example #13
Source File: DubboHealthIndicator.java    From dubbo-spring-boot-project with Apache License 2.0 4 votes vote down vote up
private Set<String> getStatusCheckerNames(ProtocolConfig protocolConfig) {
    String status = protocolConfig.getStatus();
    return StringUtils.commaDelimitedListToSet(status);
}
 
Example #14
Source File: DubboConfigurationProperties.java    From dubbo-spring-boot-project with Apache License 2.0 4 votes vote down vote up
public ProtocolConfig getProtocol() {
    return protocol;
}
 
Example #15
Source File: AbstractDubboMetadata.java    From dubbo-spring-boot-project with Apache License 2.0 4 votes vote down vote up
protected Map<String, ProtocolConfig> getProtocolConfigsBeanMap() {
    return beansOfTypeIncludingAncestors(applicationContext, ProtocolConfig.class);
}
 
Example #16
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 #17
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 #18
Source File: DubboProtocolConfigSupplier.java    From spring-cloud-alibaba with Apache License 2.0 4 votes vote down vote up
public DubboProtocolConfigSupplier(
		ObjectProvider<Collection<ProtocolConfig>> protocols) {
	this.protocols = protocols;
}
 
Example #19
Source File: DubboMetadataAutoConfiguration.java    From spring-cloud-alibaba with Apache License 2.0 4 votes vote down vote up
@Bean
public Supplier<ProtocolConfig> dubboProtocolConfigSupplier(
		ObjectProvider<Collection<ProtocolConfig>> protocols) {
	return new DubboProtocolConfigSupplier(protocols);
}
 
Example #20
Source File: ApacheDubboInstrumentationTest.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@Override
protected DubboTestApi buildDubboTestApi() {
    ApplicationConfig providerAppConfig = new ApplicationConfig();
    providerAppConfig.setName("dubbo-demo");

    ProtocolConfig protocolConfig = new ProtocolConfig();
    protocolConfig.setName("dubbo");
    protocolConfig.setPort(getPort());
    protocolConfig.setThreads(10);

    RegistryConfig registryConfig = new RegistryConfig();
    registryConfig.setAddress("N/A");

    serviceConfig = new ServiceConfig<>();
    serviceConfig.setApplication(providerAppConfig);
    serviceConfig.setProtocol(protocolConfig);
    serviceConfig.setInterface(DubboTestApi.class);
    serviceConfig.setRef(new DubboTestApiImpl());
    serviceConfig.setRegistry(registryConfig);
    serviceConfig.export();

    referenceConfig = new ReferenceConfig<>();
    referenceConfig.setApplication(providerAppConfig);
    referenceConfig.setInterface(DubboTestApi.class);
    referenceConfig.setUrl("dubbo://localhost:" + getPort());
    referenceConfig.setTimeout(3000);

    List<MethodConfig> methodConfigList = new LinkedList<>();
    referenceConfig.setMethods(methodConfigList);

    MethodConfig asyncConfig = new MethodConfig();
    asyncConfig.setName("async");
    asyncConfig.setAsync(true);
    methodConfigList.add(asyncConfig);

    MethodConfig asyncNoReturnConfig = new MethodConfig();
    asyncNoReturnConfig.setName("asyncNoReturn");
    asyncNoReturnConfig.setAsync(true);
    asyncNoReturnConfig.setReturn(false);
    methodConfigList.add(asyncNoReturnConfig);

    return referenceConfig.get();
}