[jboss-user] [JBoss Messaging] - Re: Jboss Messaging How To
sudheer_java26
do-not-reply at jboss.com
Tue Apr 22 09:34:53 EDT 2008
Please tell me how to create durable topic in jboss messaging ?
when i changed method
before
|
| TopicSubscriber recv = session.createSubscriber(topic);
|
| after
|
| TopicSubscriber recv = session.createDurableSubscriber(topic,"My Durable Exp....");
even after stop sending my sender.java program my lister is able to listen the messages ? i gusss this is unlike JBOSSMQ.
Listener.java code
============
| import java.util.Properties;
|
| import javax.jms.JMSException;
| import javax.jms.Message;
| import javax.jms.MessageListener;
| import javax.jms.TextMessage;
| import javax.jms.Topic;
| import javax.jms.TopicConnection;
| import javax.jms.TopicConnectionFactory;
| import javax.jms.TopicSession;
| import javax.jms.TopicSubscriber;
| import javax.naming.Context;
| import javax.naming.InitialContext;
| import javax.naming.NamingException;
|
| public class Listener implements MessageListener {
|
| String url_;
| String name_;
| TopicConnection conn = null;
| TopicSession session = null;
| Topic topic = null;
|
| public Listener(String url, String name) {
| super();
|
| url_ = url;
| name_ = name;
|
| try {
| this.initializeListener();
| } catch (Exception e) {
| System.out.println("Error creating listener: " + e);
| e.printStackTrace();
| }
|
| }
|
| public void onMessage(Message msg) {
|
| TextMessage tm = (TextMessage) msg;
|
| try {
| System.out.println("Incoming message: " + tm.getText());
| } catch (Exception e) {
| e.printStackTrace();
| }
| }
|
| private void initializeListener() throws JMSException, NamingException {
|
| Properties props = new Properties();
| props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
| props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
| props.setProperty("java.naming.provider.url", url_);
|
| Context context = new InitialContext(props);
| System.out.println("performing lookup...");
|
| Object tmp = context.lookup("MyExampleConnectionFactory");
| System.out.println("lookup completed, making topic");
|
| TopicConnectionFactory tcf = (TopicConnectionFactory) tmp;
| conn = tcf.createTopicConnection();
| topic = (Topic) context.lookup(name_);
|
| session = conn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
| conn.start();
|
| //TopicSubscriber recv = session.createSubscriber(topic);
|
| TopicSubscriber recv = session.createDurableSubscriber(topic,"My Durable Exp....");
| recv.setMessageListener(this);
| }
|
|
| public void disconnect() throws JMSException {
| if(conn != null) {
| conn.stop();
| }
|
| if(session != null) {
| session.close();
| }
|
| if(conn != null) {
| conn.close();
| }
| }
|
| public static void main(String args[]) {
|
| System.out.println("Starting JMS Example Listener");
| System.out.println("Program will be active for 1 minute.");
|
| //change these values to your situtation:
| Listener listener = new Listener("localhost:1099", "topic/myTopic3");
|
|
| //leave it open for 2 minutes:
| try {
| Thread.sleep(5000);
| } catch(Exception e) {
| System.out.println("Error sleeping: " + e);
| e.printStackTrace();
| }
|
| try {
| listener.disconnect();
| } catch(Exception e) {
| System.out.println("Error terminating listener JMS objects: " + e);
| e.printStackTrace();
| }
|
| System.out.println("Done listening");
| }
|
| }
I guess to create "durable topic" we need to create user, role for durable.
i referred the docs but i did't found prper information .
please help me
-----------
-Sudheer
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4145831#4145831
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4145831
More information about the jboss-user
mailing list