catcherwong-archive / APIGatewayDemo

:seedling: Simple samples that use Ocelot to build API Gateway.
MIT License
273 stars 158 forks source link

Can not connect to Eureka Server #1

Closed minhvc closed 6 years ago

minhvc commented 6 years ago

I use this code to run a eureka server. https://github.com/spring-guides/gs-service-registration-and-discovery The java eureka client connects successfully to the eureka server. But not .Net Services shows on Server Dashboard my service config:

"spring": {
        "application": {
            "name": "service-a"
        }

    },
    "eureka": {
        "client": {
            "serviceUrl": "http://localhost:8761/eureka/",
            "shouldFetchRegistry": true,
            "validateCertificates": false
        },
        "instance": {
            "port": 9003,
            "instanceId": "192.168.1.88:9003",
            "HostName": "192.168.1.88",
            "healthCheckUrlPath": "/api/values/healthcheck",
            "statusPageUrlPath": "/api/values/info"    
        }
    }

How can I fix it? Thanks

catcherwong commented 6 years ago

@minhvc Thanks for your interest in this project.

The config seems good! Have you register it in your Startup class?

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }
    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDiscoveryClient(Configuration);
        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseDiscoveryClient();
        app.UseMvc();
    }
}
minhvc commented 6 years ago

yes, I use APIServiceAA of you at the article https://www.c-sharpcorner.com/article/building-api-gateway-using-ocelot-in-asp-net-core-service-discoveryeureka/

minhvc commented 6 years ago

Thank for your respronse, now microservice connected successfully to eureka server. but "Lease expiration enabled" always is false and when micro service is down (die or shut down) the instances currently registered is not refresh my eureka server setting:

spring.application.name=service-registry

server.port=8761
#server.address= 192.168.1.88

eureka.instance.hostname=192.168.1.88
eureka.instance.ip-address= 192.168.1.88
#eureka.server.enable-self-preservation= false
eureka.server.eviction-interval-timer-in-ms=1000
eureka.server.renewal-percent-threshold = 0.0
eureka.instance.lease-expiration-duration-in-seconds = 5

eureka.client.register-with-eureka=true
eureka.client.fetch-registry= false
eureka.client.service-url.defaultZone=http://192.168.1.88:8761/eureka/
eureka.client.initial-instance-info-replication-interval-seconds=5

Can you share your eureka server configuration? Help me please, thanks image

catcherwong commented 6 years ago

Here is the configuration

server:
  port: 8761

eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
  server:
    waitTimeInMsWhenSyncEmpty: 0

You can follow this repo spring-cloud-samples/eureka