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()
- func (c *Client) WSHeartbeat(microServiceID, microServiceInstanceID string, callback func()) error
- type DataCenterInfo
- type DataCenterMetadata
- 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) GetApplication(appId string) (*ApplicationVo, error)
- func (t *EurekaServerApi) GetApplications() (*ApplicationsVo, 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 Instance
- type InstanceVo
- type LeaseInfo
- type LogFunc
- type MetaData
- type PositiveInt
- type Vraw
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
func (*Client) Run ¶
func (t *Client) Run()
start eureka client 1. parse/get service urls 2. register client to eureka server and send heartbeat
func (*Client) WSHeartbeat ¶
WSHeartbeat creates a web socket connection to service-center to send heartbeat. It relies on the ping pong mechanism of websocket to ensure the heartbeat, which is maintained by goroutines. After the connection is established, the communication fails and will be retried continuously. The retrial time increases exponentially. The callback function is used to re-register the instance.
type DataCenterInfo ¶
type DataCenterInfo struct { // MyOwn | Amazon Name string `json:"name"` // metadata is only required if name is Amazon Metadata *DataCenterMetadata `json:"metadata,omitempty"` Class string `json:"@class"` }
type DataCenterMetadata ¶
type DataCenterMetadata struct { AmiLaunchIndex string `xml:"ami-launch-index,omitempty" json:"ami-launch-index,omitempty"` LocalHostname string `xml:"local-hostname,omitempty" json:"local-hostname,omitempty"` AvailabilityZone string `xml:"availability-zone,omitempty" json:"availability-zone,omitempty"` InstanceId string `xml:"instance-id,omitempty" json:"instance-id,omitempty"` PublicIpv4 string `xml:"public-ipv4,omitempty" json:"public-ipv4,omitempty"` PublicHostname string `xml:"public-hostname,omitempty" json:"public-hostname,omitempty"` AmiManifestPath string `xml:"ami-manifest-path,omitempty" json:"ami-manifest-path,omitempty"` LocalIpv4 string `xml:"local-ipv4,omitempty" json:"local-ipv4,omitempty"` Hostname string `xml:"hostname,omitempty" json:"hostname,omitempty"` AmiId string `xml:"ami-id,omitempty" json:"ami-id,omitempty"` InstanceType string `xml:"instance-type,omitempty" json:"instance-type,omitempty"` }
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) GetApplication ¶
func (t *EurekaServerApi) GetApplication(appId string) (*ApplicationVo, error)
GetApplication Query Application by specific appId
func (*EurekaServerApi) GetApplications ¶
func (t *EurekaServerApi) GetApplications() (*ApplicationsVo, error)
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 Instance ¶
type Instance struct {
Instance *InstanceVo `xml:"instance" json:"instance"`
}
type InstanceVo ¶
type InstanceVo struct { // Register application instance needed -- BEGIN Hostname string `json:"hostName"` App string `json:"app"` IpAddr 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"` Metadata *MetaData `xml:"metadata,omitempty" json:"metadata,omitempty"` IsCoordinatingDiscoveryServer bool `xml:"isCoordinatingDiscoveryServer,omitempty" json:"isCoordinatingDiscoveryServer,omitempty"` 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"` CountryId int `xml:"countryId,omitempty" json:"countryId,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"` RenewalIntervalInSecs int `xml:"renewalIntervalInSecs,omitempty" json:"renewalIntervalInSecs,omitempty"` DurationInSecs int `xml:"durationInSecs,omitempty" json:"durationInSecs,omitempty"` RegistrationTimestamp int `xml:"registrationTimestamp,omitempty" json:"registrationTimestamp,omitempty"` LastRenewalTimestamp int `xml:"lastRenewalTimestamp,omitempty" json:"lastRenewalTimestamp,omitempty"` EvictionTimestamp int `xml:"evictionTimestamp,omitempty" json:"evictionTimestamp,omitempty"` ServiceUpTimestamp int `xml:"serviceUpTimestamp,omitempty" json:"serviceUpTimestamp,omitempty"` }