eureka

package module
v0.0.0-...-f87e79c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2022 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DEFAULT_REGION = "default"
	DEFAULT_PREFIX = "/eureka"
	DEFAULT_ZONE   = "defaultZone"
)
View Source
const (
	LevelDebug = 1
	LevelInfo  = 2
	LevelError = 3
)
View Source
const (
	STATUS_UP             = "UP"
	STATUS_DOWN           = "DOWN"
	STATUS_STARTING       = "STARTING"
	STATUS_OUT_OF_SERVICE = "OUT_OF_SERVICE"
	STATUS_UNKNOWN        = "UNKNOWN"

	DC_NAME_TYPE_MY_OWN = "MyOwn"
	DC_NAME_TYPE_AMAZON = "Amazon"
)
View Source
const (
	DEFAULT_SLEEP_INTERVALS = 3
)

Variables

View Source
var DefaultClient = new(Client)

Functions

func SetLogger

func SetLogger(logFunc LogFunc)

Types

type ApplicationVo

type ApplicationVo struct {
	Name      string       `json:"name"`
	Instances []InstanceVo `json:"instance"`
}

application

type ApplicationsVo

type ApplicationsVo struct {
	VersionDelta string          `json:"version__delta"`
	AppsHashCode string          `json:"apps_hash__code"`
	Application  []ApplicationVo `json:"application"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

eureka client

func (*Client) Api

func (t *Client) Api() ([]*EurekaServerApi, error)

Api for sending rest http to eureka server

func (*Client) Config

func (t *Client) Config(config *EurekaClientConfig) *Client

func (*Client) GetInstance

func (t *Client) GetInstance() *InstanceVo

func (*Client) GetRegistryApps

func (t *Client) GetRegistryApps() map[string]ApplicationVo

func (*Client) Register

func (t *Client) Register(appId string, port int) *Client

user brief parameters to register instance

func (*Client) RegisterVo

func (t *Client) RegisterVo(vo *InstanceVo) *Client

user raw instanceVo to register instance

func (*Client) Run

func (t *Client) Run()

start eureka client 1. parse/get service urls 2. register client to eureka server and send heartbeat

type DataCenterInfo

type DataCenterInfo struct {
	// MyOwn | Amazon
	Name string `json:"name"`
	// metadata is only required if name is Amazon
	Metadata string `json:"metadata,omitempty"`
	Class    string `json:"@class"`
}

type DiscoveryClient

type DiscoveryClient interface {
	GetRegistryApps() map[string]ApplicationVo
	GetInstance() *InstanceVo
}

type EndpointUtils

type EndpointUtils struct {
}

func (*EndpointUtils) GetDiscoveryServiceUrls

func (t *EndpointUtils) GetDiscoveryServiceUrls(config *EurekaClientConfig, zone string) ([]string, error)

func (*EndpointUtils) GetServiceUrlsFromConfig

func (t *EndpointUtils) GetServiceUrlsFromConfig(config *EurekaClientConfig, instanceZone string) ([]string, error)

*

  • Get the list of all eureka service urls from properties file for the eureka client to talk to. *
  • @param clientConfig the clientConfig to use
  • @param instanceZone The zone in which the client resides
  • @return The list of all eureka service urls for the eureka client to talk to

func (*EndpointUtils) GetServiceUrlsFromDNS

func (t *EndpointUtils) GetServiceUrlsFromDNS(config *EurekaClientConfig, instanceZone string) ([]string, error)

*

  • Get the list of all eureka service urls from DNS for the eureka client to
  • talk to. The client picks up the service url from its zone and then fails over to
  • other zones randomly. If there are multiple servers in the same zone, the client once
  • again picks one randomly. This way the traffic will be distributed in the case of failures. *
  • @param clientConfig the clientConfig to use
  • @param instanceZone The zone in which the client resides. *
  • @return The list of all eureka service urls for the eureka client to talk to.

func (*EndpointUtils) GetServiceUrlsMapFromConfig

func (t *EndpointUtils) GetServiceUrlsMapFromConfig(config *EurekaClientConfig, instanceZone string) (map[string][]string, error)

@TODO GetServiceUrlsMapFromConfig

type EurekaClientConfig

type EurekaClientConfig struct {
	/**
	 * Indicates how often(in seconds) to fetch the registry information from the eureka
	 * server.
	 */
	RegistryFetchIntervalSeconds int

	/**
	 * Gets the URL context to be used to construct the service url to contact eureka
	 * server when the list of eureka servers come from the DNS. This information is not
	 * required if the contract returns the service urls from eurekaServerServiceUrls.
	 *
	 * The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the
	 * eureka client expects the DNS to configured a certain way so that it can fetch
	 * changing eureka servers dynamically. The changes are effective at runtime.
	 */
	EurekaServerUrlContext string

	/**
	 * Gets the port to be used to construct the service url to contact eureka server when
	 * the list of eureka servers come from the DNS.This information is not required if
	 * the contract returns the service urls eurekaServerServiceUrls(String).
	 *
	 * The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the
	 * eureka client expects the DNS to configured a certain way so that it can fetch
	 * changing eureka servers dynamically.
	 *
	 * The changes are effective at runtime.
	 */
	EurekaServerPort string

	/**
	 * Gets the DNS name to be queried to get the list of eureka servers.This information
	 * is not required if the contract returns the service urls by implementing
	 * serviceUrls.
	 *
	 * The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the
	 * eureka client expects the DNS to configured a certain way so that it can fetch
	 * changing eureka servers dynamically.
	 *
	 * The changes are effective at runtime.
	 */
	EurekaServerDNSName string

	/**
	 * Gets the region (used in AWS datacenters) where this instance resides.
	 */
	Region string

	/**
	 * Map of availability zone to list of fully qualified URLs to communicate with eureka
	 * server. Each value can be a single URL or a comma separated list of alternative
	 * locations.
	 *
	 * Typically the eureka server URLs carry protocol,host,port,context and version
	 * information if any. Example:
	 * http://ec2-256-156-243-129.compute-1.amazonaws.com:7001/eureka/
	 *
	 * The changes are effective at runtime at the next service url refresh cycle as
	 * specified by eurekaServiceUrlPollIntervalSeconds.
	 */
	ServiceUrl map[string]string

	/**
	 * Indicates whether the eureka client should use the DNS mechanism to fetch a list of
	 * eureka servers to talk to. When the DNS name is updated to have additional servers,
	 * that information is used immediately after the eureka client polls for that
	 * information as specified in eurekaServiceUrlPollIntervalSeconds.
	 *
	 * Alternatively, the service urls can be returned serviceUrls, but the users should
	 * implement their own mechanism to return the updated list in case of changes.
	 *
	 * The changes are effective at runtime.
	 */
	UseDnsForFetchingServiceUrls bool

	/**
	 * Indicates whether or not this instance should register its information with eureka
	 * server for discovery by others.
	 *
	 * In some cases, you do not want your instances to be discovered whereas you just
	 * want do discover other instances.
	 */
	RegisterWithEureka bool

	/**
	 * Indicates whether or not this instance should try to use the eureka server in the
	 * same zone for latency and/or other reason.
	 *
	 * Ideally eureka clients are configured to talk to servers in the same zone
	 *
	 * The changes are effective at runtime at the next registry fetch cycle as specified
	 * by registryFetchIntervalSeconds
	 */
	PreferSameZoneEureka bool

	/**
	 * Comma separated list of regions for which the eureka registry information will be
	 * fetched. It is mandatory to define the availability zones for each of these regions
	 * as returned by availabilityZones. Failing to do so, will result in failure of
	 * discovery client startup.
	 *
	 */
	FetchRemoteRegionsRegistry string

	/**
	 * Gets the list of availability zones (used in AWS data centers) for the region in
	 * which this instance resides.
	 *
	 * The changes are effective at runtime at the next registry fetch cycle as specified
	 * by registryFetchIntervalSeconds.
	 */
	AvailabilityZones map[string]string

	/**
	 * Indicates whether to get the applications after filtering the applications for
	 * instances with only InstanceStatus UP states.
	 */
	FilterOnlyUpInstances bool

	/**
	 * Indicates whether this client should fetch eureka registry information from eureka
	 * server.
	 */
	FetchRegistry bool

	//
	// extend features
	//
	//
	// (only when UseDnsForFetchingServiceUrls=true effects)
	// Auto lookup dns to update service urls
	AutoUpdateDnsServiceUrls bool

	// when UseDnsForFetchingServiceUrls=true and AutoUpdateDnsServiceUrls=true
	// AutoUpdateDnsServiceUrlsIntervals effects
	// default value: 5*60 seconds
	AutoUpdateDnsServiceUrlsIntervals int

	// eureka client heartbeat intervals
	// Tips:
	// 1. only when RegisterWithEureka=true, HeartbeatIntervals effects
	// 2. HeartbeatIntervals must less than EvictionDurationInSecs(in server_api_vos.go, InstanceVo.LeaseInfo.EvictionDurationInSecs)
	HeartbeatIntervals int
}

refer to: https://github.com/spring-cloud/spring-cloud-netflix/blob/master/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientConfigBean.java

func GetDefaultEurekaClientConfig

func GetDefaultEurekaClientConfig() *EurekaClientConfig

get default config

func (*EurekaClientConfig) GetAvailabilityZones

func (t *EurekaClientConfig) GetAvailabilityZones(region string) []string

func (*EurekaClientConfig) GetRegion

func (t *EurekaClientConfig) GetRegion() string

type EurekaServerApi

type EurekaServerApi struct {
	BaseUrl string
}

Refer to: https://github.com/Netflix/eureka/wiki/Eureka-REST-operations

func NewEurekaServerApi

func NewEurekaServerApi(baseUrl string) *EurekaServerApi

func (*EurekaServerApi) DeRegisterInstance

func (t *EurekaServerApi) DeRegisterInstance(appId, instanceId string) error

De-register application instance

func (*EurekaServerApi) QueryAllInstanceByAppId

func (t *EurekaServerApi) QueryAllInstanceByAppId(appId string) ([]InstanceVo, error)

Query for all appId instances

func (*EurekaServerApi) QueryAllInstances

func (t *EurekaServerApi) QueryAllInstances() ([]ApplicationVo, error)

Query for all instances

func (*EurekaServerApi) QueryAllSVipInstances

func (t *EurekaServerApi) QueryAllSVipInstances()

@TODO Query for all instances under a particular vip address Sorry, I don't have the environment for testing

func (*EurekaServerApi) QueryAllVipInstances

func (t *EurekaServerApi) QueryAllVipInstances()

@TODO Query for all instances under a particular vip address Sorry, I don't have the environment for testing

func (*EurekaServerApi) QuerySpecificAppInstance

func (t *EurekaServerApi) QuerySpecificAppInstance(instanceId string) (*InstanceVo, error)

query specific instanceId

func (*EurekaServerApi) RegisterInstance

func (t *EurekaServerApi) RegisterInstance(appId string, port int) (string, error)

Register new application instance by brief info

func (*EurekaServerApi) RegisterInstanceWithVo

func (t *EurekaServerApi) RegisterInstanceWithVo(vo *InstanceVo) (string, error)

Register new application instance

func (*EurekaServerApi) SendHeartbeat

func (t *EurekaServerApi) SendHeartbeat(appId, instanceId string) error

Send application instance heartbeat

func (*EurekaServerApi) UpdateInstanceStatus

func (t *EurekaServerApi) UpdateInstanceStatus(appId, instanceId, status string) error

update instance status

func (*EurekaServerApi) UpdateMeta

func (t *EurekaServerApi) UpdateMeta(appId, instanceId string, meta map[string]string) error

Update meta data

type InstanceVo

type InstanceVo struct {
	// Register application instance needed -- BEGIN
	Hostname         string         `json:"hostName"`
	App              string         `json:"app"`
	IppAddr          string         `json:"ipAddr"`
	VipAddress       string         `json:"vipAddress"`
	SecureVipAddress string         `json:"secureVipAddress"`
	Status           string         `json:"status"`
	Port             positiveInt    `json:"port"`
	SecurePort       positiveInt    `json:"securePort"`
	HomePageUrl      string         `json:"homePageUrl"`
	StatusPageUrl    string         `json:"statusPageUrl"`
	HealthCheckUrl   string         `json:"healthCheckUrl"`
	DataCenterInfo   DataCenterInfo `json:"dataCenterInfo"`
	LeaseInfo        LeaseInfo      `json:"leaseInfo"`

	InstanceId           string `json:"instanceId,omitempty"`
	OverriddenStatus     string `json:"overriddenstatus,omitempty"`
	LastUpdatedTimestamp int    `json:"lastUpdatedTimestamp,omitempty"`
	LastDirtyTimestamp   int    `json:"lastUpdatedTimestamp,omitempty"`
	ActionType           string `json:"actionType,omitempty"`
}

func DefaultInstanceVo

func DefaultInstanceVo() *InstanceVo

type LeaseInfo

type LeaseInfo struct {
	// (optional) if you want to change the length of lease - default if 90 seconds
	EvictionDurationInSecs int `json:"eviction_duration_in_secs,omitempty"`
}

type LogFunc

type LogFunc func(level int, format string, a ...interface{})

func (LogFunc) Debugf

func (t LogFunc) Debugf(format string, a ...interface{})

func (LogFunc) Errorf

func (t LogFunc) Errorf(format string, a ...interface{})

func (LogFunc) Infof

func (t LogFunc) Infof(format string, a ...interface{})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL