Vis
Vis

Reputation: 43

How to efficiently handle spring boot microservices?

I have bunch of spring boot microservices running in unique ports. How do we handle these microservices in production ?

In production, we only need the DNS, how do we handle the DNS mapping.

For ex: example-microservice-1 (port: 8001)
example-microservice-2 (port: 8002)
example-microservice-3(port: 8003)
example-microservice-4 (port: 8004)
example-microservice-5 (port: 8005)

I would want something like below,
myprod.com/example-microservice-1
myprod.com/example-microservice-2
...

Instead of,
myprod:8001/example-microservice-1
myprod:8002/example-microservice-2

(removed "https/http" above due to less reputation)

All the microservices exists in a different codebase and when build will create individual runnable jars.

Upvotes: 0

Views: 512

Answers (2)

Barath
Barath

Reputation: 5283

In case of spring boot application depending on spring cloud dependencies. Zuul is the right option.

Please go through below guide

https://spring.io/guides/gs/routing-and-filtering/

you can find sample application here :

https://github.com/BarathArivazhagan/Microservices-workshop

For Documentation Reference: http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html

Upvotes: 1

JC Carrillo
JC Carrillo

Reputation: 1026

Simply install nginx and do a reverse proxy to your microservices.

nginx example:

server {
    listen 80 default_server;
    server_name myprod.com;
    location /example-microservice-1 {
        proxy_pass http://localhost:8001;
        proxy_set_header Host      $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    location /example-microservice-2 {
        proxy_pass http://localhost:8002;
        proxy_set_header Host      $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Upvotes: 1

Related Questions