[jboss-user] [JBoss Messaging] - Re: Expiaration date does not work ?

ivan.rododendro do-not-reply at jboss.com
Fri Dec 5 06:18:47 EST 2008


This is a stand-alone test case: 

public class JmsTestClient {
  | 
  |     private static final String SUBSCRIBER_NAME = "test-sub";
  | 
  |     private static final String TEXT_MESSAGE = "Text message in SRMChangedEvent";
  | 
  |     private static final String TOPIC_NAME = "/topic/TestTopic";
  | 
  |     private TopicSubscriber durableSubscriber;
  | 
  |     private TopicSession subscriberSession;
  | 
  |     private TopicConnection connection;
  | 
  |     public JmsTestClient() throws NamingException {
  |         System.getProperties().put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
  |         System.getProperties().put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
  |         System.getProperties().put("java.naming.provider.url", "localhost");
  |     }
  | 
  |     public static void main(String[] args) {
  | 
  |         try {
  |             JmsTestClient testClient = new JmsTestClient();
  | 
  |             testClient.createDurableSubscriber();
  | 
  |             testClient.postMessage();
  | 
  |             testClient.consumeMessage();
  | 
  |             testClient.unsuscribe();
  | 
  |         } catch (Exception e) {
  |             e.printStackTrace();
  |         }
  |     }
  | 
  |     private void unsuscribe() throws Exception {
  |         durableSubscriber.close();
  |         try {
  |             subscriberSession.unsubscribe(SUBSCRIBER_NAME);
  |         } catch (Exception e) {
  |             // TODO Auto-generated catch block
  |             e.printStackTrace();
  |         }
  |         subscriberSession.close();
  |     }
  | 
  |     private void postMessage() throws Exception {
  |         InitialContext initialContext = new InitialContext();
  |         JBossConnectionFactory topicConnectionFactory = (JBossConnectionFactory) initialContext
  |                                         .lookup("ConnectionFactory");
  |         Topic destination = (Topic) initialContext.lookup(TOPIC_NAME);
  |         TopicConnection connection = topicConnectionFactory.createTopicConnection();
  | 
  |         TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
  |         TopicPublisher producer = session.createPublisher(destination);
  |         Message message = session.createTextMessage(TEXT_MESSAGE);
  | 
  |         producer.setDeliveryMode(DeliveryMode.PERSISTENT);
  |         producer.setTimeToLive(43200);
  |         producer.send(message);
  | 
  |         producer.close();
  |         session.close();
  |         connection.stop();
  |         connection.close();
  |     }
  | 
  |     private void consumeMessage() throws Exception {
  | 
  |         System.out.println("Waiting for message...");
  |         TextMessage message = (TextMessage) durableSubscriber.receive();
  |         System.out.println("Received");
  | 
  |         if (message.getText().equals(TEXT_MESSAGE))
  |             System.out.println("message text is ok");
  |     }
  | 
  |     private void createDurableSubscriber() throws Exception {
  |         final InitialContext initialContext = new InitialContext();
  |         final JBossConnectionFactory topicConnectionFactory = (JBossConnectionFactory) initialContext
  |                                         .lookup("ConnectionFactory");
  |         final Topic destination = (Topic) initialContext.lookup(TOPIC_NAME);
  |         connection = topicConnectionFactory.createTopicConnection();
  |         connection.setClientID("test");
  | 
  |         subscriberSession = connection.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
  |         durableSubscriber = subscriberSession.createDurableSubscriber(destination, SUBSCRIBER_NAME, null, false);
  | 
  |         connection.start();
  |     }
  | }

As the message is never acked when we try to unsuscribe durable subscriber JBM throws an exception but - client code - the session is closed  anyway. 

The durable subscriber is removed anyway, the message is no more in the topic (checked on JMX console) but it still be on the database, with DELIVERY_COUNT = 1.

So unacked messages will never be removed from persistence? 

Thank you very much, and sorry to have posted the spec, I did it only to have a common "starting point"

Ivan.




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

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



More information about the jboss-user mailing list