Package javax.jms

Examples of javax.jms.TextMessage


          conn = cf.createConnection();
          conn.start();

          Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
          MessageProducer prod = sess.createProducer(queue);
          TextMessage tm1 = sess.createTextMessage("hello1");
          TextMessage tm2 = sess.createTextMessage("hello2");
          TextMessage tm3 = sess.createTextMessage("hello3");
          prod.send(tm1);
          prod.send(tm2);
          prod.send(tm3);
          sess.commit();

          MessageConsumer cons1 = sess.createConsumer(queue);

          TextMessage rm1 = (TextMessage)cons1.receive(1500);
          assertNotNull(rm1);
          assertEquals("hello1", rm1.getText());

          cons1.close();

          MessageConsumer cons2 = sess.createConsumer(queue);

          sess.commit();

          TextMessage rm2 = (TextMessage)cons2.receive(1500);
          assertNotNull(rm2);
          assertEquals("hello2", rm2.getText());

          TextMessage rm3 = (TextMessage)cons2.receive(1500);
          assertNotNull(rm3);
          assertEquals("hello3", rm3.getText());

          TextMessage rm4 = (TextMessage)cons2.receive(1500);
          assertNull(rm4);


       }
       finally
View Full Code Here


          conn = cf.createConnection();
          conn.start();

          Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
          MessageProducer prod = sess.createProducer(queue);
          TextMessage tm1 = sess.createTextMessage("hello1");
          TextMessage tm2 = sess.createTextMessage("hello2");
          TextMessage tm3 = sess.createTextMessage("hello3");
          prod.send(tm1);
          prod.send(tm2);
          prod.send(tm3);
          sess.commit();

          MessageConsumer cons1 = sess.createConsumer(queue);

          TextMessage rm1 = (TextMessage)cons1.receive(1500);
          assertNotNull(rm1);
          assertEquals("hello1", rm1.getText());

          cons1.close();

          sess.commit();

          MessageConsumer cons2 = sess.createConsumer(queue);

          TextMessage rm2 = (TextMessage)cons2.receive(1500);
          assertNotNull(rm2);
          assertEquals("hello2", rm2.getText());

          TextMessage rm3 = (TextMessage)cons2.receive(1500);
          assertNotNull(rm3);
          assertEquals("hello3", rm3.getText());

          TextMessage rm4 = (TextMessage)cons2.receive(1500);
          assertNull(rm4);


       }
       finally
View Full Code Here

          conn = cf.createConnection();
          conn.start();

          Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
          MessageProducer prod = sess.createProducer(queue);
          TextMessage tm1 = sess.createTextMessage("hello1");
          log.trace(tm1.getJMSMessageID());
          TextMessage tm2 = sess.createTextMessage("hello2");
          TextMessage tm3 = sess.createTextMessage("hello3");
          prod.send(tm1);
          prod.send(tm2);
          prod.send(tm3);
          sess.commit();

          MessageConsumer cons1 = sess.createConsumer(queue);

          TextMessage rm1 = (TextMessage)cons1.receive(1500);
          assertNotNull(rm1);
          assertEquals("hello1", rm1.getText());
          log.trace(rm1.getJMSMessageID());

          log.trace("rolling back");
          //rollback should cause redelivery of messages not acked
          sess.rollback();
          log.trace("rolled back");

          TextMessage rm2 = (TextMessage)cons1.receive(1500);
          assertEquals("hello1", rm2.getText());
          log.trace(rm1.getJMSMessageID());

          TextMessage rm3 = (TextMessage)cons1.receive(1500);
          assertEquals("hello2", rm3.getText());

          TextMessage rm4 = (TextMessage)cons1.receive(1500);
          assertEquals("hello3", rm4.getText());

          //This last step is important - there shouldn't be any more messages to receive
          TextMessage rm5 = (TextMessage)cons1.receive(1500);
          assertNull(rm5);

       }
       finally
       {
View Full Code Here

          conn = cf.createConnection();
          conn.start();

          Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
          MessageProducer prod = sess.createProducer(queue);
          TextMessage tm1 = sess.createTextMessage("hello1");
          TextMessage tm2 = sess.createTextMessage("hello2");
          TextMessage tm3 = sess.createTextMessage("hello3");
          prod.send(tm1);
          prod.send(tm2);
          prod.send(tm3);
          sess.commit();

          MessageConsumer cons1 = sess.createConsumer(queue);

          TextMessage rm1 = (TextMessage)cons1.receive(1500);
          assertNotNull(rm1);
          assertEquals("hello1", rm1.getText());

          cons1.close();

          //Cancelling is asynch so can take some time
          Thread.sleep(500);
         
          //rollback should cause redelivery of messages

          //in this case redelivery occurs to a different receiver

          sess.rollback();

          MessageConsumer cons2 = sess.createConsumer(queue);

          TextMessage rm2 = (TextMessage)cons2.receive(1500);
          assertNotNull(rm2);
          assertEquals("hello1", rm2.getText());

          TextMessage rm3 = (TextMessage)cons2.receive(1500);
          assertNotNull(rm3);
          assertEquals("hello2", rm3.getText());

          TextMessage rm4 = (TextMessage)cons2.receive(1500);
          assertNotNull(rm4);
          assertEquals("hello3", rm4.getText());

          //This last step is important - there shouldn't be any more messages to receive
          TextMessage rm5 = (TextMessage)cons2.receive(1500);
          assertNull(rm5);


       }
       finally
View Full Code Here

          conn = cf.createConnection();
          conn.start();

          Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
          MessageProducer prod = sess.createProducer(queue);
          TextMessage tm1 = sess.createTextMessage("hello1");
          TextMessage tm2 = sess.createTextMessage("hello2");
          TextMessage tm3 = sess.createTextMessage("hello3");
          prod.send(tm1);
          prod.send(tm2);
          prod.send(tm3);

          MessageConsumer cons1 = sess.createConsumer(queue);

          TextMessage rm1 = (TextMessage)cons1.receive(1500);
          assertNotNull(rm1);
          assertEquals("hello1", rm1.getText());

          //redeliver
          sess.recover();

          TextMessage rm2 = (TextMessage)cons1.receive(1500);
          assertNotNull(rm2);
          assertEquals("hello1", rm2.getText());

          TextMessage rm3 = (TextMessage)cons1.receive(1500);
          assertNotNull(rm3);
          assertEquals("hello2", rm3.getText());

          TextMessage rm4 = (TextMessage)cons1.receive(1500);
          assertNotNull(rm4);
          assertEquals("hello3", rm4.getText());


          //This last step is important - there shouldn't be any more messages to receive
          TextMessage rm5 = (TextMessage)cons1.receive(1500);
          assertNull(rm5);
       }
       finally
       {
          if (conn != null)
View Full Code Here

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

          MessageProducer prod = sess.createProducer(queue);
         
          TextMessage tm1 = sess.createTextMessage("1");
         
          TextMessage tm2 = sess.createTextMessage("2");
         
          TextMessage tm3 = sess.createTextMessage("3");
         
          prod.send(tm1);
          prod.send(tm2);
          prod.send(tm3);

          log.trace("Creating consumer");
          MessageConsumer cons1 = sess.createConsumer(queue);

          log.trace("Waiting for message");
         
          TextMessage r1 = (TextMessage)cons1.receive();
         
          assertEquals(tm1.getText(), r1.getText());

          log.trace("Got first message");

          cons1.close();

          log.trace("Closed consumer");

          MessageConsumer cons2 = sess.createConsumer(queue);

          log.trace("Waiting for second message");
          TextMessage r2 = (TextMessage)cons2.receive();
         
          assertEquals(tm2.getText(), r2.getText());

          log.trace("got second message");

          TextMessage r3 = (TextMessage)cons2.receive();
         
          assertEquals(tm3.getText(), r3.getText());

          r1.acknowledge();
          r2.acknowledge();
          r3.acknowledge();
       }
       finally
       {
          if (conn != null)
          {
View Full Code Here

         Session sessReceive = connReceive.createSession(true, Session.SESSION_TRANSACTED);

         MessageConsumer cons = sessReceive.createConsumer(queue2);

         TextMessage m2 = (TextMessage)cons.receive(1500);

         assertNotNull(m2);

         assertEquals("hello", m2.getText());

         sessReceive.commit();

         cons.close();


         connReceive = cf.createConnection();

         connReceive.start();

         sessReceive = connReceive.createSession(true, Session.SESSION_TRANSACTED);

         cons = sessReceive.createConsumer(queue2);

         TextMessage m3 = (TextMessage)cons.receive(1500);

         assertNull(m3);


         log.trace("Done test");
View Full Code Here

         {
            try
            {
               for (int i = 0; i < NUM_MESSAGES; i++)
               {
                  TextMessage m = (TextMessage)cons.receive(5000);
                  if (m == null)
                  {
                     log.error("Didn't receive all the messages");
                     failed = true;
                     break;
                  }
                  log.trace("received message");
                  if (!m.getText().equals("testing"))
                  {
                     failed = true;
                  }
               }
View Full Code Here

   public void testTwoConsumersNonTransacted() throws Exception
   {

      consumerSession.close();

      TextMessage tm = producerSession.createTextMessage();
      tm.setText("One");
      queueProducer.send(tm);
      tm.setText("Two");
      queueProducer.send(tm);

      // recreate the connection and receive the first message
      consumerConnection = cf.createConnection();
      consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      queueConsumer = consumerSession.createConsumer(queue);
      consumerConnection.start();

      TextMessage m = (TextMessage)queueConsumer.receive(1500);
      assertEquals("One", m.getText());

      consumerConnection.close();

      // recreate the connection and receive the second message
      consumerConnection = cf.createConnection();
      consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      queueConsumer = consumerSession.createConsumer(queue);
      consumerConnection.start();

      m = (TextMessage)queueConsumer.receive(1500);
      assertEquals("Two", m.getText());

      consumerConnection.close();
   }
View Full Code Here

   public void testTwoConsumersTransacted() throws Exception
   {

      consumerSession.close();

      TextMessage tm = producerSession.createTextMessage();
      tm.setText("One");
      queueProducer.send(tm);
      tm.setText("Two");
      queueProducer.send(tm);

      // recreate the connection and receive the first message
      consumerConnection = cf.createConnection();
      consumerSession = consumerConnection.createSession(true, -1);
      queueConsumer = consumerSession.createConsumer(queue);
      consumerConnection.start();

      TextMessage m = (TextMessage)queueConsumer.receive(1500);
      assertEquals("One", m.getText());

      consumerSession.commit();
      consumerConnection.close();

      // recreate the connection and receive the second message
      consumerConnection = cf.createConnection();
      consumerSession = consumerConnection.createSession(true, -1);
      queueConsumer = consumerSession.createConsumer(queue);
      consumerConnection.start();

      m = (TextMessage)queueConsumer.receive(1500);
      assertEquals("Two", m.getText());

      consumerConnection.close();
   }
View Full Code Here

TOP

Related Classes of javax.jms.TextMessage

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.