如何在Eureka Server中发现并注册没有Spring的Web应用程序(例如在Java-JEE和Go上)?
在Spring-Boot应用程序中,很容易添加以下注释:
@EnableDiscoveryClient
@SpringBootApplication
之前
public class EurekaClientApp{
public static void main(String[] args) {
SpringApplication.run(EurekaClientApp.class, args);
}
}
在配置中,application.properties
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
但是对于不是以Spring-Boot形式构建的应用程序或以微服务形式构建的应用程序,Eureka Server应该如何发现它们并将其注册为客户端
最佳答案
就像其他任何后端服务一样;您必须使用正确的客户。例如,如果您有非Spring Java服务,则可以使用;
InstanceInfo nextServerInfo = DiscoveryManager.getInstance()
.getDiscoveryClient()
.getNextServerFromEureka(vipAddress, false);
Socket s = new Socket();
int serverPort = nextServerInfo.getPort();
try {
s.connect(new InetSocketAddress(nextServerInfo.getHostName(),
serverPort));
} catch (IOException e) {
System.err.println("Could not connect to the server :"
+ nextServerInfo.getHostName() + " at port " + serverPort);
}
https://github.com/Netflix/eureka/wiki/Understanding-eureka-client-server-communication
这是一个Python客户端;
https://pypi.org/project/py-eureka-client/
一个golang客户;
https://github.com/hudl/fargo