Article ID: 176815
Article Last Modified on 11/17/2005
//******************************************************************
// msmqjavapp.java: Applet
//
// Note: This code works only with MSMQ 1.0 and Java SDK 2.0.
//*******************************************************************
import java.applet.*;
import java.awt.*;
import mqoa.*;
import com.ms.com.*;
public class msmqjavapp extends Applet implements _DMSMQEventEvents
{
private Thread m_msmqjavapp = null;
private boolean m_fStandAlone = false;
private ConnectionPointCookie cookie = null;
IMSMQQueueInfo msmqQInfo=(IMSMQQueueInfo)new MSMQQueueInfo();
IMSMQQueue msmqRead;
public void start()
{
Variant noParam = new Variant();
noParam.noParam();
msmqQInfo.setPathName (".\\msmqjavaq");
try
{
msmqQInfo.Create (noParam, noParam); // Use defaults }
catch(Exception e)
{
// Add custom exception handling here.
}
try
{
msmqRead=msmqQInfo.Open ( MQACCESS.MQ_RECEIVE_ACCESS,
MQSHARE.MQ_DENY_NONE );
}
catch(Exception e)
{
// Add custom exception handling here.
}
try
{
MSMQEvent msmqEvent = new MSMQEvent();
cookie = new ConnectionPointCookie(msmqEvent, this,
Class.forName("mqoa._DMSMQEventEvents"));
msmqRead.EnableNotification((IMSMQEvent)msmqEvent, noParam,
noParam);
}
catch(Exception e)
{
// Add custom exception handling here.
}
SendMsg("Hello World!");
}
private void SendMsg(String msg)
{
IMSMQQueueInfo msmqQInfo1=(IMSMQQueueInfo)new MSMQQueueInfo();
msmqQInfo1.setPathName (".\\msmqjavaq");
IMSMQQueue msmqRead1=msmqQInfo1.Open ( MQACCESS.MQ_SEND_ACCESS,
MQSHARE.MQ_DENY_NONE );
IMSMQMessage msmqMsg=(IMSMQMessage)new MSMQMessage();
Variant msgbody=new Variant();
msgbody.putString ( msg);
msmqMsg.setBody ( msgbody );
msmqMsg.Send ( msmqRead1, new Variant());
}
private void RecvMsg()
{
IMSMQMessage msmqMsg;
Variant wantbody=new Variant();
wantbody.putBoolean( true );
try
{
msmqMsg=msmqRead.Receive ( new Variant(), new Variant(), wantbody,
new
Variant());
//Show message text in the browser's status bar.
if ( msmqMsg != null )
showStatus(msmqMsg.getBody().getString());
}
catch(Exception e)
{
// Add custom exception handling here.
}
}
// Event handling code.
public void Arrived(Object pdispQueue, int cursor)
{
showStatus("Arrived!");
RecvMsg();
// Add code to re-enable notifications.
}
public void ArrivedError(Object pdispQueue, int lErrorCode, int
cursor)
{
showStatus("ArrivedError!");
// Add code to re-enable notifications.
}
}
179849 HOWTO: Use connectable objects including ActiveX objects in Java
Keywords: kbhowto kbcode KB176815