Skip to content

Fluent -style builder API support. #3431

Closed

Description

@chickenlj

I am thinking of providing a fluent -style builder API built on ServiceConfig, ReferenceConfig, ...
It may work like this:

ApplicationConfig applicationConfig = ApplicationBuilder.name("demo").build();

ServiceConfig serviceConfig = ServiceBuilder.ref(ref).timeout(1000).build();
ReferenceConfig referenceConfig = ReferenceBuilder.interface("interface name").timeout(2000).build();

DubboBuilder dubboBuilder = DubboBuilder.application(applicationConfig).registry(registryConfig).protocol(protocol);

// To trigger the export/refer process, you can just start dubboBuilder
dubboBuilder.services(Arrays.asList(serviceConfig)).references(Arrays.asList(referenceConfig)).start();
// Or, you can export/refer one specific Service or Reference
dubboBuilder.export(serviceConfig);
dubboBuilder.refer(referenceConfig);

At present, one of the problems of using ServiceConfig and ReferenceConfig directly is that some application-level configurations need to be set to each ServiceConfig or ReferenceConfig, which is redundant, unnecessary and inconvenient for users

ApplicationConfig application = new ApplicationConfig();

ServiceConfig serviceConfig1 = new ServiceConfig();
serviceConfig1.setApplication(application);
serviceConfig1.export();

ServiceConfig serviceConfig2 = new ServiceConfig();
serviceConfig2.setApplication(application);
serviceConfig2.export();

Activity

  1. added
    help wanted
    on Feb 3, 2019
  2. kun-song commented on Feb 3, 2019

    @kun-song
    Contributor

    Good idea!

  3. xxlv commented on Feb 7, 2019

    @xxlv

    Cool,I love it

  4. Kiddinglife commented on Feb 8, 2019

    @Kiddinglife

    nice

  5. tswstarplanet commented on Feb 8, 2019

    @tswstarplanet
    Contributor

    I think the export and refer method of DubboBuilder can provider overload methods such as

    DubboBuilder.export(ServiceConfig service,  ProviderConfig provider, RegistryConfig registry)
    java
    if users would like to refer specific config to a service or a reference. They can config by themselves.
  6. chickenlj commented on Feb 12, 2019

    @chickenlj
    ContributorAuthor

    DubboBuilder.export(ServiceConfig service, ProviderConfig provider, RegistryConfig registry)
    java
    if users would like to refer specific config to a service or a reference. They can config by themselves.

    I would suggest providing the service-restricted configs using ServiceConfigBuilder:
    ServiceConfigBuilder.provider(The ProviderConfig).registry(The RegistryConfig).build()

    What do you think? @tswstarplanet

  7. chickenlj commented on Feb 13, 2019

    @chickenlj
    ContributorAuthor

    Is there anyone who's interested and want to give it a try?

  8. tswstarplanet commented on Feb 14, 2019

    @tswstarplanet
    Contributor

    Yes, it looks good. We should also limit reproduction of global configs, such as application.

  9. Bricks-Man commented on Feb 15, 2019

    @Bricks-Man
    Contributor

    I want to try this issue.And I will commit a pr after serveral days

  10. chickenlj commented on Feb 15, 2019

    @chickenlj
    ContributorAuthor

    Yes, it looks good. We should also limit reproduction of global configs, such as application.

    Yes, the ConfigManager introduced in 2.7.0 can achieve that, but it may have some room for improvement.

  11. chickenlj commented on Feb 15, 2019

    @chickenlj
    ContributorAuthor

    @Bricks-Man Awesome, please let me know if you have any problem.

  12. chickenlj commented on Feb 15, 2019

    @chickenlj
    ContributorAuthor

    Further thought on this topic.

    A unified entry like DubboBuilder.start() can help us with:

    1. Application level rules. You may have noticed of some application level rules introduced in 2.7.0. The rules are fetched and watched inside each Service, I think it would be better if we can have an application level place to do that.
    2. Adapting to microservice architecture. The microservice model is one microservice per process which is different from Dubbo's interface level service model. A unified entry would make the application level service discovery model more easily achieved.
  13. Bricks-Man commented on Feb 22, 2019

    @Bricks-Man
    Contributor

    @chickenlj I have finished this issue.Could you have time to do a review for it?Please tell me if you have any question.

  14. modified the milestones: 2.7.1, 2.7.2 on Mar 14, 2019
  15. cvictory commented on May 20, 2019

    @cvictory
    Contributor
  16. modified the milestones: 2.7.2, 2.7.3 on May 20, 2019
  17. modified the milestones: 2.7.3, 2.7.4 on Jun 18, 2019
  18. modified the milestones: 2.7.4, 2.7.5 on Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

help wanted

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions