JMS invoker

BTT JMS invoker is used to send and receive JMS message. Because the SOA is based on ESB, and ESB is based on the message engine, BTT provides support for JMS message. You can send and receive message synchronously or subscribe inbound JMS message asynchronously by using the BTT JMS Invoker.

The message endpoint may be on the ESB or on Websphere. For the BTT JMS Invoker, the message endpoint is transparent. There is no difference between accessing both types of message endpoint. The message endpoint may be JMS topic or JMS queue.

Table 1. Property of BTT JMS Invoker
Property ID Type Default Value Description
jmsConnectionFactoryName String "" (empty String) JNDI name of JMS connection factory.
sendDestinationName String "" (empty String) JNDI name of JMS Queue or Topic to which message is sent.
receiveDestinationName String "" (empty String) JNDI name of JMS queue or Topic from which message is received.
jmsType String "" (empty String) JMS type name.
targetFunctionName String "" (empty String) Target function name of JMS.
deliveryPersistent Boolean false Whether the delivery of message is persistent.

Following are the examples of how to use JMS invoker:

  1. Send message synchronously

    Following is the sample definition:

    <JMS  id="packageSend"  connectionFactory="jms/TheConnectionFactory" 
    				sendDestination="PackageReceivedModule/MDBImport_SEND_D" > 	
    	<parameters>
    		<parameter id="input" />   <!-- parameter attribe ‘type’ is not needed in JMS invoker -->
    	</parameters>
    </JMS>

    Following is the sample code:

    InvokerFactory ivf = new InvokerFactory("jar:///com/ibm/btt/ut/invoker.xml");
    JMSInvoker inv =(JMSInvoker) ivf.createInvoker("packageSend");
    LinkedHashMap<String,Parameter> map=inv.getParameters();
    ((Parameter) map.get("input")).setValue(" outgoing message ...");
    inv.execute(InvokerUtils.convertParametersToObjects(map);
  2. Receive message synchronously

    Following is the sample definition:

    <JMS  id="packageReceive"  connectionFactory="jms/TheConnectionFactory" 
    			receiveDestination="PkgRecvMod/JMSExport1_Receive_D" /> 	

    Following is the sample code:

    InvokerFactory ivf = new InvokerFactory("jar:///com/ibm/btt/ut/invoker.xml");
    Invoker inv = ivf.createInvoker("packageReceive");
    Object result=inv.execute(null);
    //or use:  result =inv.execute(null, 5000);
    System.out.println(“Message Received :”+result);
  3. Send and Receive message synchronously

    Following is the sample definition:

    <JMS id="packageSendReceive"  connectionFactory="jms/TheConnectionFactory" 	
         sendDestination="PkgRecvMod/JMSExport1_Receive_D" 
    	    receiveDestination="PkgRecvMod/JMSExport1_Receive_D" > 
    	<parameters>
    		<parameter id="input" />
    	</parameters>
    </JMS>
    Note: The sendDestination and receiveDestination can either be the same or different.

    Following is the sample code:

    InvokerFactory ivf = new InvokerFactory("jar:///com/ibm/btt/ut/invoker.xml");
    Invoker inv = ivf.createInvoker("packageSendReceive");
    String message="out going message ";
    Object result=inv.execute(new Object[]{message });
    //or use:  result =inv.execute(new Object[]{message }, 5000);
    System.out.println(“Message Received :”+result);
  4. Send and Receive message asynchronously

    Following is the sample definition:

    <JMS  id="packageSendReceive"  connectionFactory="jms/TheConnectionFactory" 
    			sendDestination="PkgRecvMod/JMSExport1_Receive_D" 
          receiveDestination="PkgRecvMod/JMSExport1_Receive_D" > 
    	<parameters>
    		<parameter id="input" />
    	</parameters>
    </JMS>
    Note: The sendDestination and receiveDestination can either be the same or different.

    Following is the sample code:

    InvokerFactory ivf = new InvokerFactory("jar:///com/ibm/btt/ut/invoker.xml");
    Invoker inv = ivf.createInvoker("packageSendReceive");
    String message="out going message ";
    inv.execute(new Object[]{message}, new myJMSCallBack(), 5000);
    
    public class MYJMSCallBack implements CallBackPoint {
    
    	public void onCallBack(Object result) {
                   // handle received JMS message
     		System.out.println("######### JMS onMessage :"+result);
    	}
    
    	public void onError(Exception e) {
    // handle exception
    		 e.printStackTrace();
    	}
    
          	public void onTimeout() {
    	    // handle timeout
    	   System.out.println("timeout");
    
    	}
    }
  5. Receive inbound message asynchronously

    Following is the sample definition:

    <JMS  id="pacakgeReceive"  connectionFactory="jms/TheConnectionFactory" 
          receiveDestination="PkgRecvMod/JMSExport1_Receive_D" /> 

    Following is the sample code:

    InvokerFactory ivf = new InvokerFactory("jar:///com/ibm/btt/ut/invoker.xml");
    Invoker inv = ivf.createInvoker("pacakgeReceive");
    String message="out going message ";
    inv.execute(new Object[]{message}, new myJMSCallBack(), 0);