Skip to content
krakend eureka integration
Go
Branch: master
Clone or download
Ulises Olivenza
Ulises Olivenza Change to schibsted repo
Latest commit 62d0125 May 9, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Initial commit May 3, 2018
LICENSE Initial commit May 3, 2018
README.md Change to schibsted repo May 9, 2018
app.go Add license header May 8, 2018
backend.go Change to schibsted repo May 9, 2018
backend_test.go Add license header May 8, 2018
client.go Add license header May 8, 2018
client_test.go Add license header May 8, 2018

README.md

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

You can’t perform that action at this time.