如何为微服务构建前端 [英] How to build front end for Microservices

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

问题描述

假设我有十几个微服务.我想知道前端应该去哪里.假设前端是HTML,Javascript,CSS.一种方法是使它成为由UI团队处理的单独服务.因此,它可以构成API网关,其中来自浏览器的请求首先进入.但这似乎与独立的自包含服务的想法背道而驰.
浏览器------> API网关------>微服务
他们在链接中说Java和CSS应该由微服务提供. API网关应仅提供HTML页面.这是一个很好的图表,显示了此>> 我有两个问题
1.如何实施? API网关将如何为微服务中的JS和CSS文件以及HTML片段提供服务.初始页面加载如何发生以及从何处开始.
2.现在,我们将HTML混合到微服务中.但是,如果我也想提供Android和iOS应用程序怎么办?谢谢.

Let's say I have a dozen microservices. I am wondering where should the front end go. Let's say front end is HTML, Javascript, CSS. One way is to make it a separate service handled by a UI team. So it can form the API gateway where the request from browser comes in first. But this seems against the idea of independent self contained services.
browser ------> API Gateway ------> Microservices
In this link, they say that Javascript and CSS should be served by microservices. API gateway should serve only the HTML page. THere is a nice diagram showing this >> I have two questions
1. How will this be implemented? How will API gateway serve the JS and CSS files in microservices, and maybe HTML fragments too. How will initial page load happen and from where.
2. Now we are mingling HTML into microservices. But what if I want to serve Android and iOS apps too? THanks.

推荐答案

让我尝试直接回答您的两个问题,而无需讨论任何一种方法.

let me try to answer your 2 questions directly without discussing either approaches.

如果您使用MV *模式,则可以使用模块化Web Apps. AngularJS和ReactJS都支持构建模块化的Apps,并通过webpack或requireJs按需加载模块.

Modular Web Apps are possible if you use an MV* pattern. AngularJS and ReactJS both support building modular Apps and load modules on demand via webpack or requireJs.

由于UI由来自不同微服务的片段组成,因此您可能需要反向代理和一些CDN或缓存,以通过将客户端请求整理到单个主机(域)来加快页面加载速度.

Since your UI is composed of fragments coming from different microservices, you might need a reverse proxy and some CDN or caching to speed up page load by curating client requests to a single host (domain).

本机应用程序将需要一个API层,您可以将微服务管理到单个API网关中,甚至可以在移动应用程序和实际微服务之间开发中介API,以仅公开实际后端的一个简单子集.

Native Apps will require an API layer and you can curate your microservices into a single API gateway, maybe even develop a mediator API between mobile apps and actual microservices to expose only a simple subset of your actual backend.

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

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