Before we build the project, let's take a look at the Eureka, which is an official explanation, and I'll look back at you for a moment:
Service Discovery: Eureka Client
Service discovery is one of the key principles of micro-service architecture. Trying to configure each client or some form of convention can be very difficult and very fragile. The Netflix service discovers that servers and clients are Eureka. Servers can be configured and deployed as high availability, and each server replicates the state of the enrollment service to other servers.
How to include Eureka clients
To include the Eureka client in your project, use the initiator of group Org.springframework.cloud and artifact ID spring-cloud-starter-eureka.
Register Eureka
When a client registers Eureka, it provides metadata about itself, such as host and port, health indicator URL, home page, and so on. Eureka receives heartbeat messages from each instance belonging to the service. If a heartbeat failure exceeds a configurable timesheet, the instance is typically removed from the registry.
Example Eureka Client:
@[email protected]@[email protected] @RestControllerpublic class Application { @RequestMapping ("/") public string home () { return "Hello world"; } public static void main (String[] args) { new springapplicationbuilder (Application.class). Web (True). Run (args); }}
(That is, the fully normal spring boot application). In this example, we explicitly use @enableeurekaclient, but only Eureka is available, and you can use @enablediscoveryclient. Configuration is required to locate the Eureka server. Cases:
Application.yml
eureka:client:serviceurl:defaultzone:http://localhost:8761/eureka/
where "Defaultzone" is a magic string fallback value that provides a service URL for any client that does not represent a preference (that is, it is a useful default value).
The default application name (service ID) obtained from environment, the virtual host and the unsecured port are ${spring.application.name},${spring.application.name} and ${server.port respectively }。
@EnableEurekaClient the application into a Eureka "instance" (that is, registering itself) and a "client" (that is, it can query the registry to find other services). The instance behavior is driven by the eureka.instance.* configuration key, but if you make sure that your application has spring.application.name (which is the default value for the Eureka Service ID or VIP), the default value will be normal.
Authenticate with the Eureka Server
If one of the Eureka.client.serviceUrl.defaultZone URLs contains a credential such as http://user:password@localhost:8761 /eureka)), HTTP Basic authentication is automatically added to your Eureka client. For more complex requirements, you can create Discoveryclientoptionalargs types of @bean and inject clientfilter instances into them, all of which will be applied to calls from the client to the server.
Note
Basic authentication credentials for each server cannot be supported due to limitations in Eureka, so only the first found collection can be used. The status page and health indicators for the
Status page and healthy metrics
Eureka instances default to "/info" and "/" respectively, which are the default locations for useful endpoints in the Spring boot executor application. If you use a non-default context path or a servlet path (for example, Server.servletpath=/foo) or manage the endpoint path (for example, management.contextpath=/admin), you need to change these, even for the executor application. Example:
APPLICATION.YML
Eureka:
instance:
Statuspageurlpath: ${management.context-path}/ Info
Healthcheckurlpath: ${management.context-path}/health
These links appear in the metadata used by the client, And in some cases, it is helpful to decide whether to send requests to the application, so if they are accurate.
Registering Secure applications
If your application wants to connect over HTTPS, it can be in eurekainstanceconfig, or eureka.instance, respectively. Two flags are set in [Nonsecureportenabled,secureportenabled]=[false,true]. This will enable Eureka Publishing instance information to display a clear preference for secure communications. Spring Cloud Discoveryclient will always return a https://for services configured in this way ...; URI, and the Eureka (native) instance information will have a secure health check URL.
Because of how Eureka works internally, it will still publish the status and non-secure URLs for the home page unless you explicitly overwrite them. You can use placeholders to configure Eureka instance URLs, such as
Application.yml
Eureka
Instance
Statuspageurl:https://${eureka.hostname}/info
Healthcheckurl:https://${eureka.hostname}/health
homepageurl:https://${eureka.hostname}/
(Note that ${eureka.hostname} is a local placeholder that is only available in later versions of Eureka, and you can use the spring placeholder for the same functionality, such as using ${eureka.instance.hostname}. Source of information source
Integrated Spring Cloud Cloud service Architecture-Eureka Foundation (top)