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

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

问题描述

我已阅读了很多关于微服务的内容,并希望用这种方法构建我的应用程序。到目前为止,我知道的是我需要一些服务,如:


  • 负载平衡器 - 处理每个请求,并将其推送到其他服务

  • 授权服务 - 授权我的用户

  • 数据库
  • strong> - 用于我的微服务。我想为每个服务使用不同模式的数据库实例。
  • 服务A - 用于功能A


  • 等功能B

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


    • my-app-auth

    • my-app-load-balancer

    • 等。等等。



    我看到,Heroku为我的每个应用程序都提供了一些公共主机名,这是我的担忧开始的地方。我应该使用公共主机名部署我的内部服务吗?我不这么认为。在这里,我的问题来了:

    任何人都可以给我提供一些指导,如何处理Heroku上的微服务?我应该如何部署它们?我应该如何定义我的负载均衡器,并将内部服务挂接到它?什么是JHipster?我需要它吗?我如何使用它?我应该使用Heroku工具(例如CLI)还是可以使用我的gitlab回购?我无法在互联网上找到任何关于此的信息。

    解决方案

Heroku是一个非常简单的Platform-as-一家服务公司。 Heroku的工作方式非常简单:


  • 在Git仓库中有多个项目(服务)。
  • 您为每个项目(每个Git仓库)创建一个Heroku应用程序。

  • 然后,您将代码从每个Git仓库推送到它们各自的Heroku应用程序。

  • Heroku为您拥有的每个应用程序分配一个公共URL。

  • 如果您的每个服务现在都在Heroku上运行,则它们可以通过公共HTTP向对方发送API请求。 / li>


现在 - 关于您在Heroku上关于面向服务的体系结构的问题。



如果你在Heroku上使用SOA,你需要让每个服务通过HTTPS公开对话。这是典型的'模式'。



由于Heroku为每个应用程序提供免费的SSL,并且每个应用程序位于同一Amazon区域 - 您的HTTP服务非常快速且安全。



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



这里的下一个选项(如果您不想遵循典型模式)是使用像RabbitMQ或Amazon SQS(排队服务)的东西,并在不同服务之间共享消息。 / p>

在这种模式下,每个服务仍然有一个Heroku应用程序,但不是通过HTTP与对方通信,而是通过排队与其他服务进行通信协议像兔子或SQS。这有一些速度上的好处。



关于身份验证服务,您可以使用几种提供程序来提供此功能。我所知道的最受欢迎的是 Stormpath 。如果您浏览 Heroku插件市场,您也可以找到其他人。



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



您可以在所有服务中共享一个数据库,也可以为每个服务提供一个数据库。两种策略都可以正常工作。


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:

  • 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

  • etc. etc. etc.

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
  • etc. etc.

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:

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 is a very simple Platform-as-a-Service company. The way Heroku works is very straightforward:

  • You have multiple projects (services) in Git repos.
  • You create a Heroku app for each project (each Git repo).
  • You then push your code from each Git repo to their respective Heroku app.
  • Heroku assigns you a public URL for each app you have.
  • If each of your services is now running on Heroku, they can send API requests to each other over public HTTPs.

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

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'.

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.

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

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.

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.

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.

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

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

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

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