Sample Java application for retrieving asynchronous callout requests
To prepare a non-MDB Java™ application for inbound requests from an IMS application program, specify the appropriate interaction verb, the asynchronous hold queue name, and a timeout value in the Java application.
- Specify the asynchronous hold queue
name.
interactionSpec.setAltClientID(calloutQueueName);
- Set the interactionVerb property to
SYNC_RECEIVE_CALLOUT.
interactionSpec.setInteractionVerb(com.ibm.connector2.ims.ico. IMSInteractionSpec.SYNC_RECEIVE_CALLOUT);
- Specify an execution timeout value (in
milliseconds).
Specify a timeout value to wait for a callout request message in the hold queue. In this example, a large execution timeout value is specified. A large execution timeout value helps to minimize the looping required in a callout EJB component when there might be long periods of time when no callout requests occur. The length of the timeout depends on the maximum length of time that you expect to elapse between your callout requests and what you want your EJB component to do if that length of time is exceeded.interactionSpec.setExecutionTimeout(3600000);
The following sample code shows an example of a Java application that is configured to receive the callout requests.
// JNDI lookup returns connFactory
InitialContext initCntx = new InitialContext();
ConnectionFactory connFactory =
(ConnectionFactory) initCntx.lookup("java:comp/env/ibm/ims/IMSTarget");
IMSConnectionSpec connSpec = new IMSConnectionSpec();
Connection connection = connFactory.getConnection(connSpec);
Interaction interaction = connection.createInteraction();
IMSInteractionSpec interactionSpec = new IMSInteractionSpec();
//set the commit mode and sync level
interactionSpec.setCommitMode(0);
interactionSpec.setSyncLevel(1);
// An eight-character queue name that the asynchronous messages to be retrieved from
String calloutQueueName = new String ("CALLOUTQ");
// Set the asynchronous queue name for the callout message
interactionSpec.setAltClientID(calloutQueueName);
// Set interactionVerb to retrieve async output with a timeout
interactionSpec.setInteractionVerb(com.ibm.connector2.ims.ico.
IMSInteractionSpec.SYNC_RECEIVE_CALLOUT);
interactionSpec.setExecutionTimeout(3600000);
for (;;) {
try {
// Execute the interaction
iteraction.execute(interactionSpec, null, calloutMsg);
// Further processing on the calloutMsg
:
} catch (Exception e) {
// if the exception is an execution timeout error,
// you can either do nothing and continue to loop
// or process the error and then break the loop
break;
}
}
iteraction.close();
connection.close();