Spring Cloud Configures Eureka Cluster

tags: spring cloud

Refer to the Spring Cloud course of Shang Silicon Valley, have made some notes, complete code:https://github.com/yao09605/mscloud

What is EUREKA?

The service call relationship between the micro service architecture is more complicated, so a service registration center is enabled, and the registration of the unified management service is enabled. You can achieve service call, service discovery, and registration.

EUREKA cluster principle

Several machines are registered with each other, and there are registration forms of all services on each machine.

Newly built two modules as the EUREKA server

cloud-eureka-server7001 cloud-eureka-server7002
Two Module basically copy paste

POM added as follows

<dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

Profile: main / resources / application.yml

server:
  port: 7001 # Another file into 7002

eureka:
  instance:
    hostname: eureka7001.com # Another file into erbeka7002.com
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://eureka7002.com:7002/eureka/ # Another file into http://eureka7001.com:7001/Eureka/

Modify the HOSTS file (the local simulation configuration)

127.0.0.1  eureka7001.com
127.0.0.1  eureka7002.com

Master start class Add: @enableeeurekaserver

package org.example.mscloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class EurekaMain7001 {
    public static void main(String[] args) {
        SpringApplication.run(EurekaMain7001.class, args);
    }
}

Register your service on EUREKA

Add the following dependence on the POM

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

YML increase configuration

spring:
  application:
    name: cloud-payment-service #Service Name

eureka:
  client:
    register-with-eureka: true
    fetchRegistry: true
    service-url:  #eureka server address
      defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
  instance:
    instance-id: payment8001 #        
    prefer-ip-address: true  #         i i

Main start plus @enableeeurekaclient

@EnableEurekaClient
@SpringBootApplication
public class PaymentMain8001 {
    public static void main(String[] args) {
        SpringApplication.run(PaymentMain8001.class,args);
    }
}

Caller

POM Add dependence

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

The caller is no longer directly toned, and the service name is used:

public static final String PAYMENT_URL="http://CLOUD-PAYMENT-SERVICE";

Intelligent Recommendation

The cluster - spring cloud eureka cluster code

Start two cloud clusters mycloud,mycloud1 Pom.xml adds the following configuration     <dependency>             <groupId>org.springframework.cloud&l...

Spring Cloud Eureka cluster high availability

In the microservices architecture, the registry is an essential component The registration center we built earlier is only suitable for local development. In the production environment, a cluster must...

Spring Cloud Eureka Cluster Test Report 1:

Spring Cloud Eureka Cluster Test Report 1: Foreword: Due to the limited level of younger brothers, the tests may not be perfect enough. All majors are welcome to criticize and correct. Test 1. Take up...

Spring cloud eureka build dcos cluster

2019 Unicorn Enterprise Heavy Gold Recruitment Python Engineer Standard >>> Use docker deployment service in dcos, do not use docker compose. You need to register the host ip and external por...

spring cloud Eureka registry Cluster Setup

1. Create springcloud-eureka maven project  pom.xml   2. Start class EurekaServerApplication.java   3. Create application-peer1.properties registered with peer2 registry, the registry p...

More Recommendation

Spring Cloud Netflix — Eureka Server Cluster

Foreword Eureka Server as a service registry, set up the cluster is still quite necessary, Eureka Server to build a cluster fairly simple and requires only two machines were deployed, two Eureka Serve...

Spring Cloud study notes Eureka cluster configuration

Cluster: Configure the same service on different machines to build a large computing whole Implement clusters New N Eureka Server modules Add the same dependencies as the single Eureka Server to the p...

Spring Cloud Eureka Cluster Construction Guide

Introduction Eureka is a service management module of Spring Cloud, which creates conditions for the cluster deployment of business components. Business components can be registered in the Eureka cont...

Spring-cloud creates a highly available eureka cluster

Recorded a few pits encountered during the deployment of the eureka cluster, especially the last pit. After searching on the Internet for a long time, no results were found, and I finally found myself...

Spring Cloud Eureka cluster high availability configuration

On the basis of the previous article, the simple cluster configuration of Eureka is realized to meet the requirements of high availability. Eureka's cluster logic, the difference with Zookeeper, not t...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top