Consultor Eletrônico



Kbase 19921: SonicMQ-Example Connection: Java Client Connection to Broker
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   7/3/2000
SUMMARY:

The following example code tests whether a stand-alone Java Client can establish a Progress SonicMQ broker connection. It is assumed that you have compiled the below code below, that you have started the broker, and that you use SonicMQ.bat or the UNIX equivalent to set the environment.
The sample code:


// This is example code
// of a stand-alone Java Client connecting to SonicMQ

// Begin Class definition

class TestConnect {
static String broker = "localhost:2506";

// Begin main method

public static void main (String Args [])
throws javax.jms.JMSException {

// initialize qConnection, qSession

progress.message.jclient.QueueConnection qConnection = null;
javax.jms.QueueSession qSession = null;
try
{
// Create queue connection Factory

progress.message.jclient.QueueConnectionFactory factory;
factory =(new
progress.message.jclient.QueueConnectionFactory(broker));

// Create queue connection

qConnection =
(progress.message.jclient.QueueConnection)
factory.createQueueConnection();

// Create queue session

qSession = qConnection.createQueueSession(true,
javax.jms.Session.AUTO_ACKNOWLEDGE);

// Start connection

qConnection.start();
System.out.print ("Congratulations, You are connected!");

}

// Can't connect message

catch (javax.jms.JMSException jmse)
{
System.err.println("error: Cannot connect to Broker - " + broker);
jmse.printStackTrace();
System.exit(1);
}

} // End main method
} // End Class definition