Documentation ¶
Index ¶
- Constants
- Variables
- func SetLogger(logFunc LogFunc)
- type ApplicationVo
- type ApplicationsVo
- type Client
- func (t *Client) Api() ([]*EurekaServerApi, error)
- func (t *Client) Config(config *EurekaClientConfig) *Client
- func (t *Client) GetInstance() *InstanceVo
- func (t *Client) GetRegistryApps() map[string]ApplicationVo
- func (t *Client) Register(appId string, port int) *Client
- func (t *Client) RegisterVo(vo *InstanceVo) *Client
- func (t *Client) Run()
- type DataCenterInfo
- type DiscoveryClient
- type EndpointUtils
- func (t *EndpointUtils) GetDiscoveryServiceUrls(config *EurekaClientConfig, zone string) ([]string, error)
- func (t *EndpointUtils) GetServiceUrlsFromConfig(config *EurekaClientConfig, instanceZone string) ([]string, error)
- func (t *EndpointUtils) GetServiceUrlsFromDNS(config *EurekaClientConfig, instanceZone string) ([]string, error)
- func (t *EndpointUtils) GetServiceUrlsMapFromConfig(config *EurekaClientConfig, instanceZone string) (map[string][]string, error)
- type EurekaClientConfig
- type EurekaServerApi
- func (t *EurekaServerApi) DeRegisterInstance(appId, instanceId string) error
- func (t *EurekaServerApi) QueryAllInstanceByAppId(appId string) ([]InstanceVo, error)
- func (t *EurekaServerApi) QueryAllInstances() ([]ApplicationVo, error)
- func (t *EurekaServerApi) QueryAllSVipInstances()
- func (t *EurekaServerApi) QueryAllVipInstances()
- func (t *EurekaServerApi) QuerySpecificAppInstance(instanceId string) (*InstanceVo, error)
- func (t *EurekaServerApi) RegisterInstance(appId string, port int) (string, error)
- func (t *EurekaServerApi) RegisterInstanceWithVo(vo *InstanceVo) (string, error)
- func (t *EurekaServerApi) SendHeartbeat(appId, instanceId string) error
- func (t *EurekaServerApi) UpdateInstanceStatus(appId, instanceId, status string) error
- func (t *EurekaServerApi) UpdateMeta(appId, instanceId string, meta map[string]string) error
- type InstanceVo
- type LeaseInfo
- type LogFunc
Constants ¶
const ( DEFAULT_REGION = "default" DEFAULT_PREFIX = "/eureka" DEFAULT_ZONE = "defaultZone" )
const ( LevelDebug = 1 LevelInfo = 2 LevelError = 3 )
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" )
const (
DEFAULT_SLEEP_INTERVALS = 3
)
Variables ¶
var DefaultClient = new(Client)
Functions ¶
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) RegisterVo ¶
func (t *Client) RegisterVo(vo *InstanceVo) *Client
user raw instanceVo to register instance
type DataCenterInfo ¶
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 }
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"` }