编写路由调解

使用本主题来创建一个为消息选择特定正向路由的调解。

开始之前

有关将调解与服务集成总线配合使用的简介,请参阅了解调解。有关如何将调解安装到 WebSphere Application Server 中并使它与总线目标相关联的详细信息,请参阅使用调解

本主题假定您熟悉如何使用 Java Platform Enterprise Edition (Java EE) 会话 Bean 开发环境,如 组装工具IBM® Rational® Application Developer

关于此任务

路由调解是包含路由处理程序的调解应用程序。您使路由调解与服务集成总线目标相关联,并使用该调解来从各种可用路由中选择特定路由。例如,当您创建新的出站服务配置修改现有的出站服务配置时,可以应用端口选择调解以便从可供出站服务使用的端口范围中选择特定出站端口。

要创建路由调解,请使用 Java Platform Enterprise Edition (Java EE) 会话 Bean 开发环境以完成以下步骤:

过程

  1. 创建空的调解处理程序项目。 这将创建该项目并创建实现处理程序接口的处理程序类。有关如何执行此操作的详细指示信息,请参阅编写调解处理程序
  2. 使用 EJB 描述符上的调解窗格来将该处理程序类定义为调解处理程序。
    注: 执行此操作时,请指定用来标识该调解处理程序列表的名称。请记录此名称以便以后在总线中创建调解时作为参考。
  3. 将路由函数添加到处理程序中。 在开始之前,请参阅将调解函数添加到处理程序代码中,尤其是阅读它的子主题使用消息上下文。向处理程序类中添加 import 语句,并通过添加路由代码来修改处理方法。通过将路由目标添加到正向路由路径列表开头来指定该目标。正向路由路径列表可以从消息上下文中获得。例如:
    import javax.xml.rpc.handler.MessageContext;
    import com.ibm.websphere.sib.mediation.handler.MediationHandler;
    import com.ibm.websphere.sib.mediation.handler.MessageContextException;
    import com.ibm.websphere.sib.mediation.messagecontext.SIMessageContext;
    import com.ibm.websphere.sib.SIMessage;
    import com.ibm.websphere.sib.SIDestinationAddress;
    import com.ibm.websphere.sib.SIDestinationAddressFactory;
    import java.util.List;
    public class RouteMediationHandler implements MediationHandler {
    
    	public boolean handle(MessageContext ctx) throws MessageContextException {
    		SIMessageContext siCtx = (SIMessageContext) ctx;
    		SIMessage msg = siCtx.getSIMessage();
    		List frp = msg.getForwardRoutingPath();
    		try {
    			SIDestinationAddress destination =
    				SIDestinationAddressFactory
    					.getInstance()
    					.createSIDestinationAddress(
    					"RoutingDestination", //this is the name of the target destination
    					false);
    			frp.add(0, destination);
    		} catch (Exception e) {
    			return false;
    		}
    		msg.setForwardRoutingPath(frp);
    		return true;
    	}
    
    }
    有关服务集成技术类(包括调解处理程序和消息上下文类)的更多信息,请参阅生成的 API 文档 - 应用程序编程接口
  4. 导出路由调解企业应用程序。

下一步做什么

现在,您可以将调解安装到 WebSphere Application Server 中并使它与总线目标相关联,如使用调解中所述。

指示主题类型的图标 任务主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tjw_mediation_routing
文件名:tjw_mediation_routing.html