Developing an MSMQ Server
Gopalan Suresh Raj

Note
To work with any of these samples, you will need the following:
.........................................Microsoft Visual J++ ver 6.0
.........................................Windows NT 4.0 Options Pack

1. Generate Java class wrappers from type libraries
Create simple Java class wrappers to call MSMQ Automation COM Objects. The JActiveX utility generates Java source code from type libraries. The DLL containing MSMQ type libraries can be located in \WINNT\System32 directory, and is called mqoa.dll.

D:\Program Files\Microsoft Visual Studio\VJ98>
D:\Program Files\Microsoft Visual Studio\VJ98>JActiveX /javatlb c:\winnt\system32\mqoa.dll
Microsoft TypeLib Importer For Java V5.00.2918
Copyright (C) 1997-1998 by Microsoft Corporation.
IMSMQMessage.java(Class): warning: skipped. Name is a keyword or conflicts with another member.
MQBOID.java(rgb): warning: skipped. Untranslatable typelib object.
MQXACTTRANSINFO.java(uow): warning: skipped. Cannot be used as a structure field.

D:\Program Files\Microsoft Visual Studio\VJ98>

The generated source code is placed in the \WINNT\Java\trustlib\mqoa directory of your machine.

2. Develop the Server

MSMQServer.java
import com.ms.com.*;
import mqoa.*;

public class MSMQServer
{
 
/**
   * The main entry point for the application
   *
   * @param args Array of parameters passed to the
   * application via the comand line.
   */

  public static void main(String[] args)
  {
   
// This is the typeid that will be associated with the
    // new queue

    String typeID = "{E9E8CB90-D05E-11d2-B9D0-006097A7D34F}";
 
    Variant variantTrue = new Variant();
    Variant variantNoParam = new Variant();
    Variant guid = new Variant();
    Variant nop = new Variant((int)RELOPS.REL_NOP);
    Variant isEqual = new Variant((int)RELOPS.REL_EQ);
    Variant oneSecondDelay = new Variant();
    Variant theBody = new Variant();
    Variant transactionHolder = new Variant();
 
    IMSMQQueueInfo queueInfo = (IMSMQQueueInfo)new MSMQQueueInfo();
    IMSMQQueue queue = null;
    IMSMQMessage message = new MSMQMessage();
    IMSMQTransactionDispenser transactionDispenser = new MSMQTransactionDispenser();
    IMSMQTransaction transaction;

 
   
//Setting the variables
    variantTrue.putBoolean(true);
    variantNoParam.noParam();
    oneSecondDelay.putInt(1000);
 
    queueInfo.putPathName(".\\testQueue");
    queueInfo.putLabel("testQueue");
    queueInfo.putJournal(MQJOURNAL.MQ_JOURNAL);
    queueInfo.putServiceTypeGuid(typeID);

 
    try
    {
      queueInfo.Create(variantTrue,variantTrue);
    }
    catch(ComFailException except)
    {
    }
 
    queue = queueInfo.Open(MQACCESS.MQ_SEND_ACCESS, MQSHARE.MQ_DENY_NONE);
    theBody.putString("This is a test");
    message.putBody(theBody);
    message.putJournal(MQMSGJOURNAL.MQMSG_JOURNAL);
 
    transaction = transactionDispenser.BeginTransaction();

    try
    {
      transactionHolder.putDispatch(transaction);
      message.Send(queue,transactionHolder);
      transaction.Commit(variantNoParam, variantNoParam, variantNoParam);

    }
    catch(Exception transactionFailed)
    {
      transaction.Abort(variantNoParam, variantNoParam);
    }
  }
}



2. Compile and run the Server

 

click here to go to the
Developing a Simple MSMQ Client Page...
click here to go to
My MSMQ HomePage...

Go to the Component Engineering Cornucopia page

This site was developed and is maintained by Gopalan Suresh Raj

This page has been visited times since March 01,1999.

Last Updated : Mar 01,'99

If you have any questions, comments, or problems regarding this site, please write to me I would love to hear from you.


Copyright (c) 1997-99, Gopalan Suresh Raj - All rights reserved. Terms of use.

All products and companies mentioned at this site,are trademarks of their respective owners.