[jboss-user] [JBoss Messaging] - Re: All messages are not persisted in Database.

sajankn do-not-reply at jboss.com
Mon Aug 4 15:16:44 EDT 2008


I'm not able to attach the files, hence putting the code as such.

Publisher Code:

  | import javax.jms.Connection;
  | import javax.jms.ConnectionFactory;
  | import javax.jms.DeliveryMode;
  | import javax.jms.JMSException;
  | import javax.jms.MessageProducer;
  | import javax.jms.Session;
  | import javax.jms.TextMessage;
  | import javax.jms.Topic;
  | import javax.jms.TopicConnection;
  | import javax.jms.TopicConnectionFactory;
  | import javax.jms.TopicPublisher;
  | import javax.jms.TopicSession;
  | 
  | import javax.naming.InitialContext;
  | import javax.naming.NamingException;
  | 
  | public class MyPublisher 
  | {
  | 	public static void main(String[] args) 
  | 	{		
  | 		try
  | 		{
  | 			String destinationName = "/topic/testTopic";
  | 			InitialContext ic = new InitialContext();
  | 			TopicConnectionFactory cf = (TopicConnectionFactory)ic.lookup("/ClusteredConnectionFactory");
  | 			Topic topic = (Topic)ic.lookup(destinationName);
  | 			TopicConnection connection = cf.createTopicConnection();
  | 			TopicSession session = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
  | 			TopicPublisher publisher = session.createPublisher(topic);
  | 			connection.start();
  | 			String msgStr = "Hello World";
  | 			for (int i = 0; i< 1000; i++)
  | 			{
  | 				TextMessage tm = session.createTextMessage(msgStr + i);
  | 				publisher.publish(tm);
  | 			}			
  | 		}
  | 		catch(JMSException jmse)
  | 		{
  | 			jmse.printStackTrace();
  | 		}
  | 		catch(NamingException ne)
  | 		{
  | 			ne.printStackTrace();
  | 		}
  | 		catch(Exception e)
  | 		{
  | 			e.printStackTrace();
  | 		}
  | 	}
  | }
  | 

Run.sh for Publisher:

  | java -Dcom.sun.management.jmxremote.port=12346 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.naming.factory.initial=org.jboss.naming.NamingContextFactory -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces -Djava.naming.provider.url=jnp://MY_SERVER:PORT_NO -DespStress-Xms256m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=360000 -Dsun.rmi.dgc.server.gcInterval=360000 -Xloggc:gc.log -classpath ${CLIENT_CLASSPATH} MyPublisher
  | 

Subscriber Code:

  | import javax.jms.JMSException;
  | 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.InitialContext;
  | import javax.naming.NamingException;
  | 
  | public class MySubscriber 
  | {
  | 	public static void main(String[] args) 
  | 	{		
  | 		try
  | 		{
  | 			String destinationName = "/topic/testTopic";
  | 			InitialContext ic = new InitialContext();
  | 			TopicConnectionFactory cf = (TopicConnectionFactory)ic.lookup("/ClusteredConnectionFactory");
  | 			Topic topic = (Topic)ic.lookup(destinationName);
  | 			TopicConnection connection = cf.createTopicConnection("admin", "admin");
  | 			connection.setClientID("MyClientID");
  | 			TopicSession session = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
  | 			TopicSubscriber subscriber = session.createDurableSubscriber(topic, "MyName");
  | 			connection.start();
  | 			while (true)
  | 			{
  | 				TextMessage message = (TextMessage)subscriber.receive(5000);
  | 				if (message != null)
  | 				{
  | 					String msgStr = message.getText();
  | 					System.out.println(msgStr);
  | 				}				
  | 				message = null;
  | 			}
  | 		}
  | 		catch(JMSException jmse)
  | 		{
  | 			jmse.printStackTrace();
  | 		}
  | 		catch(NamingException ne)
  | 		{
  | 			ne.printStackTrace();
  | 		}
  | 		catch(Exception e)
  | 		{
  | 			e.printStackTrace();
  | 		}
  | 	}
  | }
  | 

Run.sh for Subscriber:

  | java -Dcom.sun.management.jmxremote.port=12346 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.naming.factory.initial=org.jboss.naming.NamingContextFactory -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces -Djava.naming.provider.url=jnp://MY_SERVER:PORT_NO -DespStress-Xms256m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=360000 -Dsun.rmi.dgc.server.gcInterval=360000 -Xloggc:gc.log -classpath ${CLIENT_CLASSPATH} MySubscriber
  | 

Currently I'm doing a work-around for the messages not persisted in DB. For every new topic, I publish a few test messages and subscribe them. After the first time, the messages are always persisted, hence I dont lose any message. 

Also the Subscriber sometime do not consume messages even though they are present in the database and require restart (some time more than once) of the subscriber.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4168567#4168567

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4168567



More information about the jboss-user mailing list