1
votes

Basic question so just want to ensure I understand it all correctly.

I have created a discovery server:

@SpringBootApplication
@EnableEurekaServer
public class DisocveryServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(DisocveryServiceApplication.class, args);
    }

and registered microservices with it successfully; If I hit localhost:8761 I can see my discovery service has found the microservices. The microservices run fine if i hit them on their designated port. For example, I have one called creds and if i hit localhost:9000 it returns. However, My understanding is I should now be able to hit localhost:8761/creds and it will show the same output but this isnt working.

Am I misunderstanding? Any suggestions on what I should try?

creds bootstrap.yml:

spring:
  application:
    name: creds

creds application.yml server: port: 9000 eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/

discover application.yml

server:
  port: ${PORT:8761}

eureka:
  client:
    registerWithEureka: false
    fetchRegistry: false
    server:
      waitTimeInMsWhenSyncEmpty: 0
2

2 Answers

1
votes

Another @EnableEurekaClient annotated Spring boot webservice can access your creds webservice by using an injected RestTemplate with http://creds/..., where creds is the spring.application.name registered with Eureka.

If you want to access the creds webservice from the outside of your web application, then what you want is a proxy like Zuul http://github.com/Netflix/zuul.

0
votes

Just registering micro service to Eureka server wont make sure that you can access the microservice under a gateway. Eureka Server is not a gateway server , its just a service registry. You can think Eureka as just one more service that holds information about all the other services in the cluster. It doesnt do anything extra other than getting information to the Clients registered. You may need a Gateway service for routing your request under the Eureka Server. Zuul Proxy routes a request coming to it to the under lying microservices using its service id or the URL configured.

Add this dependency in your classpath.

dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-zuul</artifactId>
    <version>1.0.4.RELEASE</version>
</dependency>

Add this config in your properties filezuul:

  routes:
    serv1:
      path: /serv1/**
      serviceId: http://localhost:8080/serv1
    serv2:
      path: /serv2/**
      serviceId: serv2

This will create a dynamic router that routes your request to appropriate service instances. This also provides a server end load balancer for your services