eureka

package module
v0.0.0-...-62d0125 Latest Latest
Warning

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

Go to latest
Published: May 9, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

README

krakend-eureka

krakend eureka integration.

The integration is based on a custom subscriber using the fargo library

Usage Example

	logger, err := logging.NewLogger("INFO", os.Stdout, "[KRAKEND]")
	if err != nil {
		log.Fatal("ERROR:", err.Error())
	}
	parser := config.NewParser()
	serviceConfig, err := parser.Parse("./test.json")
	if err != nil {
		log.Fatal("ERROR:", err.Error())
	}

	eurekaLocalAppInstance, err := NewLocalAppInstance(8000, "HELLO")
	if err != nil {
		log.Fatal("ERROR:", err.Error())
	}
	eurekaClient := NewFargoEurekaClient(eurekaLocalAppInstance, "http://localhost:8080", logger)

  subscriber := eurekaClient.NewSubscriber(sd.GetSubscriber)
	routerFactory := kgin.DefaultFactory(proxy.DefaultFactoryWithSubscriber(logger, subscriber), logger)
	routerFactory.New().Run(serviceConfig)

We need to create an app instance to register the current application to eureka:

eurekaLocalAppInstance, err := NewLocalAppInstance(8000, "HELLO")

An aws aware application instance can be used: NewAwsAppInstance

Then, a eureka client should be create with:

eurekaClient := NewFargoEurekaClient(eurekaLocalAppInstance, "http://localhost:8080", logger)

And wire it with krakend with a new Subscriber

subscriber := eurekaClient.NewSubscriber(sd.GetSubscriber)
routerFactory := kgin.DefaultFactory(proxy.DefaultFactoryWithSubscriber(logger, subscriber), logger)

Config Example

{
  "version": 2,
  "max_idle_connections": 250,
  "timeout": "3000ms",
  "read_timeout": "0s",
  "write_timeout": "0s",
  "idle_timeout": "0s",
  "read_header_timeout": "0s",
  "name": "Test",
  "endpoints": [
    {
      "endpoint": "/cbcrash",
      "method": "GET",
      "backend": [
        {
          "url_pattern": "/crash",
          "host": [
            "http://localhost:8000"
          ],
          "extra_config": {
            "github.com/schibsted/krakend-eureka": {
              "eureka_app_name": "crash",
            }
          }
        }
      ],
      "timeout": "1500ms",
      "max_rate": "10000"
    }
  ]
}

The only configuration needed it's the eureka backend application name

Documentation

Index

Constants

View Source
const BACKEND_EUREKA_APP_NAME = "eureka_app_name"
View Source
const BackendNamespace = "github.com/schibsted/krakend-eureka"

Namespace is the key to use to store and access the custom config data

View Source
const POLL_INTERVAL = 30 // seconds

Variables

View Source
var DefaultBackendExtraConfig = BackendExtraConfig{EurekaAppName: ""}
View Source
var EmptyBackendExtraConfig = BackendExtraConfig{}

Functions

func BackendConfigGetter

func BackendConfigGetter(e config.ExtraConfig) interface{}

func NewAwsAppInstance

func NewAwsAppInstance(port int, appName string, instanceMeta *ec2metadata.EC2Metadata) (*fargo.Instance, error)

func NewLocalAppInstance

func NewLocalAppInstance(port int, appName string) (*fargo.Instance, error)

Types

type BackendExtraConfig

type BackendExtraConfig struct {
	EurekaAppName string
}

func GetBackendExtraConfig

func GetBackendExtraConfig(e *config.Backend) BackendExtraConfig

func NewBackendExtraConfigFromMap

func NewBackendExtraConfigFromMap(data map[string]interface{}) BackendExtraConfig

func (BackendExtraConfig) AsMap

func (e BackendExtraConfig) AsMap() map[string]interface{}

type EurekaClient

type EurekaClient interface {
	EnableInstance()
	NewSubscriber(subscriber sd.SubscriberFactory) sd.SubscriberFactory
}

func NewFargoEurekaClient

func NewFargoEurekaClient(appInstance *fargo.Instance, url string, logger logging.Logger) EurekaClient

type EurekaConfig

type EurekaConfig struct {
	AppName string `mapstructure:"app_name"`
	URL     string `mapstructure:"url"`
}

type EurekaSubscriber

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

func (EurekaSubscriber) Hosts

func (e EurekaSubscriber) Hosts() ([]string, error)

Jump to

Keyboard shortcuts

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