메시지 헤더에 라우팅 주소 설정

기존 중개 핸들러에 기능을 추가하여 메시지 헤더에 라우팅 주소를 설정할 수 있습니다.

시작하기 전에

이 태스크를 시작하기 전에 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. 복제된 오브젝트에 설정할 전달 라우팅 경로를 작성하십시오. 예를 들어, 벡터 클래스를 사용하여 오브젝트의 확장 가능한 배열을 작성하십시오.
    3. SIDestinationAddress 인스턴스 작성에 사용할 SIDestinationAddressFactory를 가져오십시오. 예를 들어 다음과 같습니다.
      SIDestinationAddressFactory destFactory = SIDestinationAddressFactory.getInstance();
    4. 서비스 통합 버스 대상을 표시하는 새 SIDestinationAddress를 작성하십시오. 예를 들어 다음과 같습니다.
      SIDestinationAddress dest = destFactory.createSIDestinationAddress(remoteDestinationName(),false);
      이 경우, 두 번째 매개변수인 부울 "false"는 대상이 로컬 메시징 엔진으로 로컬화되지 않아야 하지만 서비스 통합 버스의 모든 위치에 존재할 수 있음을 나타냅니다.
    5. 벡터 클래스의 추가 메소드를 사용하여 배열에 다른 대상 이름을 추가하십시오.
    6. 메시지를 복제하고 복제된 메시지의 전달 라우팅 경로를 수정하십시오. 예를 들어, 다음과 같습니다.
      clonedMessage.setForwardRoutingPath(forwardRoutingPath);
    7. 메시지를 서비스 통합 버스에 보내기 위해 SIMediationSession 인터페이스에서 전송 방식을 사용하여 복제된 메시지를 보내십시오. 예를 들어, 이름이 "clonedMessage"로 지정된 경우:
      mediationSession.send(clonedMessage, false);
  4. true를 리턴하여 MediationHandler 인터페이스의 핸들 메소드로 전달되는 메시지가 계속 핸들러 체인을 따르는지 확인하십시오.

전달 라우팅 경로를 변경하는 전체 중개 기능 코드는 다음 예제와 유사합니다.
/* 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