users@glassfish.java.net

Re: Accessing a JMS Resource on a Remote Server

From: <glassfish_at_javadesktop.org>
Date: Wed, 02 Jan 2008 11:29:30 PST

Hi!

If I get it right, you'd like to write a stand-alone client program which communicates with a remote AppServer.

First, take a look at this thread:
http://forums.java.net/jive/thread.jspa?threadID=25704&tstart=15

Here's a piece of code which works fine for me:

//the following 2 lines are equivalent with setting Java VM parameters with the same
//name and value (like -Dorg.omg.CORBA.ORBInitialHost=serverhost)
System.setProperty( "org.omg.CORBA.ORBInitialHost", "serverhost" ); //default is localhost
System.setProperty( "org.omg.CORBA.ORBInitialPort", "3700" ); //default

Context jndiCtx = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory) jndiCtx.lookup( "ConnFactJNDIName" );
Destination dest = (Destination) jndiCtx.lookup( "MyQueueOrTopicJNDIName" );
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession( false, Session.AUTO_ACKNOWLEDGE );

MessageProducer producer = session.createProducer( dest );
TextMessage message = session.createTextMessage();
message.setText( "Hello" );
producer.send( message );

Now, you should put the whole thing in a try-catch block, closing the session, connection and jndiCtx with their close() method in the finally block, but the essence of it was this.

I think you'll be able to create a stand-alone message consumer relying on this code.

For me, the application needs the following jar files to be included: lib/javaee.jar lib/appserv-rt.jar lib/appserv-deployment-client.jar lib/appserv-ext.jar lib/appserv-admin.jar lib/imqjmsra.jar from the AppServ directory.

I haven't find a better way to create a stand-alone application yet, if there is any, please correct me!
[Message sent by forum member 'zoltan_kiss' (zoltan_kiss)]

http://forums.java.net/jive/thread.jspa?messageID=251951