HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"The Java Message Service"
Vol. 6, Issue 3, p. 42

	




Listing 1

Properties env = new Properties();
// ... specify the JNDI properties specific to the JNDI SPI being used
...
jndi = new InitialContext(env);
// obtain a connection factory
factory =
    (TopicConnectionFactory)jndi.lookup("TopicConnectionFactory");
// create a connection
connect = factory.createTopicConnection (username, password);


// create a session for publishing, and one for subscriptions
pubSession =



connect.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
subSession =
    connect.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);


myTopic = (Topic)jndi.lookup("My First Topic");


// create the publisher and the subscriber
publisher = pubSession.createPublisher(myTopic);
subscriber = subSession.createSubscriber(myTopic);


// associate the onMessage() handler with this subscriber
subscriber.setMessageListener(this);


// start the flow of incoming messages
connect.start();


TextMessage textMsg = pubSession.createTextMessage();
textMsg.setText("My first JMS message!);


publisher.publish(
    textMsg,
    javax.jms.DeliveryMode.PERSISTENT,          // delivery mode
    javax.jms.Message.DEFAULT_PRIORITY,    // message priority
    1800000); // Time-to-live (30 minutes)

  
 
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.