在消息头中设置路由地址

可以向以前存在的调解处理程序添加函数以在消息头中设置路由地址。

开始之前

开始执行此任务之前,应该已在 EJB 项目中创建基本的调解处理程序(请参阅编写调解处理程序)。

关于此任务

要处理路由地址,您将使用 SIDestinationAddress 和 SIDestinationAddressFactory API。SIDestinationAddress 是一个表示服务集成总线的公共接口,它使您的调解能够访问目标的名称和总线名称。SIDestinationAddressFactory 使您能够创建新的 SIDestinationAddress 来表示服务集成总线目标。有关这些 API 的参考信息,请参阅SIDestinationAddressSIDestinationAddressFactory

过程

  1. 在调解处理程序的方法 handle (MessageContext context) 中找到要插入功能性调解代码的位置。接口为 MessageContext,除非您仅对 MessageContext 提供的方法感兴趣,否则应该将此接口强制转换为 SIMessageContext。
  2. 从 MessageContext 对象中获取 SIMessage。 例如:
    SIMessage message = ((SIMessageContext)context).getSIMessage();
  3. 使用以下基本步骤来构建调解头函数:
    1. 获取运行时环境的句柄。 例如:
      .... SIMediationSession mediationSession = mediationContext.getSession(); 
    2. 创建要在克隆的对象上设置的转发路由路径。 例如,使用 Vector 类来创建可扩展的对象数组。
    3. 获取创建 SIDestinationAddress 实例时要使用的 SIDestinationAddressFactory。 例如:
      SIDestinationAddressFactory destFactory = SIDestinationAddressFactory.getInstance();
    4. 创建新的 SIDestinationAddress,它表示服务集成总线目标。 例如:
      SIDestinationAddress dest = destFactory.createSIDestinationAddress(remoteDestinationName(),false);
      在这种情况下,第二个参数(布尔值“false”)指示不应该对本地消息传递引擎将目标本地化,但是可以在服务集成总线上的任何位置将其本地化。
    5. 使用 Vector 类的 add 方法来将另一个目标名称添加到数组。
    6. 克隆该消息,并修改克隆的消息中的转发路由路径。 例如:
      clonedMessage.setForwardRoutingPath(forwardRoutingPath);
    7. 使用 SIMediationSession 接口中的 send 方法来发送克隆的消息,以将该消息发送至服务集成总线。 例如,如果将该消息命名为“clonedMessage”:
      mediationSession.send(clonedMessage, false);
  4. 返回 true,以确保传递到 MediationHandler 接口的 handle 方法中的消息继续保留在处理程序链中。

示例

用于更改转发路由路径的完整调解功能代码可能类似于以下示例:
/* A sample mediation that clones a message 
 * and sends the clone off to another destination  */

public class RoutingMediationHandler implements MediationHandler {

		public String remoteDestinationName="newdest";

	public boolean handle(MessageContext context) throws MessageContextException {
				SIMessage clonedMessage = null;
				SIMessageContext mediationContext = (SIMessageContext) context;
				SIMessage message = mediationContext.getSIMessage();
		SIMediationSession mediationSession = mediationContext.getSession(); 
				// Create a forward routing path that will be set on the cloned message
				Vector forwardRoutingPath = new Vector();
				SIDestinationAddressFactory destFactory = 
        SIDestinationAddressFactory.getInstance();
				SIDestinationAddress dest = 
        destFactory.createSIDestinationAddress(remoteDestinationName,false);
		forwardRoutingPath.add(dest);
		
		try {
			// Clone the message
						clonedMessage = (SIMessage) message.clone();
						// Modify the forward routing path for the clone
						clonedMessage.setForwardRoutingPath(forwardRoutingPath);
						// Send the message to the next destination in the frp
			mediationSession.send(clonedMessage, false);
		} catch (SIMediationRoutingException e1) {
			e1.printStackTrace();
		} catch (SIDestinationNotFoundException e1) {
			e1.printStackTrace();
		} catch (SINotAuthorizedException e1) {
			e1.printStackTrace();
		} catch (CloneNotSupportedException e) {
						// SIMessage should clone OK so you shouldn't need to enter this block
			e.printStackTrace();
		}
				// allow original message to continue on its path
				return true;
	}

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



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