SpringCloud (the next day to strengthen)

1. Use the IP registration services

a) modify the service providers and service consumers yml profile

Eureka: 
  instance: 
    hostname: localhost 
    the prefer -ip-address: to true # using the IP address registered to a registry 
    instance -id: provider- NAME # registered with the registry name 
  Client: 
    Service - url: 
      defaultzone: HTTP: // localhost: 7001 / eureka

b)  the prefer-ip-address: to true using the IP address registered to the registry access Eureka when the registry , registered to access the service registry of IP would not be 127.0.0.1 and localhost, but 192.168.xx. x

2. calls between service (communication)

a) establish a common module service providers and consumers

b) adding a module dependency on public services in the consumer and provider

c) the service provider module definition Interface (Controller layer)

d) defined in the service consumer calls the service provider controller controller

            i. remoting tools provided by restFul style SpringMVC RestTemplete achieved, in the main configuration class configuration inside RestTemplete this Spring bean to manage, and then injected RestTemplete objects in the Controller. invoke the service.

3.Eureka cluster: solve a single node failure

a) modify the hosts file: C: \ Windows \ System32 \ the Drivers \ etc \ hosts
  to add the local IP domain name registration service of two
  127.0.0.1  eureka-7001.com

  127.0.0.1 eureka-7002.com

b) modify Eurake profile configuration

the Spring: 
  the Application: 
    name: the Spring -cloud- Eureka 
Server: 
  Port: 7001 
Eureka: 
  instance: 
    hostname: Eureka -7 001 .com 
  Client: 
    # is not registered with the Eureka own 
    the Register the -with-Eureka: false 
    # Do not check other EurekaServer nodes 
    fetch -registry: false 
    service - url: 
      # set address eureka server is located, tracking and registration procedures are registered to this address (the address of the service exposure) 
      defaultzone: HTTP: // eureka-7002.com : 7002 / eureka /

 

c) set up another registry, modify the configuration file yml

the Spring: 
  the Application: 
    name: the Spring -cloud- Eureka 
Server: 
  Port: 7002 
Eureka: 
  instance: 
    hostname: eureka-7002.com 
  Client: 
    # is not registered with the Eureka own 
    the Register the -with-Eureka: false 
    # Do not check other EurekaServer nodes 
    fetch -registry: false 
    service - url: 
      # set address eureka server is located, tracking and registration procedures are registered to this address (the address of the service exposure) 
      defaultzone: HTTP: // eureka-7001.com : 7001 / eureka /

 

d) modifying the client registered to the path Eurake

the Spring: 
  the Application: 
    name: SPRING -CLOUD- the USER // if the service provider do when a cluster name must be the same here 
Server: 
  Port: 8001    // Service Provider 
Eureka: 
  instance: 
    hostname: localhost 
    the prefer -ip-address: to true # using the IP address registered to a registry 
    instance -id: USER- CLIENT // if the service provider to do this when the cluster instance-id must not be the same
Client: Service - url: # Set address eureka server is located, tracking and registration procedures are registered to this address (the address of the service exposure) #defaultZone: HTTP: // $ {eureka.instance.hostname}: $ {Server } .port / Eureka /  defaultzone: HTTP: // peer1: 7001 / Eureka, HTTP: // peer2 : 7002 / Eureka to two registration centers // registration service

 

Guess you like

Origin www.cnblogs.com/8888-lhb/p/11546503.html