Application Server: Websphere 8.5.5, RAD8.5,
Application: SampleMediation
What the application do: the application mediates any message coming on one destination to the other specified destination
Create Application Structure as below
>SampleMediation (EAr Project)
>SampleMediationEJB (ejb project)
>Mediation (java project)
Under Mediation Add a sample mediation handler as below:
public class FirstMediationHandler implements MediationHandler {
private String outDestination = "out.queue";
@Override
public boolean handle(MessageContext msgCtx) throws MessageContextException {
System.out.println("--incoming--");
SIMessageContext siMsgCtx = (SIMessageContext) msgCtx;
SIMessage originalMsg = siMsgCtx.getSIMessage();
//you do loads of thing, like transformation
List frp = new ArrayList(1);
SIDestinationAddress dest = SIDestinationAddressFactory.getInstance().createSIDestinationAddress(outDestination, false);
frp.add(dest);
originalMsg.setForwardRoutingPath(frp);
System.out.println("--routed--");
return true;
}
}
>SampleMediationEJB (ejb project), add ejb-jar.xml and ws-handler.xmi
ejb-jar.xml should have following<session id="FirstMediationHandler">
<ejb-name>FirstMediationHandler</ejb-name>
<local-home>com.ibm.websphere.sib.mediation.handler.ejb.GenericEJBMediationHandlerLocalHome</local-home>
<local>com.ibm.websphere.sib.mediation.handler.ejb.GenericEJBMediationHandlerLocal</local>
<ejb-class>com.ibm.websphere.sib.mediation.handler.ejb.GenericEJBMediationHandlerBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>mediation/MediationHandlerClass</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>com.vsp.test.FirstMediationHandler</env-entry-value>
</env-entry>
</session>
ws-handler.xmi should have the following
<handler:EJBHandlerDD xmi:id="EJBHandlerDD1" name="FirstMediationHandler" description="" critical="true">
<lists xmi:id="HandlerListRef1" listName="first_mediation" description="mediates from vcin_in to cch_in" sequence="1"/>
<ejb xmi:type="ejb:Session" href="META-INF/ejb-jar.xml#FirstMediationHandler"/>
</handler:EJBHandlerDD>
Thats it build the ear and do the setup as below.
Setup:
1) Create a local bus - bus1,
2) Create two destinations - out.queue and in.queue
3) Configure queues
- jms/out.queue for destination out.queue
- jms/in.queue for destination in.queue
4) Deploy the SampleMediation.ear
5) Create new Mediation in websphere,
Buses > bus1 > Mediations - create new, following values are entered
name = first_mediation
Handler list name = first_mediation
6) Mediate the destination
Go to Buses > bus1 > Destinations > in.queue select it by clicking the checkbox
and click the Mediate button on the top
7) Select Mediation
The mediation to apply to this destination = first_mediation
8) The mediation would be up and working and any message coming on the in.queue is routed to out.queue
No comments:
Post a Comment