Examples of TopicConnection


Examples of javax.jms.TopicConnection

     * - Close the session.
     */
    private void prepareDurableSubscriptionWithoutSelector() throws Exception
    {
        // Create a connection
        TopicConnection connection = _connFac.createTopicConnection();
        connection.start();
        connection.setExceptionListener(new ExceptionListener()
        {
            public void onException(JMSException e)
            {
                e.printStackTrace();
            }
        });
        // Create a session on the connection, transacted to confirm delivery
        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
        Topic topic = session.createTopic(TOPIC_NAME);

        // Create and register a durable subscriber without selector and then close it
        TopicSubscriber durSub1 = session.createDurableSubscriber(topic, SUB_NAME);
        durSub1.close();

        // Create a publisher and send a persistent message which matches the subscription
        TopicSession pubSession = connection.createTopicSession(true, Session.SESSION_TRANSACTED);
        TopicPublisher publisher = pubSession.createPublisher(topic);

        publishMessages(pubSession, publisher, topic, DeliveryMode.PERSISTENT, 1*1024, 1, "indifferent");
        pubSession.commit();

        publisher.close();
        pubSession.close();
        connection.close();
    }
View Full Code Here

Examples of javax.jms.TopicConnection

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

Examples of javax.jms.TopicConnection

   // Public --------------------------------------------------------

   /* Topics shouldn't hold on to messages if there are no subscribers */
   public void testPersistentMessagesForTopicDropped() throws Exception
   {
      TopicConnection conn = null;
     
      try
      {
         conn = cf.createTopicConnection();
         TopicSession sess = conn.createTopicSession(true, 0);
         TopicPublisher pub = sess.createPublisher(topic1);
         pub.setDeliveryMode(DeliveryMode.PERSISTENT);
        
         Message m = sess.createTextMessage("testing123");
         pub.publish(m);
         sess.commit();
        
         conn.close();
        
         checkEmpty(topic1);
      }
      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(topic1);
         TopicSubscriber sub = sess.createSubscriber(topic1);
         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();
        
         checkEmpty(topic1);
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }
      }
   }
View Full Code Here

Examples of javax.jms.TopicConnection

    private static TopicInfo connect(final Context context, final String factoryBindingName,
                                     final String queueBindingName, final String userName, final String password,
                                     final boolean suppress) throws Exception {
        try {
            final TopicConnectionFactory factory = (TopicConnectionFactory) lookup(context, factoryBindingName);
            TopicConnection conn;
            if (userName != null) {
                conn = factory.createTopicConnection(userName, password);
            } else {
                conn = factory.createTopicConnection();
            }
            final TopicSession sess = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            final Topic topic = (Topic) lookup(context, queueBindingName);
            final TopicPublisher publisher = sess.createPublisher(topic);
            conn.start();
            return new TopicInfo(conn, sess, publisher);
        } catch (final NamingException ex) {
            LOGGER.warn("Unable to locate connection factory " + factoryBindingName, ex);
            if (!suppress) {
                throw ex;
View Full Code Here

Examples of javax.jms.TopicConnection

                            final String password) {
        try {
            final Context ctx = new InitialContext();
            TopicConnectionFactory topicConnectionFactory;
            topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName);
            final TopicConnection topicConnection = topicConnectionFactory.createTopicConnection(username, password);
            topicConnection.start();
            final TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            final Topic topic = (Topic) ctx.lookup(topicBindingName);
            final TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
            topicSubscriber.setMessageListener(this);
        } catch (final JMSException e) {
            logger.error("Could not read JMS message.", e);
View Full Code Here

Examples of javax.jms.TopicConnection

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

Examples of javax.jms.TopicConnection

      conn.close();
   }

   public void testCreateQueueOnATopicSession() throws Exception
   {
      TopicConnection c = (TopicConnection)getConnectionFactory().createConnection();
      TopicSession s = c.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

      try
      {
         s.createQueue("TestQueue");
         ProxyAssertSupport.fail("should throw IllegalStateException");
      }
      catch (javax.jms.IllegalStateException e)
      {
         // OK
      }
      c.close();
   }
View Full Code Here

Examples of javax.jms.TopicConnection

   }

   /** See TCK test: topicconntests.connNotStartedTopicTest */
   public void testCannotReceiveMessageOnStoppedConnection() throws Exception
   {
      TopicConnection conn1 = ((TopicConnectionFactory)JMSTestCase.topicCf).createTopicConnection();
      TopicConnection conn2 = ((TopicConnectionFactory)JMSTestCase.topicCf).createTopicConnection();

      TopicSession sess1 = conn1.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
      TopicSession sess2 = conn2.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

      TopicSubscriber sub1 = sess1.createSubscriber(HornetQServerTestCase.topic1);
      TopicSubscriber sub2 = sess2.createSubscriber(HornetQServerTestCase.topic1);

      conn1.start();

      Connection conn3 = JMSTestCase.cf.createConnection();

      Session sess3 = conn3.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer prod = sess3.createProducer(HornetQServerTestCase.topic1);
      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);
      }

      for (int i = 0; i < NUM_MESSAGES; i++)
      {
         TextMessage tm = (TextMessage)sub1.receive(500);
         ProxyAssertSupport.assertNotNull(tm);
         ProxyAssertSupport.assertEquals("hello", tm.getText());
      }

      Message m = sub2.receive(200);

      ProxyAssertSupport.assertNull(m);

      conn2.start();

      for (int i = 0; i < NUM_MESSAGES; i++)
      {
         TextMessage tm = (TextMessage)sub2.receive(500);
         ProxyAssertSupport.assertNotNull(tm);
         ProxyAssertSupport.assertEquals("hello", tm.getText());
      }

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

      conn1.close();

      conn2.close();

      conn3.close();

   }
View Full Code Here

Examples of javax.jms.TopicConnection

   /**
    *
    */
   public void testTopic() throws Exception
   {
      TopicConnection conn = getTopicConnectionFactory().createTopicConnection();

      try
      {
         TopicSession s = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
         TopicPublisher publisher = s.createPublisher(HornetQServerTestCase.topic1);
         TopicSubscriber sub = s.createSubscriber(HornetQServerTestCase.topic1);
         conn.start();

         // Create 3 object messages with different bodies

         TestObject to1 = new TestObject();
         to1.text = "hello1";

         TestObject to2 = new TestObject();
         to1.text = "hello2";

         TestObject to3 = new TestObject();
         to1.text = "hello3";

         ObjectMessage om1 = s.createObjectMessage();
         om1.setObject(to1);

         ObjectMessage om2 = s.createObjectMessage();
         om2.setObject(to2);

         ObjectMessage om3 = s.createObjectMessage();
         om3.setObject(to3);

         // send to topic
         publisher.send(om1);

         publisher.send(om2);

         publisher.send(om3);

         ObjectMessage rm1 = (ObjectMessage)sub.receive(HornetQServerTestCase.MAX_TIMEOUT);

         ObjectMessage rm2 = (ObjectMessage)sub.receive(HornetQServerTestCase.MAX_TIMEOUT);

         ObjectMessage rm3 = (ObjectMessage)sub.receive(HornetQServerTestCase.MAX_TIMEOUT);

         ProxyAssertSupport.assertNotNull(rm1);

         TestObject ro1 = (TestObject)rm1.getObject();

         ProxyAssertSupport.assertEquals(to1.text, ro1.text);
         ProxyAssertSupport.assertNotNull(rm1);

         TestObject ro2 = (TestObject)rm2.getObject();

         ProxyAssertSupport.assertEquals(to2.text, ro2.text);

         ProxyAssertSupport.assertNotNull(rm2);

         TestObject ro3 = (TestObject)rm3.getObject();

         ProxyAssertSupport.assertEquals(to3.text, ro3.text);
      }
      finally
      {
         if (conn != null)
         {
            conn.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.