Package javax.jms

Examples of javax.jms.MessageConsumer


         // Create a durable subscriber on one connection and close it
         conn1 = cf.createConnection();
         conn1.setClientID(CLIENT_ID1);
         sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageConsumer durable = sess1.createDurableSubscriber(topic, "mySubscription");
         conn1.close();


         // Send some messages on another connection and close it
         conn2 = cf.createConnection();
         conn2.setClientID(CLIENT_ID1);
         Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageProducer prod2 = sess2.createProducer(topic);
         prod2.setDeliveryMode(DeliveryMode.PERSISTENT);
         final int NUM_MESSAGES = 10;
         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            TextMessage tm = sess2.createTextMessage("hello");
            prod2.send(topic, tm);
         }
         conn2.close();

         // Receive the messages on another connection
         conn3 = cf.createConnection();
         conn3.setClientID(CLIENT_ID1);
         conn3.start();
         sess3 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
         durable = sess3.createDurableSubscriber(topic, "mySubscription");
         int count = 0;
         while (true)
         {
            TextMessage tm = (TextMessage)durable.receive(1000);
            if (tm == null)
            {
               break;
            }
            assertEquals("hello", tm.getText());
            count++;
         }
         assertEquals(NUM_MESSAGES, count);
         conn3.close();

         // Try and receive them again
         conn4 = cf.createConnection();
         conn4.setClientID(CLIENT_ID1);
         conn4.start();
         sess4 = conn4.createSession(false, Session.AUTO_ACKNOWLEDGE);
         durable = sess4.createDurableSubscriber(topic, "mySubscription");

         TextMessage tm = (TextMessage)durable.receive(1000);
         assertNull(tm);
         conn4.close();

         // Send some more messages and unsubscribe
         conn5 = cf.createConnection();
         conn5.setClientID(CLIENT_ID1);
         conn5.start();
         Session sess5 = conn5.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageProducer prod5 = sess5.createProducer(topic);
         prod5.setDeliveryMode(DeliveryMode.PERSISTENT);

         log.debug("sending.1 " + NUM_MESSAGES + " messages");
         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            TextMessage tm2 = sess5.createTextMessage("hello");
            prod5.send(topic, tm2);
         }

         log.debug("unsubscribing mySubscription");

         durable.close();
         sess5.unsubscribe("mySubscription");
         log.debug("unsubscribing done");
         conn5.close();

         // Resubscribe with the same name
         conn6 = cf.createConnection();
         conn6.setClientID(CLIENT_ID1);
         conn6.start();
         sess6 = conn6.createSession(false, Session.AUTO_ACKNOWLEDGE);
         durable = sess6.createDurableSubscriber(topic, "mySubscription");

         TextMessage tm3 = (TextMessage)durable.receive(1000);
         assertNull(tm3);

         durable.close();
      }
      finally
      {
         if (conn1 != null)
         {
View Full Code Here


         Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageProducer prod = sess1.createProducer(topic);
         prod.setDeliveryMode(DeliveryMode.PERSISTENT);

         log.debug("creating durable subscription");
         MessageConsumer durable = sess1.createDurableSubscriber(topic, "mySubscription");
         log.debug("durable subscription created");

         conn1.start();

         final int NUM_MESSAGES = 2;


         log.debug("sending messages ...");

         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            TextMessage tm = sess1.createTextMessage("hello");
            prod.send(topic, tm);
         }

         final int NUM_TO_RECEIVE = NUM_MESSAGES - 1;

         log.debug("receiving messages ...");

         for (int i = 0; i < NUM_TO_RECEIVE; i++)
         {
            TextMessage tm = (TextMessage)durable.receive(3000);
            assertNotNull(tm);
         }

         // Close the connection
         conn1.close();
         conn1 = null;

         conn2 = cf.createConnection();

         conn2.setClientID(CLIENT_ID1);

         Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);

         // Re-subscribe to the subscription

         log.trace("resubscribing");

         MessageConsumer durable2 = sess2.createDurableSubscriber(topic, "mySubscription");

         conn2.start();

         int count = 0;
         while (true)
         {
            TextMessage tm = (TextMessage)durable2.receive(1500);
            if (tm == null)
            {
               break;
            }
            count++;
         }

         log.trace("Received " + count  + " messages");

         assertEquals(NUM_MESSAGES - NUM_TO_RECEIVE, count);

         durable2.close();

         sess2.unsubscribe("mySubscription");
      }
      finally
      {
View Full Code Here

         Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageProducer prod = sess1.createProducer(topic);
         prod.setDeliveryMode(DeliveryMode.PERSISTENT);

         MessageConsumer durable = sess1.createDurableSubscriber(topic, "mySubscription");

         conn1.start();

         final int NUM_MESSAGES = 50;


         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            TextMessage tm = sess1.createTextMessage("hello");
            prod.send(topic, tm);
         }

         final int NUM_TO_RECEIVE1 = 22;

         for (int i = 0; i < NUM_TO_RECEIVE1; i++)
         {
            TextMessage tm = (TextMessage)durable.receive(1500);
            if (tm == null)
            {
               fail();
            }
         }

         //Close the connection
         conn1.close();
         conn1 = null;

         conn2 = cf.createConnection();

         conn2.setClientID(CLIENT_ID2);

         Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);

         //Re-subscribe to the subscription
         MessageConsumer durable2 = sess2.createDurableSubscriber(topic, "mySubscription");

         conn2.start();

         int count = 0;
         while (true)
         {
            TextMessage tm = (TextMessage)durable2.receive(1500);
            if (tm == null)
            {
               break;
            }
            count++;
         }

         assertEquals(0, count);

         durable2.close();

         sess2.unsubscribe("mySubscription");
      }
      finally
      {
View Full Code Here

      prod.send(tm);

      consumerConnection.start();

      Session sess1 = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
      MessageConsumer cons1 = sess1.createConsumer(queue);
      TextMessage tm2 = (TextMessage)cons1.receive(3000);
     
      assertNotNull(tm2);
      assertEquals("testRedeliveredDifferentSessions", tm2.getText());

      //don't acknowledge it
      sess1.close();

      Session sess2 = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
      MessageConsumer cons2 = sess2.createConsumer(queue);
      TextMessage tm3 = (TextMessage)cons2.receive(3000);
     
      assertNotNull(tm3);
      assertEquals("testRedeliveredDifferentSessions", tm3.getText());
     
      assertTrue(tm3.getJMSRedelivered());
View Full Code Here

      conn.start();

      Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);

      MessageConsumer cons = sess.createConsumer(queue2);

      RedelMessageListenerImpl listener = new RedelMessageListenerImpl(false);
      listener.sess = sess;

      cons.setMessageListener(listener);

      MessageProducer prod = sess.createProducer(queue2);
      prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      TextMessage m1 = sess.createTextMessage("a");
      TextMessage m2 = sess.createTextMessage("b");
View Full Code Here

      Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);

      MessageConsumer cons = sess.createConsumer(queue2);

      RedelMessageListenerImpl listener = new RedelMessageListenerImpl(true);
      listener.sess = sess;

      cons.setMessageListener(listener);

      MessageProducer prod = sessSend.createProducer(queue2);
      TextMessage m1 = sess.createTextMessage("a");
      TextMessage m2 = sess.createTextMessage("b");
      TextMessage m3 = sess.createTextMessage("c");
View Full Code Here

      Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      MessageConsumer cons = sess.createConsumer(queue2);

      ExceptionRedelMessageListenerImpl listener = new ExceptionRedelMessageListenerImpl(sess);

      cons.setMessageListener(listener);

      MessageProducer prod = sessSend.createProducer(queue2);
      TextMessage m1 = sess.createTextMessage("a");
      TextMessage m2 = sess.createTextMessage("b");
      TextMessage m3 = sess.createTextMessage("c");
View Full Code Here

      Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Session sess = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);

      MessageConsumer cons = sess.createConsumer(queue2);

      ExceptionRedelMessageListenerImpl listener = new ExceptionRedelMessageListenerImpl(sess);

      cons.setMessageListener(listener);

      MessageProducer prod = sessSend.createProducer(queue2);
      TextMessage m1 = sess.createTextMessage("a");
      TextMessage m2 = sess.createTextMessage("b");
      TextMessage m3 = sess.createTextMessage("c");
View Full Code Here

      Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);

      MessageConsumer cons = sess.createConsumer(queue2);

      ExceptionRedelMessageListenerImpl listener = new ExceptionRedelMessageListenerImpl(sess);

      cons.setMessageListener(listener);

      MessageProducer prod = sessSend.createProducer(queue2);
      TextMessage m1 = sess.createTextMessage("a");
      TextMessage m2 = sess.createTextMessage("b");
      TextMessage m3 = sess.createTextMessage("c");
View Full Code Here

      Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);

      MessageConsumer cons = sess.createConsumer(queue2);

      ExceptionRedelMessageListenerImpl listener = new ExceptionRedelMessageListenerImpl(sess);

      cons.setMessageListener(listener);

      MessageProducer prod = sessSend.createProducer(queue2);
      TextMessage m1 = sess.createTextMessage("a");
      TextMessage m2 = sess.createTextMessage("b");
      TextMessage m3 = sess.createTextMessage("c");
View Full Code Here

TOP

Related Classes of javax.jms.MessageConsumer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.