生产中的微服务

微服务是一种特殊的Jhipster应用。有关执行生产构建、优化和保护生产构建的更多信息,请参阅我们的主要 Using JHipster in production documentation

微服务监控

请参阅我们的 JHipster Registry documentation ,了解哪些运行时仪表板可用,以及如何使用它们。

我们的 monitoring documentation 也非常重要,了解有关使用的特定信息:

  • jhipster控制台与您的微服务体系结构一起使用elk
  • Zipkin在整个服务中跟踪HTTP请求
  • Elastalert,在出现问题时发出警报

使用docker compose子生成器时,将询问您是否要向基础结构添加监视。此选项将把jhipster控制台添加到“docker compose.yml”文件中。一旦启动,它将在http://localhost:5601上可用,并开始收集应用程序的日志和度量。

对于网关和微服务应用程序,还提供了其他功能来帮助您有效地监视微服务集群。例如,日志中丰富了每个应用程序的名称、主机、端口和eureka/consul serviceid,这样您就可以跟踪它们来自哪个服务实例。jhipster控制台还附带了默认的仪表盘,这些仪表盘为您提供了所有服务指标的概述。

使用Docker Compose开发和部署

在微服务体系结构上工作意味着您将需要几个不同的服务和数据库一起工作,在这种情况下,Docker Compose是管理开发、测试和生产环境的一个很好的工具。

A specific section on microservices is included in our Docker Compose documentation, and we highly recommend that you get familiar with it when working on a microservices architecture.

As Docker Swarm uses the same API as Docker Machine, deploying your microservices architecture in the cloud is exactly the same as deploying it on your local machine. Follow our Docker Compose documentation to learn more about using Docker Compose with JHipster.

Going to production with Cloud Foundry

The Cloud Foundry sub-generator works the same with a microservices architecture, the main difference is that you have more applications to deploy:

  • Use the Cloud Foundry sub-generator to deploy first the JHipster Registry (which is a normal JHipster application).
  • Note the URL on which your JHipster Registry is deployed. Your applications must all point to that URL:
    • In the bootstrap-prod.yml file, the spring.cloud.config.uri must point to http(s)://<your_jhipster_registry_url>/config/
    • In the application-prod.yml file, the eureka.client.serviceUrl.defaultZone must point to http(s)://<your_jhipster_registry_url>/eureka/
  • Deploy your gateway(s) and microservices
  • Scale your applications as usual with Cloud Foundry

One important point to remember is that the JHipster Registry isn’t secured by default, and that the microservices are not supposed to be accessible from the outside world, as users are supposed to use the gateway(s) to access your application.

Two solutions are available to solve this issue:

  • Secure your Cloud Foundry using specific routes.
  • Keep everything public, but use HTTPS everywhere, and secure your JHipster Registry using Spring Security’s basic authentication support

Going to production with Heroku

The Heroku sub-generator works nearly the same with a microservices architecture, the main difference is that you have more applications to deploy:

Deploy a JHipster Registry directly with one click:

Deploy to Heroku

Please follow the Heroku sub-generator documentation in order to understand how to secure your JHipster Registry.

Note the URL on which your JHipster Registry is deployed. Your applications must all point to that URL in their application-prod.yml file. Change that configuration to be:

eureka:
    instance:
        hostname: https://admin:[password]@[appname].herokuapp.com
        prefer-ip-address: false

You can now deploy and scale the gateway(s) and microservices. The Heroku sub-generator will ask you a new question, to know the URL of your JHipster Registry: this will allow your applications to fetch their configuration on the Spring Cloud Config server.