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

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

2.接收表模式
    关于接收表模式在Mule中的实现,我已经作了简单介绍,见《企业集成模式与Mule--接收表模式》一文。
    本文简要介绍接收表模式在ServiceMix中的实现以及简单应用。

3.实现

下面简单地介绍接收表模式在ServiceMix中的实现

在ServiceMix中StaticRecipientList简单地实现了一个静态的接收表模式。
通过它可以将In-Only或者Robust-In-Only消息交互模式的消息转发到recipients列表,该列表中的接收者都可以接收到该消息。

其主要方法的代码片段:

            ....
        //复制消息exchange,将消息in作为其副本
        NormalizedMessage in = MessageUtil.copyIn(exchange);
        //根据recipient的个数,同步或异步循环发送消息
        for (int i = 0; i < recipients.length; i++) {
        
            MessageExchange me = getExchangeFactory().createExchange(
                    exchange.getPattern());
            recipients.configureTarget(me, getContext());
            in.setProperty(RECIPIENT_LIST_COUNT, new Integer(
                            recipients.length));
            in.setProperty(RECIPIENT_LIST_INDEX, new Integer(i));
            in.setProperty(RECIPIENT_LIST_CORRID, exchange.getExchangeId());
            //将消息in中的相关属性以及附件等内容拷贝到消息me中
            MessageUtil.transferToIn(in, me);
      //采用同步的方式发送消息me,该方法调用DeliveryChannel的sendSync()方法同步发送消息
      //如果是采用同步的方式发送,则调用DeliveryChannel的send()方法异步步发送消息
            sendSync(me);//同步发送
            if (me.getStatus() == ExchangeStatus.ERROR && reportErrors) {
                fail(exchange, me.getError());
                return;
            }
        }
    //将消息exchange的状态设置为ExchangeStatus.DONE,表明消息发送完毕
        done(exchange);
.....

4.简单应用

在ServiceMix中使用静态接收表模式
  <eip:static-recipient-list service="test:recipients" endpoint="endpoint">
                        <eip:recipients>
                          <eip:exchange-target service="recipient1" />
                          <eip:exchange-target service="recipient2" />
                          <eip:exchange-target service="recipient3" />
                        </eip:recipients>
    </eip:static-recipient-list>
在此我们在static-recipient-list上设定了3个recipient,分别是recipient1,recipient2和recipient3。
ServiceMix会将消息分发给这3个recipient,我们可以在这3个recipient上接收到相同的消息。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值