Examples of StubConnection


Examples of org.apache.activemq.broker.StubConnection

    }

    protected StubConnection createFailoverConnection(TransportListener listener) throws Exception {
        URI failoverURI = new URI("failover://" + connector.getServer().getConnectURI() + "," + remoteConnector.getServer().getConnectURI() + "");
        Transport transport = TransportFactory.connect(failoverURI);
        StubConnection connection = new StubConnection(transport, listener);
        connections.add(connection);
        return connection;
    }
View Full Code Here

Examples of org.apache.activemq.broker.StubConnection

    public void testLargeQueuePersistentMessagesNotLostOnRestart() throws Exception {

        ActiveMQDestination destination = new ActiveMQQueue("TEST");

        // Setup the producer and send the message.
        StubConnection connection = createConnection();
        ConnectionInfo connectionInfo = createConnectionInfo();
        SessionInfo sessionInfo = createSessionInfo(connectionInfo);
        ProducerInfo producerInfo = createProducerInfo(sessionInfo);
        connection.send(connectionInfo);
        connection.send(sessionInfo);
        connection.send(producerInfo);
       
        ArrayList<String> expected = new ArrayList<String>();
       
        int MESSAGE_COUNT = 10000;
        for(int i=0; i < MESSAGE_COUNT; i++) {
            Message message = createMessage(producerInfo, destination);
            message.setPersistent(true);
            connection.send(message);
            expected.add(message.getMessageId().toString());
        }
        connection.request(closeConnectionInfo(connectionInfo));

        // restart the broker.
        restartBroker();

        // Setup the consumer and receive the message.
        connection = createConnection();
        connectionInfo = createConnectionInfo();
        sessionInfo = createSessionInfo(connectionInfo);
        connection.send(connectionInfo);
        connection.send(sessionInfo);
        ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
        connection.send(consumerInfo);
        producerInfo = createProducerInfo(sessionInfo);
        connection.send(producerInfo);

        for(int i=0; i < MESSAGE_COUNT/2; i++) {
            Message m = receiveMessage(connection);
            assertNotNull("Should have received message "+expected.get(0)+" by now!", m);
            assertEquals(expected.remove(0), m.getMessageId().toString());
            MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
            connection.send(ack);
        }
       
        connection.request(closeConnectionInfo(connectionInfo));
       
        // restart the broker.
        restartBroker();

        // Setup the consumer and receive the message.
        connection = createConnection();
        connectionInfo = createConnectionInfo();
        sessionInfo = createSessionInfo(connectionInfo);
        connection.send(connectionInfo);
        connection.send(sessionInfo);
        consumerInfo = createConsumerInfo(sessionInfo, destination);
        connection.send(consumerInfo);

        for(int i=0; i < MESSAGE_COUNT/2; i++) {
            Message m = receiveMessage(connection);
            assertNotNull("Should have received message "+expected.get(i)+" by now!", m);
            assertEquals(expected.get(i), m.getMessageId().toString());
            MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
            connection.send(ack);
           
           
        }
       
        connection.request(closeConnectionInfo(connectionInfo));
    }
View Full Code Here

Examples of org.apache.activemq.broker.StubConnection

       
        int sendNumMessages = 10;
        int receiveNumMessages = 5;
       
        // Create a producer
        StubConnection connection1 = createConnection();
        ConnectionInfo connectionInfo1 = createConnectionInfo();
        SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
        ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
        connection1.send(connectionInfo1);
        connection1.send(sessionInfo1);
        connection1.send(producerInfo);
       
        // Create a destination on the local broker
        ActiveMQDestination destinationInfo1 = null;
       
        // Send a 10 messages to the local broker
        for (int i = 0; i < sendNumMessages; ++i) {
            destinationInfo1 = createDestinationInfo(connection1, connectionInfo1, ActiveMQDestination.QUEUE_TYPE);
            connection1.request(createMessage(producerInfo, destinationInfo1, DeliveryMode.NON_PERSISTENT));
        }
       
        // Ensure that there are 10 messages on the local broker
        Object[] messages = browseQueueWithJmx(localBroker);
        assertEquals(sendNumMessages, messages.length);
       
       
        // Create a synchronous consumer on the remote broker
        final StubConnection connection2 = createRemoteConnection();
        ConnectionInfo connectionInfo2 = createConnectionInfo();
        SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
        connection2.send(connectionInfo2);
        connection2.send(sessionInfo2);
        ActiveMQDestination destinationInfo2 =
            createDestinationInfo(connection2, connectionInfo2, ActiveMQDestination.QUEUE_TYPE);
        final ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destinationInfo2);
        connection2.send(consumerInfo2);
       
        // Consume 5 of the messages from the remote broker and ack them.
        // Because the prefetch size is set to 1000 in the createConsumerInfo()
        // method, this will cause the messages on the local broker to be
        // forwarded to the remote broker.
        for (int i = 0; i < receiveNumMessages; ++i) {
            Message message1 = receiveMessage(connection2);
            assertNotNull(message1);
            connection2.send(createAck(consumerInfo2, message1, 1, MessageAck.STANDARD_ACK_TYPE));
           
            Object[] msgs1 = browseQueueWithJmx(remoteBroker);
            LOG.info("Found [" + msgs1.length + "] messages with JMX");
//            assertEquals((sendNumMessages-i), msgs.length);
        }
       
        // Ensure that there are zero messages on the local broker. This tells
        // us that those messages have been prefetched to the remote broker
        // where the demand exists.
        messages = browseQueueWithJmx(localBroker);
        assertEquals(0, messages.length);
       
        // Close the consumer on the remote broker
        connection2.send(consumerInfo2.createRemoveCommand());
       
        // There should now be 5 messages stuck on the remote broker
        messages = browseQueueWithJmx(remoteBroker);
        assertEquals(5, messages.length);
       
        // Create a consumer on the local broker just to confirm that it doesn't
        // receive any messages 
        ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destinationInfo1);
        connection1.send(consumerInfo1);
        Message message1 = receiveMessage(connection1);
       
        //////////////////////////////////////////////////////
        // An assertNull() is done here because this is currently the correct
        // behavior. This is actually the purpose of this test - to prove that
        // messages are stuck on the remote broker. AMQ-2324 and AMQ-2484 aim
        // to fix this situation so that messages don't get stuck.
        assertNull(message1);
        //////////////////////////////////////////////////////
       
        ConsumerInfo consumerInfo3 = createConsumerInfo(sessionInfo2, destinationInfo2);
        connection2.send(consumerInfo3);
       
        // Consume the last 5 messages from the remote broker and ack them just
        // to clean up the queue.
        int counter = 0;
        for (int i = 0; i < receiveNumMessages; ++i) {
            message1 = receiveMessage(connection2);
            assertNotNull(message1);
            connection2.send(createAck(consumerInfo3, message1, 1, MessageAck.STANDARD_ACK_TYPE));
            ++counter;
        }
        // Ensure that 5 messages were received
        assertEquals(receiveNumMessages, counter);
       
        // Let those acks percolate... This stinks but it's the only way currently
        // because these types of internal broker actions are non-deterministic.
        Thread.sleep(4000);
       
        // Ensure that the queue on the remote broker is empty
        messages = browseQueueWithJmx(remoteBroker);
        assertEquals(0, messages.length);
       
        // Close the consumer on the remote broker
        connection2.send(consumerInfo3.createRemoveCommand());
       
        connection1.stop();
        connection2.stop();
    }
View Full Code Here

Examples of org.apache.activemq.broker.StubConnection

        return "vm://localhost";
    }
   
    protected StubConnection createConnection() throws Exception {
        Transport transport = TransportFactory.connect(connector.getServer().getConnectURI());
        StubConnection connection = new StubConnection(transport);
        connections.add(connection);
        return connection;
    }
View Full Code Here

Examples of org.apache.activemq.broker.StubConnection

        return connection;
    }

    protected StubConnection createRemoteConnection() throws Exception {
        Transport transport = TransportFactory.connect(remoteConnector.getServer().getConnectURI());
        StubConnection connection = new StubConnection(transport);
        connections.add(connection);
        return connection;
    }
View Full Code Here

Examples of org.apache.activemq.broker.StubConnection

        return connection;
    }

    protected StubConnection createRemoteConnection() throws Exception {
        Transport transport = TransportFactory.connect(remoteConnector.getServer().getConnectURI());
        StubConnection connection = new StubConnection(transport);
        connections.add(connection);
        return connection;
    }
View Full Code Here

Examples of org.apache.activemq.broker.StubConnection

       
        int sendNumMessages = 10;
        int receiveNumMessages = 5;
       
        // Create a producer
        StubConnection connection1 = createConnection();
        ConnectionInfo connectionInfo1 = createConnectionInfo();
        SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
        ProducerInfo producerInfo = createProducerInfo(sessionInfo1);
        connection1.send(connectionInfo1);
        connection1.send(sessionInfo1);
        connection1.send(producerInfo);
       
        // Create a destination on the local broker
        ActiveMQDestination destinationInfo1 = null;
       
        // Send a 10 messages to the local broker
        for (int i = 0; i < sendNumMessages; ++i) {
            destinationInfo1 = createDestinationInfo(connection1, connectionInfo1, ActiveMQDestination.QUEUE_TYPE);
            connection1.request(createMessage(producerInfo, destinationInfo1, DeliveryMode.NON_PERSISTENT));
        }
       
        // Ensure that there are 10 messages on the local broker
        Object[] messages = browseQueueWithJmx(localBroker);
        assertEquals(sendNumMessages, messages.length);
       
       
        // Create a synchronous consumer on the remote broker
        final StubConnection connection2 = createRemoteConnection();
        ConnectionInfo connectionInfo2 = createConnectionInfo();
        SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
        connection2.send(connectionInfo2);
        connection2.send(sessionInfo2);
        ActiveMQDestination destinationInfo2 =
            createDestinationInfo(connection2, connectionInfo2, ActiveMQDestination.QUEUE_TYPE);
        final ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destinationInfo2);
        connection2.send(consumerInfo2);
       
        // Consume 5 of the messages from the remote broker and ack them.
        // Because the prefetch size is set to 1000 in the createConsumerInfo()
        // method, this will cause the messages on the local broker to be
        // forwarded to the remote broker.
        for (int i = 0; i < receiveNumMessages; ++i) {
            Message message1 = receiveMessage(connection2);
            assertNotNull(message1);
            connection2.send(createAck(consumerInfo2, message1, 1, MessageAck.STANDARD_ACK_TYPE));
           
            Object[] msgs1 = browseQueueWithJmx(remoteBroker);
            LOG.info("Found [" + msgs1.length + "] messages with JMX");
//            assertEquals((sendNumMessages-i), msgs.length);
        }
       
        // Ensure that there are zero messages on the local broker. This tells
        // us that those messages have been prefetched to the remote broker
        // where the demand exists.
        messages = browseQueueWithJmx(localBroker);
        assertEquals(0, messages.length);
       
        // Close the consumer on the remote broker
        connection2.send(consumerInfo2.createRemoveCommand());
       
        // There should now be 5 messages stuck on the remote broker
        messages = browseQueueWithJmx(remoteBroker);
        assertEquals(5, messages.length);
       
        // Create a consumer on the local broker just to confirm that it doesn't
        // receive any messages 
        ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destinationInfo1);
        connection1.send(consumerInfo1);
        Message message1 = receiveMessage(connection1);
       
        //////////////////////////////////////////////////////
        // An assertNull() is done here because this is currently the correct
        // behavior. This is actually the purpose of this test - to prove that
        // messages are stuck on the remote broker. AMQ-2324 and AMQ-2484 aim
        // to fix this situation so that messages don't get stuck.
        assertNull(message1);
        //////////////////////////////////////////////////////
       
        ConsumerInfo consumerInfo3 = createConsumerInfo(sessionInfo2, destinationInfo2);
        connection2.send(consumerInfo3);
       
        // Consume the last 5 messages from the remote broker and ack them just
        // to clean up the queue.
        int counter = 0;
        for (int i = 0; i < receiveNumMessages; ++i) {
            message1 = receiveMessage(connection2);
            assertNotNull(message1);
            connection2.send(createAck(consumerInfo3, message1, 1, MessageAck.STANDARD_ACK_TYPE));
            ++counter;
        }
        // Ensure that 5 messages were received
        assertEquals(receiveNumMessages, counter);
       
        // Let those acks percolate... This stinks but it's the only way currently
        // because these types of internal broker actions are non-deterministic.
        Thread.sleep(4000);
       
        // Ensure that the queue on the remote broker is empty
        messages = browseQueueWithJmx(remoteBroker);
        assertEquals(0, messages.length);
       
        // Close the consumer on the remote broker
        connection2.send(consumerInfo3.createRemoveCommand());
       
        connection1.stop();
        connection2.stop();
    }
View Full Code Here

Examples of org.apache.activemq.broker.StubConnection

        return "vm://localhost";
    }
   
    protected StubConnection createConnection() throws Exception {
        Transport transport = TransportFactory.connect(connector.getServer().getConnectURI());
        StubConnection connection = new StubConnection(transport);
        connections.add(connection);
        return connection;
    }
View Full Code Here

Examples of org.apache.activemq.broker.StubConnection

    public void testConnectionAdvisories() throws Exception {
       
        ActiveMQDestination destination = AdvisorySupport.getConnectionAdvisoryTopic();
       
        // Setup a first connection
        StubConnection connection1 = createConnection();
        ConnectionInfo connectionInfo1 = createConnectionInfo();
        SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
        ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
        consumerInfo1.setPrefetchSize(100);
       
        connection1.send(connectionInfo1);
        connection1.send(sessionInfo1);
        connection1.send(consumerInfo1);

        // We should get an advisory of our own connection.
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        assertNotNull(m1.getDataStructure());
        assertEquals(((ConnectionInfo)m1.getDataStructure()).getConnectionId(), connectionInfo1.getConnectionId());

        // Setup a second connection
        StubConnection connection2 = createConnection();
        ConnectionInfo connectionInfo2 = createConnectionInfo();
        connection2.send(connectionInfo2);
       
        // We should get an advisory of the second connection.
        m1 = receiveMessage(connection1);
        assertNotNull(m1);
        assertNotNull(m1.getDataStructure());
        assertEquals(((ConnectionInfo)m1.getDataStructure()).getConnectionId(), connectionInfo2.getConnectionId());

        // Close the second connection.
        connection2.send(closeConnectionInfo(connectionInfo2));
        connection2.stop();

        // We should get an advisory of the second connection closing
        m1 = receiveMessage(connection1);
        assertNotNull(m1);
        assertNotNull(m1.getDataStructure());
View Full Code Here

Examples of org.apache.activemq.broker.StubConnection

        ActiveMQDestination queue = new ActiveMQQueue("test");
        ActiveMQDestination destination = AdvisorySupport.getConsumerAdvisoryTopic(queue);
       
        // Setup a first connection
        StubConnection connection1 = createConnection();
        ConnectionInfo connectionInfo1 = createConnectionInfo();
        SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
        ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
        consumerInfo1.setPrefetchSize(100);
       
        connection1.send(connectionInfo1);
        connection1.send(sessionInfo1);
        connection1.send(consumerInfo1);

        // We should not see and advisory for the advisory consumer.
        assertNoMessagesLeft(connection1);

        // Setup a second consumer.
        StubConnection connection2 = createConnection();
        ConnectionInfo connectionInfo2 = createConnectionInfo();
        SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
        ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, queue);
        consumerInfo1.setPrefetchSize(100);
       
        connection2.send(connectionInfo2);
        connection2.send(sessionInfo2);
        connection2.send(consumerInfo2);
       
        // We should get an advisory of the new consumer.
        Message m1 = receiveMessage(connection1);
        assertNotNull(m1);
        assertNotNull(m1.getDataStructure());
        assertEquals(((ConsumerInfo)m1.getDataStructure()).getConsumerId(), consumerInfo2.getConsumerId());

        // Close the second connection.
        connection2.send(closeConnectionInfo(connectionInfo2));
        connection2.stop();

        // We should get an advisory of the consumer closing
        m1 = receiveMessage(connection1);
        assertNotNull(m1);
        assertNotNull(m1.getDataStructure());
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.