SOA架构中的事件驱动服务

豆豆网   技术应用频道   2008年01月22日  【字号: 收藏本文

内容摘要:讨论使用Mule实现一个高效的事件驱动和面向服务的平台,一个轻量级的事件-消息架构,企业信息总线(ESB)模式。组件和程序可以使用Mule通过公共的JMS或其他的消息处理技术去实现通信。

  从onCall()方法可返回任何对象。当组件的UMOLifecycleAdapter接收这个对象时,它首先看看这个对象是否是一个UMOMessage;如果这个对象既不是UMOMessage也不是Null,那么以这个对象作为有效载荷去创建一个新的消息。这个新事件经由所配制的出站路有器发布,如果UMO对象已经配制了一个出站路由器,那么在UMOEventContext实例中不能调用setStopFurtherProcessing(true)方法。

  Mule使用的一个简单的事件框架

  让我们把这几段Mule的代码放到一起去构建一个简单的事件框架。这个框架包含一个负责注册和注销事件的管理器,可以接收事件,和负责路有同步和异步消息到他们相应的服务。

  Mule的虚拟机协议要求有一个放置事件管理器工作目录META-INF/services/org/mule/providers/vm路径下的可配制文件,配制文件为协议定义了大量的组件,例如连接器和调度工厂。配制文件的内容如下:

connector=org.mule.providers.vm.VMConnector
dispatcher.factory=org.mule.providers.vm.VMMessageDispatcherFactory
message.receiver=org.mule.providers.vm.VMMessageReceiver
message.adapter=org.mule.providers.vm.VMMessageAdapter
endpoint.builder=org.mule.impl.endpoint.ResourceNameEndpointBuilder

  一个简单的借口定义了事件管理器的公有结构:

package com.jeffhanson.mule;
  
import org.mule.umo.FutureMessageResult;
  
public interface EventManager
{
  /**
  * Sends an event message synchronously to a given service.
  *
  * @param serviceName  The name of the service to which the event
  *            message is to be sent.
  * @param payload    The content of the event message.
  * @return Object    The result, if any.
  * @throws EventException on error
  */
  public Object sendSynchronousEvent(String serviceName,
                   Object payload)
   throws EventException;
  
  /**
  * Sends an event message asynchronously to a given service.
  *
  * @param serviceName  The name of the service to which the event
  *            message is to be sent.
  * @param payload    The content of the event message.
  * @return FutureMessageResult The result, if any.
  * @throws EventException on error
  */
  public FutureMessageResult sendAsynchronousEvent(String serviceName,
                          Object payload)
   throws EventException;
  
  /**
  * Starts this event manager.
  */
  public void start();
  
  /**
  * Stops this event manager.
  */
  public void stop();
  
  /**
  * Retrieves the protocol this event manager uses.
  * @return
  */
  public String getProtocol();
  
  /**
  * Registers a service to receive event messages.
  *
  * @param serviceName   The name to associate with the service.
  * @param implementation  Either a container reference to the service
  *             or a fully-qualified class name.
  */
  public void registerService(String serviceName,
                String implementation)
   throws EventException;
  
  /**
  * Unregisters a service from receiving event messages.
  *
  * @param serviceName The name associated with the service to unregister.
  */
  public void unregisterService(String serviceName)
   throws EventException;
}

责编:豆豆技术应用

正在加载评论...