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上接收相同的消息。
企業集成模式與Mule--接收表模式
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.