In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "basic deployment tutorial of eureka+zuul in Micro Services". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and study the "basic deployment tutorial of eureka+zuul in Micro Services".
Some time ago, when I encountered a work crisis, I almost realized the importance of technology, so I began to understand and learn about micro-services on the advice of the company architect. The first thing I learned was the zuul gateway and the eureka registry. Because there was a lot of work and development during the day, I had to study at night. Now I can simply deploy a set of environment and run it successfully. Although these can be regarded as scratching the surface for the veteran, it is still a pleasure for me.
On the relevant introduction of zuul and eureka, I will not say more about a large number of search, directly on the configuration.
1. First create the Spring boot.
Next, change the project name.
And then continue to the next step, I directly skip the selection of components in the middle, or add it in pom after creation.
two。 Introduce dependency
Eureka:
Org.springframework.cloud spring-cloud-starter-netflix-eureka-client
Dome1 、 dome2:
Org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.boot spring-boot-starter-web
3. Startup class annotation
Eureka:
@ EnableEurekaServer
Zuul:
@ EnableZuulProxy
Dome1 、 dome2:
@ EnableEurekaClient
4: configuration fil
Eureka:application.properties
Whether server.port=8080eureka.instance.hostname=127.0.0.1# registers its own eureka.client.register-with-eureka=false# with the service center, retrieves the configuration content of the service eureka.client.fetch-registry=falseeureka.instance.prefer-ip-address=true# service registry, and specifies the location of the service registry eureka.client.service-url.defaultZone= http://${eureka.instance.hostname}:${server.port}/eureka/
Zuul:application.yml
Server: port: 8084 # Service port spring: application: name: api-zuul # Service name eureka: client: registry-fetch-interval-seconds: 5 # cycle of getting service list: 5s service-url: defaultZone: http://127.0.0.1:8080/eureka # eureka address zuul: prefix: / api # add routing prefix all access routes plus this prefix retryable: true # whether it is on Enable retry function routes: api: # casually use path: / service/** # access address with service request will be forwarded to service-provider-A serviceId: service-provider-A # if both service names are registered with service-provider-A to eureka Zuul will forward it randomly.
Dome1, dome2:application.properties (different ports, same service name)
# Registration address of the registry eureka.client.service-url.defaultZone= http://127.0.0.1:8080/eureka/# service name-- the method spring.application.name=service-provider-Aserver.port=8081 that invokes the service based on its name when called
The above configuration is cloud load balancer configuration. Reverse proxy can add a name to the configuration under routes in zuul, and path and serviceid can be another service name.
Dome1 and dome2 each need to create a test class.
Package com.example.eurekaclientdemo.controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import java.util.HashMap;import java.util.Map;@RequestMapping ("/ users") @ RestControllerpublic class UserController {@ GetMapping ("/ {name}") public Map getUser (@ PathVariable ("name") String userName) {Map data = new HashMap () Data.put ("id", userName); data.put ("from", "provider-A-1"); return data;}} package com.example.eurekaclient2demo.controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import java.util.HashMap;import java.util.Map @ RequestMapping ("/ users") @ RestControllerpublic class UserController {@ GetMapping ("/ {name}") public Map getUser (@ PathVariable ("name") String userName) {Map data = new HashMap (); data.put ("id", userName); data.put ("from", "provider-A-2"); return data;}}
After the above configuration is completed, start eureka, zuul, dome1, and dome2 in turn. View registered services after entering http://127.0.0.1:8080 in the browser
Then type http://127.0.0.1:8084/api/service/users/sdffsd in the browser and need to refresh to see the effect.
Thank you for your reading. the above is the content of the basic deployment tutorial of eureka+zuul in Micro Services. After the study of this article, I believe you have a deeper understanding of the basic deployment tutorial of eureka+zuul in Micro Services, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.