This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JMS Temporary Topic/Queue  RSS feed

Malli Raman
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();}
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!