Runtime tools : Service components : JCA SNA Connector : JCA SNA LU62 Connector : Tasks : JCA LU62 sample code : Using Inbound Interface for Incoming message
  
Using Inbound Interface for Incoming message
By using MDB, the application can get the information of the arrival of inbound message. The MDB implements Lu62MessageListener interface and specifies the messaging-type and activation-config-property attributes in deployment descriptor of MDB.
The following is an example:
Deployment descriptor of example MDB
<message-driven id="MDBtest2">
  <ejb-name>MDBtest2</ejb-name>
  <ejb-class>ejbs.MDBtest2Bean</ejb-class>
  <messaging-type>
    com.ibm.connector2.sna.lu62.Lu62MessageListener
  </messaging-type>
  <transaction-type>Container</transaction-type>
  <message-destination-type>javax.jms.Queue</message-destination-type>
  <activation-config>
    <activation-config-property>
      <activation-config-property-name>outgoing</activation-config-property-name>
      <activation-config-property-value>false</activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
      <activation-config-property-name>tpName</activation-config-property-name>
      <activation-config-property-value>TPCDL</activation-config-property-value>
    </activation-config-property>
  </activity-config>
</message-driven>
MDB bean class
public class MDBtest2Bean implements
javax.ejb.MessageDrivenBean,
com.ibm.connector2.sna.lu62.Lu62MessageListener {
  ...
  public int onIncomingMessage(String msg, Lu62Conversation conversation) {
  // add the application implementation of handling the inbound message here
  // handling the message
  //send reply message back
  conversation.send(replyMessage);
  }
...
}
Note MDB is anonymous in nature. Therefore, it cannot be directly invoked by a client like session bean or entity bean. When the inbound message comes in, the LU62 Connector will deliver the message to message endpoint, and the onIncomingMessage method will be called by application server.
Inbound Communication for outbound reply message
The outbound message is sent by CCI verb ASYNC_SEND_RECEIVE, and the replied inbound message is received in MDB.
Following is the deployment descriptor of an example MDB:
<message-driven id="MDBtest2">
<ejb-name>MDBtest2</ejb-name>
<ejb-class>ejbs.MDBtest2Bean</ejb-class>
<messaging-type>
com.ibm.connector2.sna.lu62.Lu62MessageListener
</messaging-type>
<transaction-type>Container</transaction-type>
<message-destination-type>javax.jms.Queue</message-destination-type>
<activation-config>
<activation-config-property>
<activation-config-property-name>outgoing</activation-config-property-name>
<activation-config-property-value>true</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>symbolicDestinationName</activation-config-property-name>
<activation-config-property-value>DSCCRIS0</activation-config-property-value>
</activation-config-property>
</activity-config>
</message-driven>
Note The outgoing, symbolicDestinationName and tpName values must match the values of these fields defined in J2C connection factory custom properties.
The outbound code:
initialContext = new javax.naming.InitialContext();
connectionFactory = (ConnectionFactory) initialContext.lookup("snalu62");
Lu62ConnectionSpec lu62ConnectionSpec = new Lu62ConnectionSpec();
lu62ConnectionSpec.setUserName("sna");
lu62ConnectionSpec.setPassword("sna");
Connection cxn = connectionFactory.getConnection(lu62ConnectionSpec);
Interaction ixn = cxn.createInteraction();
Lu62InteractionSpec ixnSpec = new Lu62InteractionSpec();
Lu62Record outgoingData = new Lu62Record();
Lu62Record returnData = new Lu62Record();
ixnSpec.setInteractionVerb(ixnSpec.ASYNC_SEND_RECEIVE);
outgoingData.setData(requestData);
ixn.execute(ixnSpec, outgoingData, null);
ixn.close();
cxn.close();
The MDB handles the reply message for the outbound. The following is the MDB bean class:
public class MDBtest2Bean implements
javax.ejb.MessageDrivenBean,
com.ibm.connector2.sna.lu62.Lu62MessageListener {
…….
public int onOutgoingReplyMessage (String msg) {
……..
// handling the reply message for outgoing message send by CCI
}
……
}
Go up to
JCA LU62 sample code