In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to carry out Eureka writing service, in view of this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
1) create a project to register with Eureka
Now that the registry is created and started, we implement to register a service provider eureka-client-user-service with Eureka and provide an interface to other service invocations.
First, create a Maven project, and then add related dependencies to pom.xml, as shown below.
Org.springframework.bootspring-boot-starter-parent2.0.6.RELEASEorg.springframework.bootspring-boot-starter-weborg.springframework.cloudspring-cloud-starter-netflix-eureka-clientorg.springframework.cloudspring-cloud-dependenciesFinchley.SR2pomimport
Create a startup class, App, with the following code.
@ SpringBootApplication@EnableDiscoveryClientpublic class App {public static void main (String [] args) {SpringApplication.run (App.class, args);}}
The method of starting the class is not much different from that before, except that the annotation is replaced by @ EnableDiscoveryClient, indicating that the current service is a client of Eureka.
Next, create an application.properties properties file under src/main/resources and add the following configuration:
Spring.application.name= eureka-client-user-serviceserver.port=8081eureka.client.serviceUrl.defaultZone= http://localhost:8761/eureka/# uses IP registration eureka.instance.preferIpAddress=true# to define instance ID format eureka.instance.instance-id=$ {spring.application.name}: ${spring.cloud.client.ip-address}: ${server.port}
The address of eureka.client.serviceUrl.defaultZone is the address of the Eureka service that we started earlier, and we need to register our own information with Eureka when starting.
By executing the App startup service, we can see that there is a log in the console that outputs the registration information:
DiscoveryClient_EUREKA-CLIENT-USER-SERVICE/eureka-client-user-service:192.168.31.245:8081-registration status: 204
We can further check whether the service is registered successfully. Go back to the Web console of Eureka that you opened earlier, refresh the page, and you can see the newly registered service information.
2) write and provide interface
Create a Controller that provides an interface to other service queries, as shown below.
@ RestControllerpublic class UserController {@ GetMapping ("/ user/hello") public String hello () {return "hello";}}
Restart the service and visit http://localhost:8081/user/hello (http://localhost%EF%BC%9A8081/user/hello)). If you can see the Hello string we returned, it proves that the interface has been provided successfully.
This is the answer to the question about how to write Eureka service. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.