使用Micro-frontends Deployed to Heroku的JHipster 7.9.3应用程序可以工作吗?

fcipmucu  于 2023-03-30  发布在  其他
关注(0)|答案(1)|浏览(134)

在Heroku上部署JHipster 7.9.3生成的微服务应用程序后,我得到了下面的消息。我的应用程序有2个微服务(tajvoteservice和siennaservice),两个微服务都是微前端。当我在笔记本电脑上本地部署我的应用程序时,它工作正常;但是,在Heroku上,我在网关上收到以下错误消息:

2023-03-25T16:35:53.163730+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/services/siennaservice/remoteEntry.js" host=www.saathratri.com request_id=7e56ca8a-620e-45b9-bb9d-a2241aa2143c fwd="50.172.26.133" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
2023-03-25T16:35:53.095621+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/services/tajvoteservice/remoteEntry.js" host=www.saathratri.com request_id=d4f9e086-fe6e-465a-9855-7bb8f9c78d2d fwd="50.172.26.133" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
2023-03-25T16:36:23.127957+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/services/tajvoteservice/remoteEntry.js" host=www.saathratri.com request_id=0d5053bf-4cf9-412b-b59b-e67ff17e3bf5 fwd="50.172.26.133" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=https

我尝试检查网关的webpack.microfrontend.js中的remotes参数:

...
module.exports = (config, options, targetOptions) => {
  return {
    plugins: [
      new ModuleFederationPlugin({
        remotes: {
          tajvoteservice: 'tajvoteservice@/services/tajvoteservice/remoteEntry.js',
          siennaservice: 'siennaservice@/services/siennaservice/remoteEntry.js',
        },
...

我修改如下:

...
module.exports = (config, options, targetOptions) => {
  return {
    plugins: [
      new ModuleFederationPlugin({
        remotes: {
          tajvoteservice: 'tajvoteservice@https://www.saathratri.com/services/tajvoteservice/remoteEntry.js',
          siennaservice: 'siennaservice@https://www.saathratri.com/services/siennaservice/remoteEntry.js',
        },
...

但同样的错误发生了。
我在浏览器控制台中收到以下错误:

main.1cba1d1f42986c71.js:1 Initialization of sharing external failed: ScriptExternalLoadError: Loading script failed.
(error: https://www.saathratri.com/services/siennaservice/remoteEntry.js)

我认为这与Webpack和Module Federation(也不是微前端)无关。我已经将部署(在JDL中)更改为常规微服务,但仍然得到503(服务不可用)错误。在我看来,这与Auth 0有关。但不确定出了什么问题。我按照www.example.com中的说明https://www.jhipster.tech/security/#oauth2进行Auth 0,但没有运气。

68de4m5k

68de4m5k1#

问题是我的微服务中的Eureka 服务配置(网关很好)。我必须在我的微服务中的Eureka的application-prod.yml中包含以下内容:

...
eureka:
  instance:
    hostname: tajvote-service.herokuapp.com
    non-secure-port: 80
    prefer-ip-address: false
  client:
    service-url:
      defaultZone: ${JHIPSTER_REGISTRY_URL}/eureka/
...

主机名条目很重要。
微服务没有被调用,网关一直返回Service Unavailable(503),因为Eureka 配置错误;sienna-service和tajvote-service微服务没有在服务发现Eureka 中正确注册自己,因此Eureka不知道如何将请求转发到相应的微服务上。一旦在Eureka配置中添加了主机名条目,事情就开始工作了,503 Service Unavailable错误消失了。
最后,这个问题与Auth 0和Micro-frontend无关。此外,是的,在Heroku上部署的使用Micro-frontend的JHipster 7.9.3应用程序确实可以工作(只要你解决了服务发现难题)!

相关问题