eeureka

package module
v0.0.0-...-54f6bb0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2016 License: MIT Imports: 13 Imported by: 0

README

eeureka

Simplistic Eureka client for Go Microservices

What is is?

I use this in my personal Microservice projects where I use Go-based microservices in a Spring Cloud context deployed on docker containers. It is not production tested, use at your own peril...

Internally, it's basically wraps a little HTTP client for the following operations of the Netflix Eureka REST API :

  • register appId
  • heartbeat appId
  • deregister appId
  • instances of appId

The top three is enough to handle the lifecycle of a Microservice while the "instances of appId" can be used to get hostname/port for all running instances of a particular appId. Useful for client-side load-balancing.

Usage

Import

import "github.com/eriklupander/eeureka"

In your code, call the Register method:

eeureka.Register("myMicroservice", "8080", "8443")

or

eeureka.RegisterAt("http://192.168.123.123:8761","myMicroservice", "8080", "8443")

The register method will try to contact the Eureka server indefinitely. When registration succeeds (HTTP 204), heartbeats (PUTs) will be issued every 30 seconds. When the microservice exits by a Sigterm or OS interrupt signal, the microservice will deregister itself with Eureka before shutting down.

Public functions
  • RegisterAt - registers your application at a specific Eureka service URL.
  • Register - registers your application at the default Eureka service URL http://192.168.99.100:8761 (e.g. typical local Docker installation)
  • GetServiceInstances - Returns all running instances of a given appName

The register methods automatically handles retries, heartbeats and deregistration.

Configuration

By default, the Eureka server is assumed to be at http://192.168.99.100:8761

Otherwise, use the RegisterAt function.

Spring Cloud vs Netflix Eureka

This lib has only been tested with the Spring Cloud flavour of Eureka. Internally, this lib uses the REST endpoints of Eureka which exists in two versions. With "/v2" or without. This lib is only tested with the non-v2 version.

License

MIT License. See LICENSE.md

Documentation

Overview

* The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

* The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

* The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

* The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(appName string, port string, securePort string)

*

Register the application at the default eurekaUrl.

func RegisterAt

func RegisterAt(eurekaUrl string, appName string, port string, securePort string)

*

  • Registers this application at the Eureka server at @eurekaUrl as @appName running on port(s) @port and/or @securePort.

Types

type EurekaApplication

type EurekaApplication struct {
	Name     string           `json:"name"`
	Instance []EurekaInstance `json:"instance"`
}

func GetServices

func GetServices() ([]EurekaApplication, error)

Experimental, untested.

type EurekaApplicationsResponse

type EurekaApplicationsResponse struct {
	Version      string              `json:"versions__delta"`
	AppsHashcode string              `json:"versions__delta"`
	Applications []EurekaApplication `json:"application"`
}

type EurekaApplicationsRootResponse

type EurekaApplicationsRootResponse struct {
	Resp EurekaApplicationsResponse `json:"applications"`
}

Response for /eureka/apps

type EurekaInstance

type EurekaInstance struct {
	HostName string     `json:"hostName"`
	Port     EurekaPort `json:"port"`
}

func GetServiceInstances

func GetServiceInstances(appName string) ([]EurekaInstance, error)

*

  • Given the supplied appName, this func queries the Eureka API for instances of the appName and returns
  • them as a EurekaApplication struct.

type EurekaPort

type EurekaPort struct {
	Port int `json:"$"`
}

type EurekaServiceResponse

type EurekaServiceResponse struct {
	Application EurekaApplication `json:"application"`
}

Response for /eureka/apps/{appName}

type HttpAction

type HttpAction struct {
	Method      string `yaml:"method"`
	Url         string `yaml:"url"`
	Body        string `yaml:"body"`
	Template    string `yaml:"template"`
	Accept      string `yaml:"accept"`
	ContentType string `yaml:"contentType"`
	Title       string `yaml:"title"`
	StoreCookie string `yaml:"storeCookie"`
}

Jump to

Keyboard shortcuts

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