diff --git a/contrib/registry/eureka/client.go b/contrib/registry/eureka/client.go index ab9eb30d2..3b985c5b1 100644 --- a/contrib/registry/eureka/client.go +++ b/contrib/registry/eureka/client.go @@ -19,9 +19,9 @@ const ( statusOutOfService = "OUT_OF_SERVICE" heartbeatRetry = 3 maxIdleConns = 100 - heartbeatTime = 10 - httpTimeout = 3 - refreshTime = 30 + heartbeatTime = 10 * time.Second + httpTimeout = 3 * time.Second + refreshTime = 30 * time.Second ) type Endpoint struct { @@ -139,8 +139,8 @@ func NewClient(urls []string, opts ...ClientOption) *Client { urls: urls, eurekaPath: "eureka/v2", maxRetry: len(urls), - heartbeatInterval: time.Second * heartbeatTime, - client: &http.Client{Transport: tr, Timeout: time.Second * httpTimeout}, + heartbeatInterval: heartbeatTime, + client: &http.Client{Transport: tr, Timeout: httpTimeout}, keepalive: make(map[string]chan struct{}), } diff --git a/contrib/registry/eureka/eureka.go b/contrib/registry/eureka/eureka.go index a5c1201e7..a7759dee4 100644 --- a/contrib/registry/eureka/eureka.go +++ b/contrib/registry/eureka/eureka.go @@ -29,7 +29,7 @@ func NewAPI(ctx context.Context, client *Client, refreshInterval time.Duration) } // it is required to broadcast for the first time - e.broadcast() + go e.broadcast() go e.refresh(ctx) @@ -112,6 +112,7 @@ func (e *API) Subscribe(serverName string, fn func()) error { appID: appID, callBack: fn, } + go e.broadcast() return nil }