Spring Cloud Commons General Abstraction

Source: Internet
Author: User

Patterns such as service discovery, load balancing, and circuit breakers apply to the common abstraction layer that all spring cloud clients can consume independently of implementations (for example, through Eureka or consul Discovery).

@EnableDiscoveryClient
Commons provides @enablediscoveryclient annotations. This finds the implementation of the Discoveryclient interface through Meta-inf/spring.factories. Discovery The implementation of the client will add a configuration class in the spring.factories under the Org.springframework.cloud.client.discovery.EnableDiscoveryClient key. Examples of discoveryclient implementations are spring cloud Netflix eureka,spring Cloud Consul Discovery and Spring Cloud zookeeper discovery.

By default, the implementation of Discoveryclient will automatically register the local spring boot server with the remote discovery server. You can disable this feature by setting Autoregister=false in @enablediscoveryclient.

Serviceregistry
Commons now provides a serviceregistry interface that provides methods such as register (registration) and deregister (registration) that allow you to provide custom registration services. Registration is a markup interface.

@Configurationbr/> @EnableDiscoveryClient (autoregister=false)

Private Serviceregistry Registry;

public MyConfiguration(ServiceRegistry registry) {    this.registry = registry;}// called via some external process, such as an event or a custom actuator endpointpublic void register() {    Registration registration = constructRegistration();    this.registry.register(registration);}

}
Each serviceregistry implementation has its own registry implementation.

Automatic Registration of service department

By default, the Serviceregistry implementation automatically registers the service that is running. There are two ways to disable this behavior. You can set @enablediscoveryclient (autoregister=false) to permanently disable autoenrollment. You can also set Spring.cloud.service-registry.auto-registration.enabled=false to disable this behavior through configuration.

Service Register Executor Endpoint

The Commons provides a/service-registry actuator endpoint. The endpoint relies on the registration bean in the context of the spring application. Calling/service-registry/instance-status via get will return the state of registration. The post of the same endpoint with the string body changes the state of the current registration to a new value. See the documentation that you are using for the serviceregistry implementation to get the allowed values for the update status and the values obtained for the state.

Spring Cloud Commons General Abstraction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.