I am now thinking how to combine spring cloud with nodejs. So I want to use nodeJS as middle tier, which is providing api to frontend angularjs application, but once nodeJS is getting api request, it will trigger other http request to backend spring api. I noticed spring cloud is providing a lot very good feature, such as service discovery, configure server, BUT these are all used for spring itself. Let's say,how can I load configuration server result in nodeJS, if that can be easily done through json parsing, how can I use service discovery from NodeJS? In spring project, I can use:
InstanceInfo instance = discoveryClient.getNextServerFromEureka("spirent", false);
String url = instance.getHomePageUrl();
But if I am using nodeJS, how can nodeJS easily find out next service instance from eureka service?
Hope to hear your advice and suggestions.
Frank
Based on the suggestion, I added
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-sidecar</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>
To my current Eureka server POM, and then I have this in the mainApplication:
@SpringBootApplication
@EnableEurekaServer
@EnableSidecar
public class SpringCloudEurekaServerApplication {
public static void main(String[] args) throws IOException {
System.err.println(new ClassPathResource("static/eureka/css/wro.css").getURL());
SpringApplication.run(SpringCloudEurekaServerApplication.class, args);
}
}
The Application.yml and bootstrap.yml at Eureka server is same as before.
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
server:
waitTimeInMsWhenSyncEmpty: 0
and bootstrap.yml:
spring:
application:
name: eureka
cloud:
config:
uri: ${CONFIG_SERVER_URL:http://localhost:8888}
Now, the Eureka clients can still register against this Eureka Server, but when I visit: http://localhost:8761/hosts/mysevice, I got empty response.
So my question is: Can sideCar automatically find out all the sevices registered with Eureka server?