代码拉取完成,页面将自动刷新
package eureka
import (
"io/ioutil"
"time"
"github.com/ArthurHlt/go-eureka-client/eureka"
"github.com/cenk/backoff"
"github.com/containous/flaeg"
"github.com/traefik/traefik/job"
"github.com/traefik/traefik/log"
"github.com/traefik/traefik/provider"
"github.com/traefik/traefik/safe"
"github.com/traefik/traefik/types"
)
// Provider holds configuration of the Provider provider.
type Provider struct {
provider.BaseProvider `mapstructure:",squash" export:"true"`
Endpoint string `description:"Eureka server endpoint"`
Delay flaeg.Duration `description:"Override default configuration time between refresh (Deprecated)" export:"true"` // Deprecated
RefreshSeconds flaeg.Duration `description:"Override default configuration time between refresh" export:"true"`
}
// Init the provider
func (p *Provider) Init(constraints types.Constraints) error {
return p.BaseProvider.Init(constraints)
}
// Provide allows the eureka provider to provide configurations to traefik
// using the given configuration channel.
func (p *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool) error {
eureka.GetLogger().SetOutput(ioutil.Discard)
operation := func() error {
client := eureka.NewClient([]string{p.Endpoint})
applications, err := client.GetApplications()
if err != nil {
log.Errorf("Failed to retrieve applications, error: %s", err)
return err
}
configuration, err := p.buildConfiguration(applications)
if err != nil {
log.Errorf("Failed to build configuration for Provider, error: %s", err)
return err
}
configurationChan <- types.ConfigMessage{
ProviderName: "eureka",
Configuration: configuration,
}
ticker := time.NewTicker(time.Duration(p.RefreshSeconds))
pool.Go(func(stop chan bool) {
for {
select {
case t := <-ticker.C:
log.Debugf("Refreshing Provider %s", t.String())
applications, err := client.GetApplications()
if err != nil {
log.Errorf("Failed to retrieve applications, error: %s", err)
continue
}
configuration, err := p.buildConfiguration(applications)
if err != nil {
log.Errorf("Failed to refresh Provider configuration, error: %s", err)
continue
}
configurationChan <- types.ConfigMessage{
ProviderName: "eureka",
Configuration: configuration,
}
case <-stop:
return
}
}
})
return nil
}
err := backoff.RetryNotify(operation, job.NewBackOff(backoff.NewExponentialBackOff()), notify)
if err != nil {
log.Errorf("Cannot connect to Provider server %+v", err)
return err
}
return nil
}
func notify(err error, time time.Duration) {
log.Errorf("Provider connection error %+v, retrying in %s", err, time)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。