Package javax.jms

Examples of javax.jms.MessageConsumer


      ServerManagement.deployQueue("Queue");
     
      conn = cf.createConnection();
      Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      conn.start();
      MessageConsumer cons = sessReceive.createConsumer(queue);
    
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("j", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("i", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("h", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("g", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("f", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("e", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("d", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("c", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("b", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("a", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(500);
         assertNull(t);
      }
     
    
      conn.close();
View Full Code Here


      ServerManagement.deployQueue("Queue");
     
      conn = cf.createConnection();
      Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      conn.start();
      MessageConsumer cons = sessReceive.createConsumer(queue);
    
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("j", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("h", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("i", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("f", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("g", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("d", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("e", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("a", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("b", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receive(1000);
         assertNotNull(t);
         assertEquals("c", t.getText());
      }
      {
         TextMessage t = (TextMessage)cons.receiveNoWait();
         assertNull(t);
      }
     
      conn.close();
   }
View Full Code Here

      Connection conn = cf.createConnection();
      conn.setClientID("five");

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

      MessageConsumer ds = s.createDurableSubscriber(thisTopic, "sub", null, false);

      MessageProducer p = s.createProducer(thisTopic);
      p.setDeliveryMode(DeliveryMode.PERSISTENT);
      TextMessage tm = s.createTextMessage("thebody");
      p.send(tm);
      log.debug("message sent");

      conn.close();

      log.debug("stopping the server");
      ServerManagement.stopServerPeer();

      try
      {
         initialContext.lookup("/topic/YetAnotherTopic");
         fail("this should throw exception");
      }
      catch(NameNotFoundException e)
      {
         // OK
      }

      log.debug("starting the server");
      ServerManagement.startServerPeer();
      log.debug("server started");

      // Messaging server restart implies new ConnectionFactory lookup
      cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");

      ServerManagement.deployTopic("YetAnotherTopic");
      log.debug("topic deployed");

      thisTopic = (Topic)initialContext.lookup("/topic/YetAnotherTopic");

      conn = cf.createConnection();
      conn.setClientID("five");

      s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      conn.start();

      ds = s.createDurableSubscriber(thisTopic, "sub", null, false);

      TextMessage rm = (TextMessage)ds.receive(3000);
      assertNotNull(rm);
      assertEquals("thebody", rm.getText());


      conn.close();
View Full Code Here

      Connection conn = cf.createConnection();
      conn.setClientID("Sausages");
     
      Session sessConsume = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
     
      MessageConsumer sub1 = sessConsume.createDurableSubscriber(topic, "sub1", null, false);
      MessageConsumer sub2 = sessConsume.createDurableSubscriber(topic, "sub2", null, false);
      MessageConsumer sub3 = sessConsume.createDurableSubscriber(topic, "sub3", null, false);
     
     
      Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer prod = sessSend.createProducer(topic);
      prod.setDeliveryMode(DeliveryMode.PERSISTENT);
     
      for (int i = 0; i < 10; i++)
      {
         TextMessage tm = sessSend.createTextMessage("message" + i);
         prod.send(tm);
      }
     
      conn.close();
     
      ServerManagement.stopServerPeer();

      ServerManagement.startServerPeer();

      // Messaging server restart implies new ConnectionFactory lookup
      cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");

      ServerManagement.deployTopic("Topic");
     
      conn = cf.createConnection();
      conn.setClientID("Sausages");
     
      sessConsume = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      conn.start();
     
      sub1 = sessConsume.createDurableSubscriber(topic, "sub1", null, false);
      sub2 = sessConsume.createDurableSubscriber(topic, "sub2", null, false);
      sub3 = sessConsume.createDurableSubscriber(topic, "sub3", null, false);
                 
      for (int i = 0; i < 10; i++)
      {
         TextMessage tm1 = (TextMessage)sub1.receive(3000);
         assertNotNull(tm1);
         if (tm1 == null)
         {
            break;
         }
         assertEquals("message" + i, tm1.getText());
        
         TextMessage tm2 = (TextMessage)sub2.receive(3000);
         assertNotNull(tm2);
         if (tm2 == null)
         {
            break;
         }
         assertEquals("message" + i, tm2.getText());
        
         TextMessage tm3 = (TextMessage)sub3.receive(3000);
         assertNotNull(tm3);
         if (tm3 == null)
         {
            break;
         }
View Full Code Here

         // read the message from the queue

         Connection conn = cf.createConnection();
         conn.start();
         Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageConsumer cons = sess.createConsumer(queue);
         TextMessage tm = (TextMessage)cons.receive(5000);

         assertNotNull(tm);
         assertEquals(MESSAGE_TEXT, tm.getText());

         // the client VM should exit by itself. If it doesn't, that means we have a problem
View Full Code Here

      count++;
    }
   
    assertEquals(numMessages, count);
   
    MessageConsumer mc = session.createConsumer(queue);
   
    connection.start();
   
    for (int i = 0; i < numMessages; i++)
    {
      Message m = mc.receive();
         assertNotNull(m);
    }
     
      // Need to pause here since delivery is done on a different thread. Message might not be
      // removed from in memory state by this point.
View Full Code Here


      Connection conn2 = cf.createConnection();
      conn2.start();
      Session sessReceive = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);     
      MessageConsumer cons = sessReceive.createConsumer(queue1);
     
 
      Runner[] runners = new Runner[] {
      new Sender("prod1", sess1, prod1, NUM_NON_PERSISTENT_MESSAGES),
      new Sender("prod2", sess2, prod2, NUM_PERSISTENT_MESSAGES),
View Full Code Here

      Session rsess18 = rxaSess2.getSession();
      Session rsess19 = rxaSess3.getSession();
      Session rsess20 = rxaSess4.getSession();

                     
      MessageConsumer cons1 = rsess1.createConsumer(topic1);
      MessageConsumer cons2 = rsess2.createDurableSubscriber(topic1, "sub1");
      MessageConsumer cons3 = rsess3.createConsumer(topic1);
      MessageConsumer cons4 = rsess4.createDurableSubscriber(topic1, "sub2");
      MessageConsumer cons5 = rsess5.createConsumer(topic1);
      MessageConsumer cons6 = rsess6.createDurableSubscriber(topic1, "sub3");
      MessageConsumer cons7 = rsess7.createConsumer(topic1);
      MessageConsumer cons8 = rsess8.createDurableSubscriber(topic1, "sub4");
      MessageConsumer cons9 = rsess9.createConsumer(topic1);
      MessageConsumer cons10 = rsess10.createDurableSubscriber(topic1, "sub5");
      MessageConsumer cons11 = rsess11.createConsumer(topic1);
      MessageConsumer cons12 = rsess12.createDurableSubscriber(topic1, "sub6");
      MessageConsumer cons13 = rsess13.createConsumer(topic1);
      MessageConsumer cons14 = rsess14.createDurableSubscriber(topic1, "sub7");
      MessageConsumer cons15 = rsess15.createConsumer(topic1);
      MessageConsumer cons16 = rsess16.createDurableSubscriber(topic1, "sub8");
      MessageConsumer cons17 = rsess17.createConsumer(topic1);
      MessageConsumer cons18 = rsess18.createDurableSubscriber(topic1, "sub9");
      MessageConsumer cons19 = rsess19.createConsumer(topic1);
      MessageConsumer cons20 = rsess20.createDurableSubscriber(topic1, "sub10");

     
      //To make sure paging occurs first send some messages before receiving
 
      Runner[] runners = new Runner[] {
View Full Code Here

      log.debug("message sent");

      s.close();

      s = conn.createSession(true, Session.SESSION_TRANSACTED);
      MessageConsumer c = s.createConsumer(queue);
      conn.start();
      Message m = c.receive();

      assertEquals("one", ((TextMessage)m).getText());
      assertFalse(m.getJMSRedelivered());
      assertEquals(1, m.getIntProperty("JMSXDeliveryCount"));

      s.rollback();

      // get the message again
      m = c.receive();
      assertTrue(m.getJMSRedelivered());
      assertEquals(2, m.getIntProperty("JMSXDeliveryCount"));

      conn.close();
     
View Full Code Here

      {
         conn = cf.createConnection();
        
         Session sessSend = conn.createSession(true, Session.SESSION_TRANSACTED);
         Session sess1 = conn.createSession(true, Session.SESSION_TRANSACTED);        
         MessageConsumer consumer1 = sess1.createConsumer(topic);
        
         MessageProducer producer = sessSend.createProducer(topic);
         Message mSent = sessSend.createTextMessage("igloo");
         producer.send(mSent);     
         sessSend.commit();
              
         conn.start();
             
         TextMessage mRec1 = (TextMessage)consumer1.receive(2000);
         assertEquals("igloo", mRec1.getText());
         assertFalse(mRec1.getJMSRedelivered());
        
         sess1.rollback(); //causes redelivery for session

         mRec1 = (TextMessage)consumer1.receive(2000);
         assertEquals("igloo", mRec1.getText());
         assertTrue(mRec1.getJMSRedelivered());
                          
         sess1.commit();
      }
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.