使用 flex 4(MATE MVC) 和 MSMQ 集成

发布于 2024-10-11 17:45:49 字数 336 浏览 0 评论 0原文

我正在空气中做一个应用程序(flex4),因为这是我的第一个应用程序,我需要一些建议来完成集成部分。

我的系统和后端之间的所有集成都必须使用 MSMQ 完成,好吧,我听说过一些库可以导入到我的 Flex 项目中以在 MSMQ 队列中放置和读取消息,但这不是我的双体,我我想知道,这是如何进行这种通信的好方法,我的意思是,我是否应该有一个名为 MSMQService 的动作脚本类,并且在那里,我应该具有在队列中放入和读取的功能?或者我应该在 Mate 中创建一个新的自定义标签,并有单独的 eventMap 只是为了处理集成?!我知道有很多方法,但如果有人已经这样做了,我想知道你是怎么做的,比如一些好的模式。

感谢您的帮助!

I`m doing an application in air(flex4), as this is my first app, I need some advices to do the integration part.

All integration between my system and the back-end have to be done using MSMQ, alright, I have heard some libs that I can import inside my flex project to put and read messages in the MSMQ queue, but this is not my doublet, I would like to know, how it`s a good approach to do this communication, what I mean is, should I have an actionscript class, called for example MSMQService, and there, I should have the functions to put and read in the queue? or should I create a new custom tag in Mate, and have separate eventMap just to deal with the integration?! I know that there are lots approach, but if someone already done that, I would like to know how you did, like some good patterns.

Thanks for all help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜夜流光相皎洁 2024-10-18 17:45:49

首先,我从未使用过 MSMQ,我的答案通常是 Mate 和服务器通信(基于我的观点和 3 个月的经验)。

其次,我认为您的通信类不需要另一个 eventMap

我当前项目的结构概述:

  • 视图类,仅负责显示用户界面,我们尝试在其中不包含任何应用程序逻辑。
  • 控制器类,一个大的全视eventMap和一堆事件。 eventMap 包含“什么 view.event 触发什么 model.function”的逻辑。 “eventMap”中不得有任何计算或其他应用程序逻辑。
  • modelMap 负责绑定模型和视图之间的单向链接,描述当模型中的某些内容发生更改时视图类 (UI) 中必须更改的内容。 modelMap 不得允许视图类直接操作模型,这违反了 MVC
  • 模型类(负责应用程序逻辑的类)的原则。那里还有交流课程。像“ServerCommunicationManager”这样的类,发送 GET/POST/tec 请求并请求响应

MATE 逻辑:

1.) 某些视图类被操纵,并且该视图发送了一些事件。示例:具有名称和密码的用户按下登录按钮 (RegisterScreen.mxml)

dispatchEvent(new UserRequest(UserRequest.AUTHENTICATION, name, password));

2.) eventMap 实例接收 EventHandler 中的事件并调用 中的某些方法ServerCommunicationManager 类。示例:

<EventHandlers type="{UserRequest.AUTHENTICATION}">
   <MethodInvoker generator="ServerCommunicationManager"
                  method="signUser"
                  arguments="{[event.name, event.password]}" />
</EventHandlers>

3.) 调用模型类方法。示例:我的示例已失效!

public function signUser(user:String, password:String):void
{
   var passwordEncoded:String = encodePassword(password);
   var jsonMessage:Object = new Object();
   jsonMessage.type = "checkUser";
   jsonMessage.name = name;
   jsonMessage.password = passwordEncoded;

   sendGetRequest(serverIP, json, receiveResponseHandler);
}

public function receiveResponseHandler(response:Object)
{
   var userDetails:UserDetails = decodeJsonToUser(response);

   if(userDetails is NoUser)
   {
      FlexGlobals.topLevelApplication.dispatchEvent(new ServerResponseEvent(ServerResponseEvent.NO_USER));
   }
   else if(userDetails is NormalUser)
   {
      FlexGlobals.topLevelApplication.dispatchEvent(new ServerResponseEvent(ServerResponseEvent.NORMAL_USER, userDetails));
   }
   else if(userDetails is Administrator){...} else ...
}

4.) 返回 EventMap

<EventHandlers type="{ServerResponseEvent.NORMAL_USER}">
   <PropertySetter generator="UserModel"
                   targetId="signedUser"
                   source="{event.userDetails}"/>
</EventHandlers>
<EventHandlers type="{ServerResponseEvent.NoUser}">
   <PropertySetter generator="UserModel"
                   targetId="signedUser"
                   source="null"/>
   <PropertySetter generator="ViewModel"
                   targetId="state"
                   source="loginDenied"/>
</EventHandlers>

modelMap

<Injectors target="{RegisterScreen}">
    <PropertyInjector targetKey="state" 
                      source="{ViewModel}" 
                      sourceKey="state" />
    <PropertyInjector targetKey="userName" 
                      source="{UserModel}" 
                      sourceKey="signedUser"/>
</Injectors>

概述:在这种方法中,您可以成功地将视图类与通信类分离。到目前为止,它在我们的项目中运行稳定。

编辑:由于我对 Mate 比较陌生,如果有人发现我的方法有错误,他必须对此发表评论。如果其中某些逻辑部分或完全错误,这对我来说非常重要。

First, I've never used MSMQ and my answer will be generally for Mate and server communication(due to my point of view and 3 months experience).

Second, I don't think that your communication classes need another eventMap.

Overview of the structure of my current project:

  • view classes, responsible only for showing user interface, we tried to not include any application logic in them.
  • controller classes, one big all-seeing eventMap and bunch of events. The eventMap include logic for 'what view.event triggers what model.function'. There must be NO calculations or other application logic in the 'eventMap'.
  • modelMap responsible for binding the one direction link between model and view, describing what must change in the view classes (UI) when something is changed in the model. modelMap MUST NOT allow the view classes to directly manipulate model, it is against principles of MVC
  • model classes - the classes responsible for application logic. Also the communication classes are there. Something like `ServerCommunicationManager, class sending GET/POST/tec requests and requesting for response

MATE logic:

1.) Some View class is manipulated and this view sent some event. Example: user with name and password presses the login button (RegisterScreen.mxml)

dispatchEvent(new UserRequest(UserRequest.AUTHENTICATION, name, password));

2.) The eventMap instance receives the event in EventHandler and invokes some method in the ServerCommunicationManager class. Example:

<EventHandlers type="{UserRequest.AUTHENTICATION}">
   <MethodInvoker generator="ServerCommunicationManager"
                  method="signUser"
                  arguments="{[event.name, event.password]}" />
</EventHandlers>

3.) The model class method is invoked. Example: my example is stubbed!

public function signUser(user:String, password:String):void
{
   var passwordEncoded:String = encodePassword(password);
   var jsonMessage:Object = new Object();
   jsonMessage.type = "checkUser";
   jsonMessage.name = name;
   jsonMessage.password = passwordEncoded;

   sendGetRequest(serverIP, json, receiveResponseHandler);
}

public function receiveResponseHandler(response:Object)
{
   var userDetails:UserDetails = decodeJsonToUser(response);

   if(userDetails is NoUser)
   {
      FlexGlobals.topLevelApplication.dispatchEvent(new ServerResponseEvent(ServerResponseEvent.NO_USER));
   }
   else if(userDetails is NormalUser)
   {
      FlexGlobals.topLevelApplication.dispatchEvent(new ServerResponseEvent(ServerResponseEvent.NORMAL_USER, userDetails));
   }
   else if(userDetails is Administrator){...} else ...
}

4.) Back in the EventMap

<EventHandlers type="{ServerResponseEvent.NORMAL_USER}">
   <PropertySetter generator="UserModel"
                   targetId="signedUser"
                   source="{event.userDetails}"/>
</EventHandlers>
<EventHandlers type="{ServerResponseEvent.NoUser}">
   <PropertySetter generator="UserModel"
                   targetId="signedUser"
                   source="null"/>
   <PropertySetter generator="ViewModel"
                   targetId="state"
                   source="loginDenied"/>
</EventHandlers>

And in the modelMap:

<Injectors target="{RegisterScreen}">
    <PropertyInjector targetKey="state" 
                      source="{ViewModel}" 
                      sourceKey="state" />
    <PropertyInjector targetKey="userName" 
                      source="{UserModel}" 
                      sourceKey="signedUser"/>
</Injectors>

Overview: In this approach you can successfully decopulate view classes from communication classes. It works stable so far in our project.

Edit: Since I'm relatively new to Mate, if someone see errors in my approach he MUST make a comment about it. It really important for me if some of this logic is partially or entirely wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文