Introduction to the
Eureka service Registry is a service highly available solution provided by Netflix open source organization. In the front-end time, the problem of 2.0 open source abortion has been widely circulated, but it does not affect our use. Netflix just no longer maintains the open source code of 2.0 branch, so it makes a disclaimer. However, this is a real concern for us, and many of us are switching service registries, such as Zookeeper and Consul.
Of course, the Eureka 2.0 miscarriage should be treated as a farce, since springCloud.finchley.sr1 relies on Eureka 1.9.3, so there is no need to consider this. Let’s focus on how we design our distributed microservices architecture system.
Build the project
As we built the project before, use idea tool to directly create a new SpringBoot project, check Cloud Discovert -> Eureka Server dependency on the interface of dependency selection, and the content of the poM. XML configuration file after creation is as follows:
. </groupId> org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> The < version > at 2.0.5. RELEASE < / version > < relativePath / > <! -- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> < project. Reporting. OutputEncoding > utf-8 < / project. Reporting. OutputEncoding > < Java version > 1.8 < / Java version > <! < SpringCloud. Version > finchley. SR1</ SpringCloud. Version > </properties> <dependencies> <! - Netflix had been relying on - > < the dependency > < groupId > org. Springframework. Cloud < / groupId > <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> </dependencies> <! - SpringCloud rely on version management - > < dependencyManagement > < dependencies > < the dependency > < groupId > org. Springframework. Cloud < / groupId > <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version>
<type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> ... // omit partCopy the code
When we create a new project, if the relevant SpringCloud dependency is selected, the SpringCloud latest stable version dependency configuration is automatically added to the POM.xml configuration file.
in Maven
in Maven
The version information set in < Dependency > under
is used by default. This is why, after adding the Spring-cloud-dependencies dependency, we can import the dependencies of the specified version without adding the version tag when using the relevant SpringCloud plug-in.
Configure the Eureka Server
After adding the spring-cloud-starter-Netflix-Eureka-server dependency, let’s see how to start the Eureka Server service. Starting the Registry server for Eureka is relatively simple and requires only two changes.
- The first place is to add an enable on the entry class
Eureka Server
annotations@EnableEurekaServer
, as follows:
@SpringBootApplication
@EnableEurekaServer
public class SpringCloudEurekaApplication {
// main method
}
Copy the code
- The second place is application. Yml/application. The properties file to add basic information configuration, as shown below:
# service name
spring:
application:
name: hengboy-spring-cloud-eureka
# Service port number
server:
port: 10000
#Eureka configuration
eureka:
client:
service-url:
defaultZone: http://localhost:${server.port}/eureka/
Whether to synchronize the service list from other service centers
fetch-registry: false
# Whether to register yourself as a service in another service registry
register-with-eureka: false
Copy the code
- Spring.application. name: service name
- Server. port: indicates the service port number
- Eureka.client.service-url. defaultZone: indicates the default configuration of the eureka service address space
- Eureka. Client. fetch-registry: Whether to synchronize the service list from other Eureka registries (single-node configuration does not need to be enabled).
- Register-with-eureka: specifies whether to register itself as a service with other Eureka service registries (single-node configuration is not required).
Run the test
Now that we have integrated the dependencies and configurations required by the Eureka server, let’s run the test to see what works. Eureka provides us with a nice management interface that allows us to view the list of registered services and service status.
Test steps:
- through
Application
Mode to startEureka Server
- Access from the local browser
http://localhost:10000
, 10000 is the port number of ourapplication.yml
Set in the configuration fileserver.port
The value of the.- Successful access to
Eureka Server
Management interface
The interface is as follows:
We can see some Eureka Server health data and basic information on the interface, such as:
server-uptime
: Indicates the startup timecurrent-memory-usage
: Indicates the total amount of memory currently occupiedInstances currently registered with Eureka
: List of services registered with the centeripAddr
: the currentEureka Server
If no IP address is configuredeureka.instance.ip-address
So use the default IP address here. .
conclusion
This chapter introduces the configuration of Eureka as a Server. The configuration steps are relatively simple and there are not so many complicated places. Of course, this is only the configuration of a single Eureka service node.
Face to face with Hengyu youth
If you like heng Yu teenager related articles, then go to wechat public number (Heng Yu teenager) follow me!! Of course, you can also go to SpringCloud code cloud source code project at the bottom of the qr code to follow me, thank you for reading!!
Study catalog recommendation
- SpringBoot matching source address: access code cloud view source code, access GitHub view source code
- SpringCloud matching source address: access code cloud view source code
- For SpringBoot related articles, visit: Directory: SpringBoot learning directory
- For a series of QueryDSL articles, visit the QueryDSL Generic Query Framework learning directory
- For articles in the SpringDataJPA series, visit: Directory: SpringDataJPA Learning directory
Open source information
During this period of time, I have been writing relevant open source frameworks, devoting myself to the framework upgrade and open source plan used by the company, and upgrading and reconstructing the tools and plug-ins used by the company and opening source.
- Code Builder
code-builder
Code generators are based on the template files you provide (currently supportedfreemarker
) automatically generate entity classes, can greatly improve the efficiency of development.Gitee address
:Gitee.com/hengboy/cod…Making the address
:Github.com/hengyuboy/c… - Persistence Framework (MyBatis-Enhance)
mybatis-enhance
Is a rightmybatis
The enhanced encapsulation of the framework provides a series of internal methods to perform operations on single-table data, and multi-table data is providedDSL
Mode to perform operations.Gitee address
:Gitee.com/hengboy/myb…Making the address
:Github.com/hengyuboy/m… - Automatic paging plug-in
MyBatis-Pageable
Is a plug-in for automatic paging, based onMyBatis
Internal pluginsInterceptor
Interceptor written, interceptExecutor.query
The two overloaded methods of compute the paging information as well as the database based on the configurationDialect
Automatic execution of different query statements to complete the total number of statistics.Gitee address
:Gitee.com/hengboy/myb…