How to use spring cloud from nodejs?

Now I am thinking how to combine spring cloud with nodejs. So I want to use nodeJS as a middle tier that provides an api for an angularjs frontend app, but as soon as nodeJS receives an api request, it initiates another HTTP request for the spring api backend. I noticed that spring cloud provides a very nice feature like service discovery, configure the server, BUT they are all used for spring itself. Let's say how can I load the result of the config server in nodeJS, if it can be done easily with json parsing, how can I use service discovery from NodeJS? In a spring project, I can use:

InstanceInfo instance = discoveryClient.getNextServerFromEureka("spirent", false);
String url = instance.getHomePageUrl();

      

But if I use nodeJS, how can nodeJS easily find the next service instance from the eureka service?

Hope to hear your tips and suggestions.

Franc

Based on the assumption, 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 POM server and then I have this in 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);
    }
}

      

Application.yml and bootstrap.yml on Eureka server are similar to the previous one.

    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 Eureka clients can still register with this Eureka server, but when I am at: http: // localhost: 8761 / hosts / mysevice , I got an empty response.

So my question is: can SideCar automatically find out all the notifications registered on the Eureka server?

+3


source to share


1 answer


Spring Cloud Netflix Sidecar is the way to do it. Docs here . You can do one of two things:



  • You can use zuul's auto-proxying with a stroller. You send requests tohttp://localhost:<sidecarport>/<servicename>

  • You can get a list of available hosts for a service by requesting http://localhost:<sidecarport>/hosts/<servicename>

+3


source







All Articles