This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes JMS Temporary Topic/Queue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JMS Temporary Topic/Queue" Watch "JMS Temporary Topic/Queue" New topic

JMS Temporary Topic/Queue

Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
I am using the following program to send/receive Topic Message using Temporary Topic. But after the receive() method the program waits for the message. How to solve the program.
import java.util.*;
import javax.jms.*;
import javax.naming.*;
public class MQ_JMS_Sample6 {
private java.lang.String CTX_FACTORY = "";
private java.lang.String INIT_URL = "iiop://localhost:900/";
private javax.jms.TopicConnectionFactory factory;
private javax.jms.TopicConnection conn;
private javax.jms.TopicSession session;
private javax.jms.Topic topic;
private javax.naming.Context jndiContext;
private javax.jms.TopicSubscriber subscriber;
private javax.jms.TopicPublisher publisher;
public MQ_JMS_Sample6() {
jndiContext= getInitialContext();
}catch(NamingException ne)
System.out.println("NamingException occured: " + ne);
System.out.println("Inside the try loop");
factory= (TopicConnectionFactory)jndiContext.lookup("jms/TopicConnection1");
System.out.println("The factory: " + factory);
//topic= (Topic) jndiContext.lookup("jms/AllComputers");
//System.out.println("The Topic:" + topic);
catch(Exception je)
System.out.println("JMSException occured: " + je);
conn= factory.createTopicConnection();
session= conn.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
System.out.println("The Topic:" + topic);
//subscriber= session.createDurableSubscriber(topic,"Raman");
publisher= session.createPublisher(topic);
System.out.println("publisher: " + publisher);
TextMessage msgp= session.createTextMessage();
msgp.setText("Hi Raman this msg is sent thro temp topic");
System.out.println("THE MESSAGE IS : " + msgp.getText());
System.out.println("The message is published");
subscriber= session.createSubscriber(topic);
System.out.println("The Subscriber is : " + subscriber);
Following statements are not printed
TextMessage msg= (TextMessage)subscriber.receive();

System.out.println("Msg be received:" + msg.getText());

System.out.println("End of the program");

catch(Exception e1)
System.out.println("Exception occured: " + e1);

* Insert the method's description here.
* Creation date: (3/20/01 12:09:27 PM)
* @return javax.naming.InitialContext
public javax.naming.Context getInitialContext() throws javax.naming.NamingException{
Properties p= new Properties();
return new InitialContext(p);

* Insert the method's description here.
* Creation date: (3/20/01 12:03:07 PM)
* @param args java.lang.String[]
public static void main(String[] args) {new MQ_JMS_Sample6();}
I agree. Here's the link:
subject: JMS Temporary Topic/Queue
It's not a secret anymore!