Package javax.jms

Examples of javax.jms.TopicSubscriber


         if (HornetQRASession.trace)
         {
            HornetQRASession.log.trace("createDurableSubscriber " + session + " topic=" + topic + " name=" + name);
         }

         TopicSubscriber result = session.createDurableSubscriber(topic, name);
         result = new HornetQRATopicSubscriber(result, this);

         if (HornetQRASession.trace)
         {
            HornetQRASession.log.trace("createdDurableSubscriber " + session + " HornetQTopicSubscriber=" + result);
View Full Code Here


                                       messageSelector +
                                       " noLocal=" +
                                       noLocal);
         }

         TopicSubscriber result = session.createDurableSubscriber(topic, name, messageSelector, noLocal);
         result = new HornetQRATopicSubscriber(result, this);

         if (HornetQRASession.trace)
         {
            HornetQRASession.log.trace("createdDurableSubscriber " + session + " HornetQTopicSubscriber=" + result);
View Full Code Here

    PooledSession createPubSubSession(boolean producer,
                                              boolean consumer,
                                              Destination destination) throws JMSException {
        TopicSession session = ((TopicConnection)theConnection).createTopicSession(false,
                                                                                   Session.AUTO_ACKNOWLEDGE);
        TopicSubscriber sub = null;
        if (consumer) {
            String messageSelector = runtimePolicy.getMessageSelector();
            String durableName = runtimePolicy.getDurableSubscriberName();
            if (durableName != null) {
                sub = session.createDurableSubscriber((Topic)destination,
View Full Code Here

       
        QueueSession qSession = ((AMQConnection)_connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueReceiver receiver = qSession.createReceiver(queue);
       
        TopicSession tSession = ((AMQConnection)_connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        TopicSubscriber sub = tSession.createSubscriber(topic);
       
        Session ssn = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer prod1 = ssn.createProducer(ssn.createQueue("ADDR:my-queue"));
        prod1.send(ssn.createTextMessage("test1"));
       
        MessageProducer prod2 = ssn.createProducer(ssn.createTopic("ADDR:amq.topic/test"));
        prod2.send(ssn.createTextMessage("test2"));
       
        Message msg1 = receiver.receive();
        assertNotNull(msg1);
        assertEquals("test1",((TextMessage)msg1).getText());
       
        Message msg2 = sub.receive();
        assertNotNull(msg2);
        assertEquals("test2",((TextMessage)msg2).getText())
    }
View Full Code Here

            TopicConnectionFactory factory = getConnectionFactory();
            Topic topic = (Topic) getInitialContext().lookup(_topicName);
            //create and register a durable subscriber then close it
            TopicConnection durConnection = factory.createTopicConnection("guest", "guest");
            TopicSession durSession = durConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            TopicSubscriber durSub1 = durSession.createDurableSubscriber(topic, "dursub");
            durConnection.start();
            durSub1.close();
            durSession.close();
            durConnection.stop();

            //create a publisher and send a persistant message followed by a non persistant message
            TopicConnection pubConnection = factory.createTopicConnection("guest", "guest");
            TopicSession pubSession = pubConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            TopicPublisher publisher = pubSession.createPublisher(topic);
            Message message = pubSession.createMessage();
            message.setIntProperty("count", 1);
            publisher.publish(message, javax.jms.DeliveryMode.PERSISTENT, javax.jms.Message.DEFAULT_PRIORITY,
                              javax.jms.Message.DEFAULT_TIME_TO_LIVE);
            message.setIntProperty("count", 2);
            publisher.publish(message, javax.jms.DeliveryMode.NON_PERSISTENT, javax.jms.Message.DEFAULT_PRIORITY,
                              javax.jms.Message.DEFAULT_TIME_TO_LIVE);
            publisher.close();
            pubSession.close();
            //now stop the server
            try
            {
                restartBroker();
            }
            catch (Exception e)
            {
                _logger.error("problems restarting broker: " + e);
                throw e;
            }
            //now recreate the durable subscriber and check the received messages
            factory = getConnectionFactory();
            topic = (Topic) getInitialContext().lookup(_topicName);
            TopicConnection durConnection2 = factory.createTopicConnection("guest", "guest");
            TopicSession durSession2 = durConnection2.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            TopicSubscriber durSub2 = durSession2.createDurableSubscriber(topic, "dursub");
            durConnection2.start();
            Message m1 = durSub2.receive(1000);
            if (m1 == null)
            {
                assertTrue("testDurSubRestoredAfterNonPersistentMessageSent test failed. no message was returned",
                           false);
            }
View Full Code Here

            TopicConnectionFactory factory = getConnectionFactory();
            Topic topic = (Topic) getInitialContext().lookup(_topicName);
            //create and register a durable subscriber with a message selector and then close it
            TopicConnection durConnection = factory.createTopicConnection("guest", "guest");
            TopicSession durSession = durConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            TopicSubscriber durSub1 = durSession.createDurableSubscriber(topic, "dursub", "testprop='true'", false);
            durConnection.start();
            durSub1.close();
            durSession.close();
            durConnection.stop();
            //now stop the server
            try
            {
                restartBroker();
            }
            catch (Exception e)
            {
                _logger.error("problems restarting broker: " + e);
                throw e;
            }
            topic = (Topic) getInitialContext().lookup(_topicName);
            factory = getConnectionFactory();
            TopicConnection pubConnection = factory.createTopicConnection("guest", "guest");
            TopicSession pubSession = pubConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            TopicPublisher publisher = pubSession.createPublisher(topic);
            for (int i = 0; i < 5; i++)
            {
                Message message = pubSession.createMessage();
                message.setStringProperty("testprop", "true");
                publisher.publish(message);
                message = pubSession.createMessage();
                message.setStringProperty("testprop", "false");
                publisher.publish(message);
            }
            publisher.close();
            pubSession.close();

            //now recreate the durable subscriber and check the received messages
            TopicConnection durConnection2 = factory.createTopicConnection("guest", "guest");
            TopicSession durSession2 = durConnection2.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            TopicSubscriber durSub2 = durSession2.createDurableSubscriber(topic, "dursub", "testprop='true'", false);
            durConnection2.start();
            for (int i = 0; i < 5; i++)
            {
                Message message = durSub2.receive(1000);
                if (message == null)
                {
                    assertTrue("testDurSubRestoresMessageSelector test failed. no message was returned", false);
                }
                else
View Full Code Here

        Topic topic = (Topic) getInitialContext().lookup(_topicName);
       
        //create and register a durable subscriber then unsubscribe it
        TopicConnection durConnection = factory.createTopicConnection("guest", "guest");
        TopicSession durSession = durConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        TopicSubscriber durSub1 = durSession.createDurableSubscriber(topic, SUB_NAME);
        durConnection.start();
        durSub1.close();
        durSession.unsubscribe(SUB_NAME);
        durSession.close();
        durConnection.close();

        //create and register a durable subscriber with a message selector and then close it
        TopicConnection durConnection2 = factory.createTopicConnection("guest", "guest");
        TopicSession durSession2 = durConnection2.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        TopicSubscriber durSub2 = durSession2.createDurableSubscriber(topic, SUB_NAME, "testprop='true'", false);
        durConnection2.start();
        durSub2.close();
        durSession2.close();
        durConnection2.close();
       
        //now restart the server
        try
        {
            restartBroker();
        }
        catch (Exception e)
        {
            _logger.error("problems restarting broker: " + e);
            throw e;
        }
       
        //send messages matching and not matching the selector
        TopicConnection pubConnection = factory.createTopicConnection("guest", "guest");
        TopicSession pubSession = pubConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        TopicPublisher publisher = pubSession.createPublisher(topic);
        for (int i = 0; i < 5; i++)
        {
            Message message = pubSession.createMessage();
            message.setStringProperty("testprop", "true");
            publisher.publish(message);
            message = pubSession.createMessage();
            message.setStringProperty("testprop", "false");
            publisher.publish(message);
        }
        publisher.close();
        pubSession.close();

        //now recreate the durable subscriber with selector to check there are no exceptions generated
        //and then verify the messages are received correctly
        TopicConnection durConnection3 = (TopicConnection) factory.createConnection("guest", "guest");
        TopicSession durSession3 = (TopicSession) durConnection3.createSession(false, Session.AUTO_ACKNOWLEDGE);
        TopicSubscriber durSub3 = durSession3.createDurableSubscriber(topic, SUB_NAME, "testprop='true'", false);
        durConnection3.start();
       
        for (int i = 0; i < 5; i++)
        {
            Message message = durSub3.receive(2000);
            if (message == null)
            {
                fail("testDurSubChangedToHaveSelectorThenRestart test failed. Expected message " + i + " was not returned");
            }
            else
            {
                assertTrue("testDurSubChangedToHaveSelectorThenRestart test failed. Got message not matching selector",
                           message.getStringProperty("testprop").equals("true"));
            }
        }

        durSub3.close();
        durSession3.unsubscribe(SUB_NAME);
        durSession3.close();
        durConnection3.close();
    }
View Full Code Here

        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        AMQTopic topic = new AMQTopic((AMQConnection) conn, "testResubscribeWithChangedSelectorAndRestart");
        MessageProducer producer = session.createProducer(topic);
       
        // Create durable subscriber that matches A
        TopicSubscriber subA = session.createDurableSubscriber(topic,
                "testResubscribeWithChangedSelector",
                "Match = True", false);

        // Send 1 matching message and 1 non-matching message
        TextMessage msg = session.createTextMessage("testResubscribeWithChangedSelectorAndRestart1");
        msg.setBooleanProperty("Match", true);
        producer.send(msg);
        msg = session.createTextMessage("testResubscribeWithChangedSelectorAndRestart2");
        msg.setBooleanProperty("Match", false);
        producer.send(msg);

        Message rMsg = subA.receive(1000);
        assertNotNull(rMsg);
        assertEquals("Content was wrong",
                     "testResubscribeWithChangedSelectorAndRestart1",
                     ((TextMessage) rMsg).getText());

        // Queue has no messages left
        AMQQueue subQueueTmp = new AMQQueue("amq.topic", "clientid" + ":" + "testResubscribeWithChangedSelectorAndRestart");
        assertEquals("Msg count should be 0", 0, ((AMQSession<?, ?>) session).getQueueDepth(subQueueTmp));
       
        rMsg = subA.receive(1000);
        assertNull(rMsg);
       
        // Send another 1 matching message and 1 non-matching message
        msg = session.createTextMessage("testResubscribeWithChangedSelectorAndRestart1");
        msg.setBooleanProperty("Match", true);
        producer.send(msg);
        msg = session.createTextMessage("testResubscribeWithChangedSelectorAndRestart2");
        msg.setBooleanProperty("Match", false);
        producer.send(msg);
       
        // Disconnect subscriber without receiving the message to
        //leave it on the underlying queue
        subA.close();
       
        // Reconnect with new selector that matches B
        TopicSubscriber subB = session.createDurableSubscriber(topic,
                "testResubscribeWithChangedSelectorAndRestart",
                "Match = false", false);
       
        //verify no messages are now present on the queue as changing selector should have issued
        //an unsubscribe and thus deleted the previous durable backing queue for the subscription.
        //check the dur sub's underlying queue now has msg count 0
        AMQQueue subQueue = new AMQQueue("amq.topic", "clientid" + ":" + "testResubscribeWithChangedSelectorAndRestart");
        assertEquals("Msg count should be 0", 0, ((AMQSession<?, ?>) session).getQueueDepth(subQueue));
       
        // Check that new messages are received properly
        msg = session.createTextMessage("testResubscribeWithChangedSelectorAndRestart1");
        msg.setBooleanProperty("Match", true);
        producer.send(msg);
        msg = session.createTextMessage("testResubscribeWithChangedSelectorAndRestart2");
        msg.setBooleanProperty("Match", false);
        producer.send(msg);
       
        rMsg = subB.receive(1000);
        assertNotNull(rMsg);
        assertEquals("Content was wrong",
                     "testResubscribeWithChangedSelectorAndRestart2",
                     ((TextMessage) rMsg).getText());
       
        rMsg = subB.receive(1000);
        assertNull(rMsg);

        //check the dur sub's underlying queue now has msg count 0
        subQueue = new AMQQueue("amq.topic", "clientid" + ":" + "testResubscribeWithChangedSelectorAndRestart");
        assertEquals("Msg count should be 0", 0, ((AMQSession<?, ?>) session).getQueueDepth(subQueue));

        //now restart the server
        try
        {
            restartBroker();
        }
        catch (Exception e)
        {
            _logger.error("problems restarting broker: " + e);
            throw e;
        }
       
        // Reconnect to broker
        Connection connection = getConnectionFactory().createConnection("guest", "guest");
        connection.start();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        topic = new AMQTopic((AMQConnection) connection, "testResubscribeWithChangedSelectorAndRestart");
        producer = session.createProducer(topic);

        //verify no messages now present on the queue after we restart the broker
        //check the dur sub's underlying queue now has msg count 0
        subQueue = new AMQQueue("amq.topic", "clientid" + ":" + "testResubscribeWithChangedSelectorAndRestart");
        assertEquals("Msg count should be 0", 0, ((AMQSession<?, ?>) session).getQueueDepth(subQueue));

        // Reconnect with new selector that matches B
        TopicSubscriber subC = session.createDurableSubscriber(topic,
                "testResubscribeWithChangedSelectorAndRestart",
                "Match = False", false);
       
        // Check that new messages are still sent and recieved properly
        msg = session.createTextMessage("testResubscribeWithChangedSelectorAndRestart1");
        msg.setBooleanProperty("Match", true);
        producer.send(msg);
        msg = session.createTextMessage("testResubscribeWithChangedSelectorAndRestart2");
        msg.setBooleanProperty("Match", false);
        producer.send(msg);

        //check the dur sub's underlying queue now has msg count 1
        subQueue = new AMQQueue("amq.topic", "clientid" + ":" + "testResubscribeWithChangedSelectorAndRestart");
        assertEquals("Msg count should be 1", 1, ((AMQSession<?, ?>) session).getQueueDepth(subQueue));
       
        rMsg = subC.receive(1000);
        assertNotNull(rMsg);
        assertEquals("Content was wrong",
                     "testResubscribeWithChangedSelectorAndRestart2",
                     ((TextMessage) rMsg).getText());
       
        rMsg = subC.receive(1000);
        assertNull(rMsg);
       
        session.unsubscribe("testResubscribeWithChangedSelectorAndRestart");
       
        subC.close();
        session.close();
        connection.close();
    }
View Full Code Here

            Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
            conn.start();

            // create kipper
            Topic kipper = sess.createTopic("kipper");
            TopicSubscriber subscriber = sess.createDurableSubscriber(kipper, "kipper");

            subscriber.close();
            sess.unsubscribe("kipper");

            //Do something to show connection is active.
            sess.rollback();
            conn.close();
View Full Code Here

            Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
            conn.start();

            // create kipper
            Topic kipper = sess.createTopic("kipper");
            TopicSubscriber subscriber = sess.createDurableSubscriber(kipper, "kipper");

            subscriber.close();
            sess.unsubscribe("kipper");

            //Do something to show connection is active.
            sess.rollback();
            conn.close();
View Full Code Here

TOP

Related Classes of javax.jms.TopicSubscriber

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.