Exemple #1
0
func updateProxies(entries []RoutingEntry) {
	// FIXME: support routes that has been gone from the routing table.

	for _, entry := range entries {
		routingProxy, ok := proxies[entry.ListenPort]
		if ok {
			if routingProxy.service == entry.TargetService {
				continue
			}

			delete(proxies, entry.ListenPort)
			routingProxy.serviceProxy.Close()
			routingProxy.serviceDiscovery.Close()
		}

		serviceDiscovery := discovery.New(entry.TargetService,
			*region, *table)
		serviceDiscovery.Start()

		serviceProxy := proxy.New(serviceDiscovery, proxyConfig)
		err := serviceProxy.Listen(entry.ListenPort)
		if err != nil {
			log.Print("cannot start listen on port", entry.ListenPort)
			continue
		}

		go serviceProxy.Accept()

		proxies[entry.ListenPort] = &RoutingProxy{
			service:          entry.TargetService,
			serviceDiscovery: serviceDiscovery,
			serviceProxy:     serviceProxy,
		}
	}
}
Exemple #2
0
func main() {
	flag.Parse()

	serviceDiscovery := discovery.New(*service, "eu-west-1", "uio-jrydberg-default")
	serviceDiscovery.Start()

	config := proxy.Config{
		MaxPoolSize:    30,
		ConnectTimeout: 10,
	}

	forwardProxy := proxy.New(serviceDiscovery, config)
	err := forwardProxy.Listen(*listenPort)
	if err != nil {
		panic(err)
	}

	forwardProxy.Accept()
}