+1 vote
in .NET Core by

6 Answers

+1 vote
by
B1: Cài đặt gói nuget cho các services & gateway

- nuget Steeltoe.Discovery.Eureka
- nuget SSteeltoe.Discovery.ClientCore
+1 vote
by
B2: Config enviroment file appsettings cho từng services

"Spring": {
  "Application": {
    "Name": "SERVICE.CONTENTAPI"
  }
},
"Eureka": {
  "Client": {
    "ServiceUrl": "http://eureka-server:8761/eureka/",
    "ValidateCertificates": false,
    "ShouldRegisterWithEureka": true
  },
  "Instance": {
    "NonSecurePort": 8080,
    "HostName": "content.api",
    "InstanceId": "Content.API,Port:8080",
    "StatusPageUrlPath": "/swagger/index.html",
    "HealthCheckUrlPath": "/api/values/healthcheck"
  }
}
+1 vote
by
B3: Đăng ký eureka cho từng services trong program.cs

builder.Services.AddServiceDiscovery(o => o.UseEureka());
+1 vote
by

B4: Đăng ký eureka service trong ocelot gateway

builder.Services.AddOcelot(builder.Configuration).AddEureka().AddPolly();

builder.Services.AddServiceDiscovery(o => o.UseEureka());

+1 vote
by

B5: Config route serviceName trong gateway

"Routes": [

  {

    "DownstreamPathTemplate": "/category/{everything}",

    "DownstreamScheme": "http",

    "SwaggerKey": "systemservice",

    "UseServiceDiscovery": true,

    "DownstreamHostAndPorts": [

      {

        "Host": "systemservice",

        "Port": "8080"

      }

    ],

    "UpstreamPathTemplate": "/category/{everything}",

    "UpstreamHttpMethod": [ "GET", "POST", "PUT", "DELETE" ],

    "LoadBalancerOptions": {

      "Type": "LeastConnection"

    }

  }

]

+1 vote
by
B6: Triển khai các services và eureka bằng docker-compose

1. docker-compose.yml

  eureka-server:
    container_name: eureka-server
    image: steeltoeoss/eurekaserver:latest
    restart: on-failure
    hostname: eureka-server

2. docker-compose.override.yml

  eureka-server:
    environment:
      - EUREKA_SERVER_ENABLE_SELF_PRESERVATION=false
    ports:
      - 8761:8761
  content.api:
    environment:
      - EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8761/eureka
    depends_on:
      - eureka-server
Welcome to Qtsd Q&A, where you can ask questions and receive answers from other members of the community.
...