Package javax.jms

Examples of javax.jms.MessageConsumer


    Session producerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    MessageProducer producer = producerSess.createProducer(queue);

    Session consumerSess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    MessageConsumer consumer = consumerSess.createConsumer(queue);
    conn.start();

    final int NUM_MESSAGES = 20;
    final int ACKED_MESSAGES = 11;

    //Send some messages
    for (int i = 0; i < NUM_MESSAGES; i++)
    {
      Message m = producerSess.createMessage();
      producer.send(m);
    }
     
      assertRemainingMessages(NUM_MESSAGES);

    log.trace("Sent messages");

    int count = 0;

    Message m = null;
    for (int i = 0; i < NUM_MESSAGES; i++)
    {
      m = consumer.receive(200);
      if (m == null)
         {
            break;
         }
      if (count == ACKED_MESSAGES -1)
         {
            m.acknowledge();
         }
      count++;
    }
     
      assertRemainingMessages(NUM_MESSAGES - ACKED_MESSAGES);
     
    assertNotNull(m);

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

    assertEquals(count, NUM_MESSAGES);

    consumerSess.recover();

    log.trace("Session recover called");

    count = 0;
    while (true)
    {
      m = consumer.receive(200);
      if (m == null) break;
      count++;
    }

    assertEquals(NUM_MESSAGES - ACKED_MESSAGES, count);           
View Full Code Here


    Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = producerSess.createProducer(queue);

    Session consumerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = consumerSess.createConsumer(queue);
    conn.start();

    final int NUM_MESSAGES = 20;

    //Send some messages
    for (int i = 0; i < NUM_MESSAGES; i++)
    {
      Message m = producerSess.createMessage();
      producer.send(m);
    }
     
      assertRemainingMessages(NUM_MESSAGES);

    log.trace("Sent messages");

    int count = 0;

    Message m = null;
    for (int i = 0; i < NUM_MESSAGES; i++)
    {
         assertRemainingMessages(NUM_MESSAGES - i);
        
      m = consumer.receive(200);
        
         assertRemainingMessages(NUM_MESSAGES - (i + 1));
        
      if (m == null) break;
      count++;
    }
     
      assertRemainingMessages(0);         

    assertNotNull(m);

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

    assertEquals(count, NUM_MESSAGES);

    consumerSess.recover();

    log.trace("Session recover called");

    m = consumer.receive(200);

    log.trace("Message is:" + m);

    assertNull(m);
View Full Code Here

      Session producerSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer producer = producerSess.createProducer(queue);

      Session consumerSess = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
      MessageConsumer consumer = consumerSess.createConsumer(queue);
      conn.start();

      //Send some messages
      for (int i = 0; i < 19; i++)
      {
         Message m = producerSess.createMessage();
         producer.send(m);
      }
     
      assertRemainingMessages(19);

      log.trace("Sent messages");

      Message m = null;
      for (int i = 0; i < 10; i++)
      {
         m = consumer.receive(200);
        
         assertNotNull(m);
         
         if (i == 9)
         {
            assertRemainingMessages(9);
         }
         else
         {
            assertRemainingMessages(19);
         }
      }
     
      for (int i = 0; i < 9; i++)
      {
         m = consumer.receive(200);
        
         assertNotNull(m);
        
         assertRemainingMessages(9);
      }
View Full Code Here

    Session producerSess = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    MessageProducer producer = producerSess.createProducer(queue);

    Session consumerSess = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    MessageConsumer consumer = consumerSess.createConsumer(queue);
    conn.start();

    final int NUM_MESSAGES = 20;

    //Send some messages
    for (int i = 0; i < NUM_MESSAGES; i++)
    {
      Message m = producerSess.createMessage();
      producer.send(m);
    }

      assertRemainingMessages(NUM_MESSAGES);
     
    log.trace("Sent messages");

    int count = 0;

    Message m = null;
    for (int i = 0; i < NUM_MESSAGES; i++)
    {
      m = consumer.receive(200);
      if (m == null) break;
      count++;
    }
     
    assertNotNull(m);
     
      assertRemainingMessages(NUM_MESSAGES);

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

    assertEquals(count, NUM_MESSAGES);

    consumerSess.recover();

    log.trace("Session recover called");

    m = consumer.receive(200);

    log.trace("Message is:" + m);

    assertNull(m);
View Full Code Here

         // make sure we're connecting to node 1

         assertEquals(1, ((JBossConnection)conn).getServerID());

         s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageConsumer c = s.createConsumer(queue1);
         conn.start();

         // we must receive the message

         TextMessage tm = (TextMessage)c.receive(10000);
         assertNotNull(tm);
         assertEquals("blip", tm.getText());

      }
      finally
View Full Code Here

      Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
     
      log.trace("Creating consumer");
     
      MessageConsumer cons = sessReceive.createConsumer(queue);
     
      log.trace("Created consumer");
     
      MessageListenerAutoAck listener = new MessageListenerAutoAck(sessReceive);
     
      log.trace("Setting message listener");
     
      cons.setMessageListener(listener);
     
      log.trace("Set message listener");

      listener.waitForMessages();
     
View Full Code Here

      Session sessReceive = conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
     
      log.trace("Creating consumer");
     
      MessageConsumer cons = sessReceive.createConsumer(queue);
     
      log.trace("Created consumer");
     
      MessageListenerDupsOK listener = new MessageListenerDupsOK(sessReceive);
     
      log.trace("Setting message listener");
     
      cons.setMessageListener(listener);
     
      log.trace("Set message listener");

      listener.waitForMessages();
     
View Full Code Here

     
      assertRemainingMessages(3);
     
      conn.start();
      Session sessReceive = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
      MessageConsumer cons = sessReceive.createConsumer(queue);
      MessageListenerClientAck listener = new MessageListenerClientAck(sessReceive);
      cons.setMessageListener(listener);
     
      listener.waitForMessages();
     
      assertRemainingMessages(0);
     
View Full Code Here

     
      assertRemainingMessages(3);
     
      conn.start();
      Session sessReceive = conn.createSession(true, Session.SESSION_TRANSACTED);
      MessageConsumer cons = sessReceive.createConsumer(queue);
      MessageListenerTransactionalAck listener = new MessageListenerTransactionalAck(sessReceive);
      cons.setMessageListener(listener);
      listener.waitForMessages();
     
      assertRemainingMessages(0);
     
      conn.close();
View Full Code Here

     
      conn = cf.createConnection();
     
      sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
     
      MessageConsumer cons = sess.createConsumer(queue);
     
      conn.start();
     
      //Consume messages and make sure we get the right ones
     
      int count = 0;
     
      while (true)
      {
         TextMessage m = (TextMessage)cons.receive(1000);
        
         assertNotNull(m);
        
         int c = m.getIntProperty("message");
        
         assertEquals(count, c);
        
         count++;
        
         if (count == i)
         {
            //Next message should be null
            Message m2 = cons.receive(1000);
           
            assertNull(m2);
           
            break;
         }        
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.