【问题标题】:How to distribute this architecture?如何分发这个架构?
【发布时间】:2018-10-21 23:11:17
【问题描述】:

在很多例子中exampleLink

我们看到在 X 实体上操作 CRUD 操作。

涉及的组件有:

X :描述 X 的实体(例如:对于实体 Book :标题、ISBN 号、 价格……)

XService : 接口本地

XServiceImpl:一个无状态的 EJB,具有用于持久化、更新、删除、从数据库中查找的事务

XClientService : 为 EJB 提供 RESTful 接口的客户端 Rest 接口服务

XClientServiceImpl:客户端接口服务的 Rest 实现,为 EJB 提供 RESTful 接口

可以翻译成如下代码:

import javax.ejb.Local;
// This an Basic interface service example for operating on X.
@Local
public interface XService {

}


// This is an Basic service implementation example for operating on X.
import javax.ejb.Stateless;
@Stateless 
public class XServiceImpl implements XService
{

}



import javax.ws.rs.core.Response;

/**
 * Client service with CRUD operations for working with Xs.
 */
public interface XClientService {

  ... create(...);
  ... get(...);
  ... update(...);
  ... delete(...);  
}



import javax.inject.Inject;
import javax.ws.rs.Produces;
/**
 * Client service implementation with CRUD operations for working with Xs.
 */
@Path("/X")
public class XClientServiceImpl implements XClientService
{
  //@Inject is used to inject an stateless EJB interface into the Rest web service 
  @Inject
  private XService xService;

    @GET
    @Produces(JSON)
    @Override
    public Response get() {


        return Response.ok().entity(x).build();

    }
}

这种做事方式对我来说仍然模棱两可:

Q1- 为什么我们在联系 EJB 之前必须通过 Rest Api?为什么不直接去EJB? (是否需要不同的应用程序可以使用该 Rest API,即确保应用程序在各种平台上运行。IOS、Android、Windows 等......?)

Q2- 另一方面,知道 Wildfly 有一个内置的网络服务器,并假设我们的前端是 AngulaJS,那么 Rest-Api 是驻留在这个 Web 容器(场景 1)或 ejb 容器(场景 2)中的情况? (见下图)

场景 1:

或场景 2:

另一方面,假设我们在 Maven 多项目布局上遵循相同的策略,其中包含多个模块和用于 jar、ejb、ear 和 war 的具体包装项目。如下图

对于模块 X1

  • app-modules-X1-client
  • app-modules-X1-client-impl
  • app-modules-X1-service
  • app-modules-X1-service-impl

    ├── pom.xml
    ├── src
    │   └── main
    │       ├── java
    │       │   └── com
    │       │       └── production
    │       │           └── package
    │       │               └── app
    │       │                   └── X1
    │       │                       ├── client
    │       │                       │   └── impl
    │       │                       └── service
    │       │                           └── impl
    │       └── resources (optional)
    └── target
    

    .......................

对于一个模块 Xn

  • app-modules-Xn-client
  • app-modules-Xn-client-impl
  • app-modules-Xn-service
  • app-modules-Xn-service-impl

    ├── pom.xml
    ├── src
    │   └── main
    │       ├── java
    │       │   └── com
    │       │       └── production
    │       │           └── package
    │       │               └── app
    │       │                   └── Xn
    │       │                       ├── client
    │       │                       │   └── impl
    │       │                       └── service
    │       │                           └── impl
    │       └── resources (optional)
    └── target
    

Maven 将在根项目中执行创建所有子项目和工件。对于部署,我们通过 maven 创建 'ear' 。 生成的 ear 文件的内容,即 results-ear.ear 将具有如下所示的内容:

    └── resulting-ear.ear
        ├── META-INF
        │    ├── maven 
        │    │   ├──com.production.package.app
        │    │      ├──pom.properties
        │    │      ├──pom.xml
        │    ├── application.xml 
        │    └── MANIFEST.MF 
        ├─────── App-war.war
                ├── css
                │    ├── bootstrap <-- bootstrap framework
                │    ├── fonts <- bootstrap fonts
                │    └── ... <- application css files
                ├── images
                │    ├── ... <- application image files
                ├── js
                │    ├── controllers <- application controllers
                │    ├── directives <- application directives
                │    ├── services <- application services used across the application *-service.js
                │    ├── external <- external js libraries
                │    └── ... <- application js and routes
                ├── templates
                │    └── ... <- application wide templates
                ├── WEB-INF
                │   └── web.xml
                │   └── lib
                │   │     ├── dependecie1.jar <- application dependencie1
                │   │     ├── dependecieN.jar <- application dependencieN
                │   │     ├── * app-modules-X1-client.jar
                │   │     ├── * app-modules-X...-client.jar
                │   │     ├── * app-modules-Xn-client.jar
                │   │     ├── * app-modules-X1-client-impl.jar
                │   │     └── * app-modules-X...-client-impl.jar
                │   │     └── * app-modules-Xn-client-impl.jar
                │   │     ├── * app-modules-X1-service.jar
                │   │     ├── * app-modules-X...-service.jar
                │   │     └── * app-modules-Xn-service.jar          
                │   │     ├── * app-modules-X1-service-impl.jar
                │   │     └── * app-modules-X...-service-impl.jar
                │   │     └── * app-modules-Xn-service-impl.jar
                │   │
                │   └── classes 
                │   └── jboss-deployment-structure.xml
                └── index.html <- root single page application 

Q3- 在这种情况下,如何横向分布和扩展的最佳方式 许多节点,耳朵文件? (知道所有会话 bean 都是 无国籍)?

客户端应用程序(即 Web 应用程序 HTML5 文件 AngularJS 文件 css .js 文件 img 等)和访问会话 bean 的 Rest-Api 可以在应用程序服务器的同一实例(并置)或不同实例中运行在同一台机器上运行。它们也可以在物理上独立的机器上运行,这些机器具有如下应用服务器实例:

Q4- 在这种情况下,我们是否需要更多编码来处理负载平衡和 故障转移,或者只是配置应用服务器的问题,例如 Wildfly 和硬件统一?

如果我的理解是正确的:

如果我们想在多个节点上水平分布和扩展,ear 文件(就像现在一样,即无需对代码进行任何更改,即只需编辑配置文件:即通过从standalone-full 传递。 xml 到standalone-full-ha.xml) :

Q5- 在这种情况下,AngularJS UI 是否也不会在每个节点上复制?

非常感谢。

【问题讨论】:

  • 或许您应该详细说明一下您计划如何构建 Wildfly 集群。你检查Wildfly High Availability Guide了吗?当您“将应用程序分发到多个节点”时,如何进行部署?您是否使用域模式、服务器组、集群 EJB、...?
  • 谢谢你 Frito 我根据你的提示更新了我的问题,

标签: jakarta-ee jax-rs ejb wildfly load-balancing


【解决方案1】:
Q1- Why are we forced to go through the Rest Api before contacting the EJB? 
    why not go directly to the EJB? 

Answer: 通过利用 http 协议,我们确保应用程序在各种平台上运行 不同的应用程序可以通过 http 使用该 Rest API: IOS、Android、Windows、DesktopApp(嵌入一个apache HttpClient和json(将pojo转换为json并从json转换回pojo))。

如果我们想不使用http直接进入EJB:

     - The first option is to have a jvm on the client, means an java application that could reach
       the ejb directly by using RMI.

     - The second option is to have a not jvm app on the client, means a not java application,e.g dot.net app that could reach
       the ejb directly by using RMI-IIOP

     - The third option is to use http protocle from client requests to reach a between media on the webcontainer, This between media        
       could be servlet jsp  and webcontainer who knows very well(by default) how to handle the contact with ejbs embedded on the ejbcontainer via RMI.
    so as you can see the third option using servlet or jsp, this way of doing has now been overtaken by the use of the new standard Rest API as mediate 
    in between.

Q2- 另一方面,知道 Wildfly 有一个内置的网络服务器,并假设 我们的前端是 AngulaJS,然后是在这种情况下驻留在 web 容器中的 Rest-Api (情景 1)或 在 ejb 容器中(场景 2)? (见下图)

Answer: in webContainer (Scenario 1) as you can deduce from the first answer.

Q3- 在这种情况下,如何水平分布和扩展的最佳方式, 在许多节点上,ear 文件? (知道所有会话 bean 都是无状态的)?

Answer: 
        theoretically,you should have to get everything out of your front-end from the wildfly container 
        and leave in wildfly container only Rest-api in its webcontainer and the beans in ejbcontainer. 
        Your front-end should contact clustered wildfly containers only via http/json, 
        i.e your Front-end should act as a RestClient for the clustered Rest-api wildfly containers.

对于无状态 ejb 来说很容易,但这并不是一件容易的事,对于有状态 ejb 来说,在这种情况下很难实现。 因为有必要分发有状态的事务和 使用分布式内存,例如 Ehecache、Hazelcast、Infinispan 以及通过 narayana 事务管理器管理 XA 事务。

Q4- 在这种情况下,我们是否需要更多编码来处理负载平衡和故障转移 还是只需要配置 Wildfly 和硬件单元等应用服务器?

Answer: both  

Q5- AngularJS UI 在这种情况下不会在每个节点上复制吗?

in the figure that you imagined yes in this case you will repeat the front end on each node, 
but in reality it does not happen in this way.
we deduce from the previous answer that the front-end AngularJs should not be replicated 
but it will be aggregation of microservices having each microservice its own clustering mechanism. 
but to be at the height of this hard task you must use architecture that can easily help 
you to perform scaling such as CQRS pattern embeded for each microservice 
called by your application AngularJS. AngularJS reach the clustered wildflys by using http/json.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-23
    • 2012-02-06
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    • 1970-01-01
    • 2012-01-01
    相关资源
    最近更新 更多