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

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上接收相同的消息。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值