Package javax.jms

Examples of javax.jms.MessageConsumer


               this.open = false;
               Object[] keys = this.consumerMap.keySet().toArray();
               if (log.isLoggable(Level.FINE))
                  log.fine("close: going to close '" + keys.length + "' consumers too");
               for (int i=0; i < keys.length; i++) {
                  MessageConsumer consumer = (MessageConsumer)this.consumerMap.get(keys[i]);
                  if (consumer != null) consumer.close();
               }
               this.consumerMap.clear();
               this.global.getXmlBlasterAccess().disconnect(new DisconnectQos(this.global));
            }
            finally { // to avoid thread leak
View Full Code Here


    public void testPooledSession() throws Exception {
           
        Session sess =  EasyMock.createMock(Session.class);
        Destination dest = EasyMock.createMock(Destination.class);
        MessageProducer mproducer = EasyMock.createMock(MessageProducer.class);
        MessageConsumer mconsumer = EasyMock.createMock(MessageConsumer.class);
      
        PooledSession ps = new PooledSession(sess, dest, mproducer, mconsumer);
      
        assertTrue(ps.session().equals(sess));
        assertTrue(ps.destination().equals(dest));
        assertTrue(ps.consumer().equals(mconsumer));
        assertTrue(ps.producer().equals(mproducer));   
        
        MessageConsumer mcons = EasyMock.createMock(MessageConsumer.class);
        assertFalse(mconsumer.equals(mcons));
        
        ps.consumer(mcons);
        
        assertTrue(ps.consumer().equals(mcons));
View Full Code Here

      assertEquals(messageCount, count.intValue());


      conn = cf.createConnection();
      session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageConsumer cons = session.createConsumer(queue);

      conn.start();

      // messages will be sent in bulk from server side, on the next HTTP client listner poll

      for(int i = 0; i < messageCount; i++)
      {
         TextMessage t = (TextMessage)cons.receive(2000);
         assertNotNull(t);
         assertEquals("krakatau" + i, t.getText());
      }
     
      conn.close();
View Full Code Here

     
      Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
     
      MessageProducer prod = sess.createProducer(dest);
     
      MessageConsumer cons = sess.createConsumer(dest);
     
      conn.start();
     
      TextMessage tm = sess.createTextMessage("ref test");
     
      prod.send(tm);
     
      tm = (TextMessage)cons.receive(1000);
     
      assertNotNull(tm);
     
      assertEquals("ref test", tm.getText());
     
View Full Code Here

      MessageProducer prod = sess.createProducer(queue);
     
      //Make persistent to make sure message gets serialized
      prod.setDeliveryMode(DeliveryMode.PERSISTENT);
     
      MessageConsumer cons = sess.createConsumer(queue);
     
      TestMessage tm = new TestMessage(123, false);
     
      ObjectMessage om = sess.createObjectMessage();
     
      om.setObject(tm);
     
      conn.start();
     
      prod.send(om);
     
      ObjectMessage om2 = (ObjectMessage)cons.receive(1000);
     
      assertNotNull(om2);
     
      TestMessage tm2 = (TestMessage)om2.getObject();
     
View Full Code Here

      {
         int commitCounter = 0;
         try
         {
            Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
            MessageConsumer consumer = session.createConsumer((Destination)queue);

            int lastCount = messageCount;
            while (true)
            {
               TextMessage message = (TextMessage) consumer.receive(5000);
               if (message == null)
               {
                  break;
               }
               log.debug("read message " + message.getText());

               // alternating commits and rollbacks
               if ( (commitCounter++) % 2 == 0)
               {
                  messagesRead += (messageCount - lastCount);
                  lastCount = messageCount;
                  log.debug("commit");
                  session.commit();
               }
               else
               {
                  lastCount = messageCount;
                  log.debug("rollback");
                  session.rollback();
               }

               messageCount++;

               if (messageCount %7 == 0)
               {
                  session.close();

                  session = conn.createSession(true, Session.SESSION_TRANSACTED);
                  consumer = session.createConsumer((Destination)queue);
               }

               if (messageCount % 50 == 0)
               {
                  log.info("Reader " + index + " read " + messageCount + " messages");
               }
            }

            messagesRead += (messageCount - lastCount);

            session.commit();
            consumer.close();
            session.close();
         }
         catch (Exception e)
         {
            e.printStackTrace();
View Full Code Here

      final int NUM_MESSAGES = 1000;
     
      //send some messages
     
      conn.start();
      MessageConsumer cons = sess.createConsumer(queue);

      produceMessages(sess, prod, 100, cons);
     
      JVMTIInterface jvmti = new JVMTIInterface();
      Map inventory1=jvmti.produceInventory();
View Full Code Here

      for (int i=0;i<100;i++)
      {
         payLoad.add("" + i);
      }
      conn.start();
      MessageConsumer cons1 = sess.createConsumer(queue,"target='1'");
      MessageConsumer cons2 = sess.createConsumer(queue,"target='2'");

      produceMessages(sess, prod, 30, cons1,cons2,payLoad);
     
      JVMTIInterface jvmti = new JVMTIInterface();
      Map inventory1=jvmti.produceInventory();
View Full Code Here

           
      for (int i = 0; i < numRelayers; i++)
      {
         Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         MessageConsumer cons = sess.createConsumer(topic, "name = 'Watt'");
         //MessageConsumer cons = sess.createConsumer(topic);
        
         MessageProducer prod = sess.createProducer(topic);
        
         relayers[i] = new Relayer(prod);
        
         cons.setMessageListener(relayers[i]);
      }
     
      for (int i = 0; i < numConsumers; i++)
      {
         Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         MessageConsumer cons = sess.createConsumer(topic, "name = 'Tim'");
        
         consumers[i] = new Consumer();
        
         cons.setMessageListener(consumers[i]);
      }
     
      conn.start();
     
      Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
View Full Code Here

      ServerManagement.deployQueue("Queue");
     
      conn = cf.createConnection();
      sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      conn.start();
      MessageConsumer cons = sess.createConsumer(queue);
      for (int i = 0; i < 10; i++)
      {
         TextMessage tm = (TextMessage)cons.receive(3000);
         assertNotNull(tm);
         if (tm == null)
         {
            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.