如何在 Heroku 上部署微服务 [英] How to deploy microservices on Heroku

查看:25
本文介绍了如何在 Heroku 上部署微服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多关于微服务的文章,并且想用这种方法构建我的应用程序.到目前为止,我所知道的是我需要一些服务,例如:

I have read a lot about microservices, and would like to build my app with that approach. What I know so far is that I nead some services like:

  • 负载均衡器 - 处理每个请求,并将其推送到其他服务
  • 授权服务 - 授权我的用户
  • 数据库 - 用于我的微服务.我想为每项服务使用一个具有不同架构的数据库实例.
  • 服务 A - 用于功能 A
  • 服务 B - 用于功能 B

  • load balancer - to deal with every request, and push it forward to another services
  • authorization service - to authorize my users
  • database - for my microservices. I would like to use one instance of DB with different schemas for every service.
  • service A - for functionality A
  • service B - for functionality B

等等.等等等等

我发现,Heroku 是部署应用程序的有趣地方.我的问题是我完全不了解他们的意识形态.到目前为止,我所做的是创建/注册几个应用程序":

I found out, that Heroku is interesting place to deploy applications. My problem is that I completely don't understand they ideology. What I have done so far, is creation/registration of few "apps":

  • my-app-auth
  • my-app-load-balancer
  • 等.等

我明白了,Heroku 为每个应用程序提供了一些公共主机名,这就是我担心的地方.我应该使用公共主机名部署我的内部服务吗?我不这么认为.我的问题来了:

I see, that Heroku gives me some public hostname for every of that app, and this is where my concerns starts. Should I deploy my internal services with public hostnames? I don't think so. And here my question comes:

谁能给我一些指导,如何在 Heroku 上处理微服务?我应该如何部署它们?我应该如何定义我的负载均衡器,并将内部服务挂钩到它?什么是 JHipster?我需要吗?我怎样才能使用它?我应该使用 Heroku 工具(例如 CLI)还是可以继续使用我的 gitlab 存储库?我在互联网上找不到任何关于这一点的把握.

Can anyone provide me some guidelines, how to deal with microservices on Heroku? How should i deploy them? How should I define my load balancer, and hook internal services to it? What is JHipster? Do I need it? How can I use it? Should I use Heroku tools (for example CLI) or can I stay with my gitlab repo? I can't find any point of grasp on the Internet, about that.

推荐答案

Heroku 是一家非常简单的平台即服务公司.Heroku 的工作方式非常简单:

Heroku is a very simple Platform-as-a-Service company. The way Heroku works is very straightforward:

  • 您在 Git 存储库中有多个项目(服务).
  • 您为每个项目(每个 Git 存储库)创建一个 Heroku 应用.
  • 然后,您将代码从每个 Git 存储库推送到各自的 Heroku 应用.
  • Heroku 为您拥有的每个应用分配一个公共 URL.
  • 如果您的每个服务现在都在 Heroku 上运行,则它们可以通过公共 HTTP 向彼此发送 API 请求.

现在——关于您关于 Heroku 上面向服务的架构的问题.

Now -- regarding your question about service oriented architecture on Heroku.

如果您在 Heroku 上执行 SOA,您需要让每个服务通过 HTTPS 公开相互交流.这是典型的模式".

If you're doing SOA on Heroku, you'll need to have each service talk publicly with each other over HTTPS. This is the typical 'pattern'.

因为 Heroku 为每个应用程序提供免费的 SSL,并且每个应用程序都位于同一亚马逊区域 - 通过 HTTPs 在您的服务之间来回通信非常快速且安全.

Because Heroku provides free SSL for each application, and each application is on the same Amazon region -- talking back-and-fourth between your services over HTTPs is very fast + secure.

每个 Heroku 应用程序都有自动负载平衡,因此无需担心负载平衡器.

Each Heroku app has automatic load balancing, so no need to worry about load balancers.

此处的下一个选项(如果您不想遵循典型模式)是使用 RabbitMQ 或 Amazon SQS(一种排队服务)之类的东西,并在您的不同服务之间共享消息".

The next option here (if you don't want to follow the typical patterns) is to use something like RabbitMQ or Amazon SQS (a queueing service), and share 'messages' between your different services.

在这种模式中,每个服务仍然有一个 Heroku 应用程序,但不是通过 HTTPs 相互通信,而是通过队列协议(如 Rabbit 或 SQS)与其他服务通信.这有一些速度优势.

In this pattern, you would still have one Heroku app for each service, but instead of communicating with each other over HTTPs, you would instead communicate with your other services through a queueing protocol like Rabbit or SQS. This has some speed benefits.

关于身份验证服务,您可以使用多个提供程序来提供此功能.我所知道的最流行的是 Stormpath.如果您浏览 Heroku 插件市场,您也可以找到其他插件.

In regards to authentication services, there are several providers you can use to provide this functionality. The most popular one I know of is Stormpath. If you look through the Heroku addon marketplace, you can find others as well.

最后,对于数据库内容:您可以使用任何您想要的数据库提供程序.最受欢迎的可能是 Heroku Postgres.它是 PostgreSQL 的托管版本,非常可靠/易于使用.

Finally, for database stuff: you can use any Database provider you want. The most popular one is likely Heroku Postgres. It's a hosted version of PostgreSQL that's very reliable / easy to use.

您可以在所有服务之间共享一个数据库,也可以每个服务拥有一个数据库.这两种策略都行得通.

You can either share one database amongst ALL your services, or you can have one databases per service. Either strategy will work fine.

这篇关于如何在 Heroku 上部署微服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆