aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JMS Temporary Topic/Queue" Watch "JMS Temporary Topic/Queue" New topic
Author

JMS Temporary Topic/Queue

Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Hi,
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.
Regards,
M.S.Raman
package com.ibm.mq;
import java.util.*;
import javax.jms.*;
import javax.naming.*;
import com.ibm.mq.jms.*;
public class MQ_JMS_Sample6 {
private java.lang.String CTX_FACTORY = "com.ibm.ejs.ns.jndi.CNInitialContextFactory";
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() {
try
{
jndiContext= getInitialContext();
}catch(NamingException ne)
{
System.out.println("NamingException occured: " + ne);
}
try
{
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);
}
try
{
conn= factory.createTopicConnection();
session= conn.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
topic=session.createTemporaryTopic();
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());
conn.start();
publisher.publish(msgp);
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();
p.put(Context.INITIAL_CONTEXT_FACTORY,CTX_FACTORY);
p.put(Context.PROVIDER_URL,INIT_URL);
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: http://aspose.com/file-tools
 
subject: JMS Temporary Topic/Queue