企业集成模式与Mule--接收表模式

编程技术  /  houtizong 发布于 3年前   85

Gregor Hohpe在《Enterprise Integration Patterns 》一书中讲述了几十种企业集成模式 (Enterprise Integration Pattern,EIP )。
目前企业集成模式 一共有65种。

本文介绍其中的一种接收表模式(Recipient List)。

1.读者要求 :了解企业集成模式,了解Mule.

2.接收表模式 :将消息分发到多个通道中,消息消费者通过这些通道接收消息。

3.使用场景 :在使用邮件的过程中,我们可以将一封邮件分发给多个邮件地址,这就是接收表模式的一个简单应用,在这里邮件相当于
消息,邮件地址相当于通道,消息消费者相当于邮箱的使用者。

4.接收表模式在Mule中的实现
StaticRecipientList 简单地实现了一个静态的接收表模式,静态是指在配置文件中指定消息的通道。
下面是其主要方法的代码片段:
....
//从message的熟悉中获得recipients
List recipients = this.getRecipients(message);
//将消息发送到每个recipient上。
for (Iterator iterator = recipients.iterator(); iterator.hasNext;){
     Object recipient = iterator.next();
      request = new DefaultMuleMessage(message.getPayload(), message);
      endpoint = this.getRecipientEndpoint(request, recipient);
      try {
            //将消息发送或者分发到每个端点上,消息接受者可以在端点上接收消息。
      if (synchronous) {
                    result = this.send(session, request, endpoint);
                    if (result != null) {
                           results.add(result.getPayload());
                   }
            }else {
             this.dispatch(session, request, endpoint);
        }
             } catch (MuleException e) {
                        throw new CouldNotRouteOutboundMessageException(request,endpoint, e);
              }
     }
.....

5.在Mule中使用静态接收表模式

<static-recipient-list-router >
                    <recipients>
                        <spring:value>vm://recipient1</spring:value>
                        <spring:value>vm://recipient2</spring:value>
                        <spring:value>vm://recipient3</spring:value>
                    </recipients>
</static-recipient-list-router>
         上述的配置文件中,我们给static-recipient-list-router设定了3个recipient,分别是vm://recipient1,vm://recipient2和vm://recipient3。
Mule会将消息分发给这3个recipient,我们可以在这3个recipient上接收相同的消息。

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客