Designing with Communication Adapters

Installing the MSMQ DLL and JNI Files

The MSMQ adapter installation includes two additional components (as well as the Enterprise Manager Plug-In), as seen in the following figure , that must be downloaded and installed for the MSMQ adapter:

ProcedureTo Download the MSMQ DLLs and Runtime JNI

  1. From the Sun Java Composite Application Platform Suite Installer, click the DOWNLOADS tab. The MSMQ DLLs and Runtime JNI Component list are available from the Repository Downloads list.

  2. Download both files to a local directory. For directions on adding the msmqjni.jar file to the Windows Environment path, see To Add the Runtime JNI File. For directions on adding the DLL files to the PATH for the App Server process, see To Add the DLL Files to the Environment Path.

ProcedureTo Add the Runtime JNI File

  1. Prior to creating your MSMQ adapter Project, copy the Runtime JNI (msmqjni.jar), downloaded from the Suite Installer, to the following locations:


          
    JavaCAPS6\netbeans\lib\ext
          JavaCAPS6\appserver\is\lib

    where JavaCAPS6 is the directory in which Sun Java Composite Application Platform Suite is installed.

    These file must be copied manually.


    Note –

    You need to copy the msmqjni.jar file to the \compile\lib\ext folder before deploying and running command line codegen. You also need to copy the msmqjni.jar file to the c:\Sun\ApplicationServer\lib folder before deploying and running via the Sun Java System Application Server Enterprise Edition 8.1.


ProcedureTo Add the DLL Files to the Environment Path

The Runtime win32 bridge DLL files must be added to a directory that is included in the Windows Environment System Variable Path before running an MSMQ Project. To make sure that the correct file is added to the proper path location, do the following:

  1. Locate the msmqruntimejni.zip file that you downloaded to a local folder.

  2. Extract the ZIP file to a directory that is part of the Windows Environment path.

Enabling Rollback When an MSMQ Message Fails

Procedure To Roll back an Outbound MSMQ Message

In order to roll back an outbound MSMQ message when a failure occurs in the Java Collaboration Definition (for example, failure to insert a duplicate row into a database table that is defined to have unique keys), do the following:

  1. Select Manual as the MSMQ Connection Mode in the outbound MSMQ adapter Connectivity Map properties .

  2. Use the following JCD code:


    try {
        MSMQClient_1.getEwayConfiguration().setOutMSMQName( "public" );
        MSMQClient_1.getEwayConfiguration().setOutMSMQShareMode( "DENY_RECEIVE_SHARE" );
        MSMQClient_1.getEwayConfiguration().setOutMSMQReceiveActionCode
    ( "ACTION_PEEK_CURRENT" );
        MSMQClient_1.connect();
        MSMQClient_1.getMSMQMessage();
        TestDB_1.getTEST1().insert();
        TestDB_1.getTEST1().setTESTSTRING( "From JCD" );
        TestDB_1.getTEST1().insertRow();
        MSMQClient_1.getEwayConfiguration().setOutMSMQReceiveActionCode
    ( "ACTION_RECEIVE" );
        MSMQClient_1.getMSMQMessage();
        MSMQClient_1.disconnect();
    } catch ( Exception Catch ) {
        MSMQClient_1.disconnect();
    }

    The key code items are highlighted in bold. You must also use a try/catch block to catch the exception (for this example, the error is a failed insert to database).

  3. Open the queue with the following settings:

    • MSMQ Share Mode– DENY_RECEIVE_SHARE: This locks the queue so that other applications cannot open the queue in Receive mode. Until your application closes the queue, no other application can open the queue to receive the message.

    • MSMQ Receive Action Code– ACTION_PEEK_CURRENT: This opens the queue so you can “peek” (view) the message.

  4. Next, try a database update on the message you received from the queue. If this fails, move on to step 7 (close the queue instance). If that succeeds, change the adapter configuration properties to receive messages programmatically in this manner .

  5. Next, receive the message. This removes the message from queue.

  6. Disconnect from the queue.

  7. Finally, close the queue using MSMQClient_1.disconnect(). This closes the current queue instance and unlocks the queue.