Examples of TopicConnection


Examples of javax.jms.TopicConnection

         // create a factory (normally retreived by naming service)
         TopicConnectionFactory factory = new XBConnectionFactory(null, this.cmdLine, false);
         // should be retreived via jndi
         Topic topic = new XBDestination("jms-test", null, false);
     
         TopicConnection connection = factory.createTopicConnection();
         connection.start();
         TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
         TopicSubscriber subscriber = session.createSubscriber(topic);
         subscriber.setMessageListener(this);
     
         TopicPublisher publisher = session.createPublisher(topic);
     
         TextMessage msg = session.createTextMessage();
         msg.setText("this is a simple jms test message");
         publisher.publish(msg);
     
         Thread.sleep(3000L);
         connection.stop();
      }
      catch (Exception ex) {
         ex.printStackTrace();
      }
   }
View Full Code Here

Examples of javax.jms.TopicConnection

  
  
   /* Topics shouldn't hold on to messages if there are no subscribers */
   public void testPersistentMessagesForTopicDropped() throws Exception
   {
      TopicConnection conn = null;
     
      try
      {
         conn = cf.createTopicConnection();
         System.out.println("******   ClientID = " + conn.getClientID());
         TopicSession sess = conn.createTopicSession(true, 0);
         TopicPublisher pub = sess.createPublisher(topic);
         pub.setDeliveryMode(DeliveryMode.PERSISTENT);
        
         Message m = sess.createTextMessage("testing123");
         pub.publish(m);
         sess.commit();
        
         conn.close();
         conn = cf.createTopicConnection();
         conn.start();
        
         TopicSession newsess = conn.createTopicSession(true, 0);
         TopicSubscriber newcons = newsess.createSubscriber(topic);
        
         Message m2 = (Message)newcons.receive(200);
         assertNull(m2);
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }
      }
   }
View Full Code Here

Examples of javax.jms.TopicConnection

   }
  
   /* Topics shouldn't hold on to messages when the non-durable subscribers close */
   public void testPersistentMessagesForTopicDropped2() throws Exception
   {
      TopicConnection conn = null;
     
      try
      {
         conn = cf.createTopicConnection();
         conn.start();
         TopicSession sess = conn.createTopicSession(true, 0);
         TopicPublisher pub = sess.createPublisher(topic);
         TopicSubscriber sub = sess.createSubscriber(topic);
         pub.setDeliveryMode(DeliveryMode.PERSISTENT);
        
         Message m = sess.createTextMessage("testing123");
         pub.publish(m);
         sess.commit();
        
         //receive but rollback
         TextMessage m2 = (TextMessage)sub.receive(3000);
               
         assertNotNull(m2);
         assertEquals("testing123", m2.getText());
        
         sess.rollback();
        
         conn.close();
         conn = cf.createTopicConnection();
         conn.start();
        
         TopicSession newsess = conn.createTopicSession(true, 0);
         TopicSubscriber newcons = newsess.createSubscriber(topic);
        
         Message m3 = (Message)newcons.receive(200);
         assertNull(m3);
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }
      }
   }
View Full Code Here

Examples of javax.jms.TopicConnection

      }
   }
  
   public void testRollbackRecover() throws Exception
   {
      TopicConnection conn = null;
     
      try
      {
         conn = cf.createTopicConnection();
         TopicSession sess = conn.createTopicSession(true, 0);
         TopicPublisher pub = sess.createPublisher(topic);
         TopicSubscriber cons = sess.createSubscriber(topic);
         conn.start();
        
         Message m = sess.createTextMessage("testing123");
         pub.publish(m);
         sess.commit();
        
         TextMessage m2 = (TextMessage)cons.receive(3000);
         assertNotNull(m2);
         assertEquals("testing123", m2.getText());
        
         sess.rollback();
        
         m2 = (TextMessage)cons.receive(3000);
         assertNotNull(m2);
         assertEquals("testing123", m2.getText());
        
         conn.close();
        
         conn = cf.createTopicConnection();
         conn.start();
        
         //test 2
        
         TopicSession newsess = conn.createTopicSession(true, 0);
         TopicPublisher newpub = newsess.createPublisher(topic);
         TopicSubscriber newcons = newsess.createSubscriber(topic);
        
         Message m3 = newsess.createTextMessage("testing456");
         newpub.publish(m3);
         newsess.commit();
        
         TextMessage m4 = (TextMessage)newcons.receive(3000);
         assertNotNull(m4);
         assertEquals("testing456", m4.getText());
        
         newsess.commit();
        
         newpub.publish(m3);
         newsess.commit();
        
         TextMessage m5 = (TextMessage)newcons.receive(3000);
         assertNotNull(m5);
         assertEquals("testing456", m5.getText());
        
         newsess.rollback();
        
         TextMessage m6 = (TextMessage)newcons.receive(3000);
         assertNotNull(m6);
         assertEquals("testing456", m6.getText());
        
         newsess.commit();
        
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }
      }
   }
View Full Code Here

Examples of javax.jms.TopicConnection

    * Test introduced as a result of a TCK failure.
    */
   public void testNonDurableSubscriberOnNullTopic() throws Exception
   {
      TopicConnectionFactory cf = (TopicConnectionFactory)ic.lookup("ConnectionFactory");
      TopicConnection conn = cf.createTopicConnection();

      TopicSession ts = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

      try
      {
         ts.createSubscriber(null);
         fail("this should fail");
View Full Code Here

Examples of javax.jms.TopicConnection

    * Test introduced as a result of a TCK failure.
    */
   public void testNonDurableSubscriberInvalidUnsubscribe() throws Exception
   {
      TopicConnectionFactory cf = (TopicConnectionFactory)ic.lookup("ConnectionFactory");
      TopicConnection conn = cf.createTopicConnection();
      conn.setClientID("sofiavergara");

      TopicSession ts = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

      try
      {
         ts.unsubscribe("invalid-subscription-name");
         fail("this should fail");
View Full Code Here

Examples of javax.jms.TopicConnection

    */
   public void testTopicConnectionFactory() throws Exception
   {
      TopicConnectionFactory qcf =
         (TopicConnectionFactory)initialContext.lookup("/ConnectionFactory");
      TopicConnection tc = qcf.createTopicConnection();
      tc.close();
   }
View Full Code Here

Examples of javax.jms.TopicConnection

    */
   public void testQueueConnection2() throws Exception
   {
      TopicConnectionFactory tcf = (TopicConnectionFactory)cf;

      TopicConnection tc = tcf.createTopicConnection();

      tc.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

      tc.close();

   }
View Full Code Here

Examples of javax.jms.TopicConnection

   }
  
   /** See TCK test: topicconntests.connNotStartedTopicTest */
   public void testCannotReceiveMessageOnStoppedConnection() throws Exception
   {
      TopicConnection conn1 = ((TopicConnectionFactory)cf).createTopicConnection();
      TopicConnection conn2 = ((TopicConnectionFactory)cf).createTopicConnection();
     
      TopicSession sess1 = conn1.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
      TopicSession sess2 = conn2.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
     
      TopicSubscriber sub1 = sess1.createSubscriber(topic);
      TopicSubscriber sub2 = sess2.createSubscriber(topic);
     
      conn1.start();
     
      Connection conn3 = cf.createConnection();
     
      Session sess3 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer prod = sess3.createProducer(topic);
      prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
     
      final int NUM_MESSAGES = 10;
     
      for (int i = 0; i < NUM_MESSAGES; i++)
      {
         TextMessage tm = sess3.createTextMessage("hello");
         prod.send(tm);
      }

      log.debug("all messages sent");

      int count = 0;
      while (true)
      {
         TextMessage tm = (TextMessage)sub1.receive(2000);
         if (tm == null)
         {
            break;
         }
         assertEquals("hello", tm.getText());
         count++;
      }
      assertEquals(NUM_MESSAGES, count);

      log.debug("all messages received by sub1");

      Message m = sub2.receive(200);
     
      assertNull(m);
     
      conn2.start();
     
      count = 0;
      while (true)
      {
         TextMessage tm = (TextMessage)sub2.receive(200);
         if (tm == null)
         {
            break;
         }
         assertEquals("hello", tm.getText());
         count++;
      }
      assertEquals(NUM_MESSAGES, count);

      log.debug("all messages received by sub2");
     
      conn1.close();
     
      conn2.close();
     
      conn3.close();
     
   }
View Full Code Here

Examples of javax.jms.TopicConnection

   }

   public void testInvalidSelectorOnSubscription() throws Exception
   {
      TopicConnectionFactory cf = (TopicConnectionFactory)ic.lookup("/ConnectionFactory");
      TopicConnection c =  cf.createTopicConnection();
      c.setClientID("something");
      try
      {
         TopicSession s = c.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
         Topic topic = (Topic)ic.lookup("/topic/Topic");

         try
         {
            s.createSubscriber(topic, "=TEST 'test'", false);
            fail("this should fail");
         }
         catch(InvalidSelectorException e)
         {
            // OK
         }
      }
      finally
      {
         c.close();
      }
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.