28 Nisan 2019 Pazar

SpringCloud Netflix Eureka Sunucu u@EnableEurekaServer Anotasyonu - Eureka Sunucusunu Başlatır

Giriş
Şu satırı dahil ederiz
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
Euraka'ya alternatif olarak Spring Cloud Consul kullanılabilir. Şeklen şöyle

Açıklaması şöyle.
If your infrastructure is not based on any popular Cloud environment but you still want to take advantage of the dynamic discovery rather than static IP configuration, you can set up your service registry. One of the more popular choices, especially in the JVM-based microservice world, is Eureka (initially developed by Netflix and now part of Spring Cloud). Eureka follows the client-server model, and you usually set up a server (or a cluster of servers for high availability) and use clients to register and locate services.
Açıklaması şöyle
- REST service which registers itself at the registry (Eureka Client) and
- Web application, which is consuming the REST service as a registry-aware client (Spring Cloud Netflix Feign Client).
Maven
Eureka Server tarafında şu satırı dahil ederiz
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
Örnek
Şöyle yaparız
@SpringBootApplication
@EnableEurekaServer
public class SuperdevEurekaServerApplication {
  public static void main(String[] args) {
    SpringApplication.run(SuperdevEurekaServerApplication.class, args);
  }
}
application.properties
Ayarlar eureka.client ve eureka.server başlıkları altında belirtilir

1. eureka server Ayarlar
registerWithEureka  Alanı
Eureka Sunucusunun Eurak Server'da listelenmesini isteyip istemediğimizi belirtiriz. 

Örnek 
Eureka Server'a kayıt olmak istemiyorsak şöyle yaparız
eureka.client.registerWithEureka = false
eureka.client.fetchRegistry = false
server.port = 8761

spring.application.name=superdev-eureka-server
Örnek
Şöyle yaparız
spring.application.name=eureka-server server.port=8761 eureka.client.register-with-eureka=false eureka.client.fetch-registry=false

2. eureka client Ayarlar
Örnek
Şöyle yaparız
spring.application.name=my-client eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
Örnek
Şöyle yaparız
server: port: 8761 # default port where discovery client is registered eureka: client: registerWithEureka: false fetchRegistry: false server: waitTimeInMsWhenSyncEmpty: 0
fetch-registry Alanı
Örnek 
Şöyle yaparız
server.port=8761

eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF
Dashboard
Eureka Server Dashboard'u görmek için şöyle yaparız
http://localhost:8761/
Şeklen şöyle



Hiç yorum yok:

Yorum Gönder