简体   繁体   English

如何有效地处理Spring Boot微服务?

[英]How to efficiently handle spring boot microservices?

I have bunch of spring boot microservices running in unique ports. 我有一堆在唯一端口中运行的spring boot microservices。 How do we handle these microservices in production ? 我们如何在生产中处理这些微服务?

In production, we only need the DNS, how do we handle the DNS mapping. 在生产中,我们只需要DNS,我们如何处理DNS映射。

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

I would want something like below, 我想要下面这样的东西
myprod.com/example-microservice-1 myprod.com/example-microservice-1
myprod.com/example-microservice-2 ... myprod.com/example-microservice-2 ...

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

(removed "https/http" above due to less reputation) (由于声誉降低,已将上述“ https / http”删除)

All the microservices exists in a different codebase and when build will create individual runnable jars. 所有微服务都存在于不同的代码库中,并且在构建时将创建单个可运行的jar。

Simply install nginx and do a reverse proxy to your microservices. 只需安装nginx并为您的微服务做一个反向代理。

nginx example: nginx示例:

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;
    }
}

In case of spring boot application depending on spring cloud dependencies. 如果是Spring Boot应用程序,则取决于Spring Cloud依赖项。 Zuul is the right option. Zuul是正确的选择。

Please go through below guide 请通过以下指南

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

you can find sample application here : 您可以在此处找到示例应用程序:

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

For Documentation Reference: http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html 有关文档参考: http : //cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM