Search in sources :

Example 6 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class ProxyTestSupport method createRemoteConnection.

protected StubConnection createRemoteConnection() throws Exception {
    Transport transport = TransportFactory.connect(remoteConnector.getServer().getConnectURI());
    StubConnection connection = new StubConnection(transport);
    connections.add(connection);
    return connection;
}
Also used : StubConnection(org.apache.activemq.broker.StubConnection) Transport(org.apache.activemq.transport.Transport)

Example 7 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class DiscoveryTransportBrokerTest method testPublisherFailsOver.

public void testPublisherFailsOver() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    int deliveryMode = DeliveryMode.NON_PERSISTENT;
    // Start a normal consumer on the local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.request(consumerInfo1);
    // Start a normal consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Start a failover publisher.
    StubConnection connection3 = createFailoverConnection();
    ConnectionInfo connectionInfo3 = createConnectionInfo();
    SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
    ProducerInfo producerInfo3 = createProducerInfo(sessionInfo3);
    connection3.send(connectionInfo3);
    connection3.send(sessionInfo3);
    connection3.send(producerInfo3);
    // Send the message using the fail over publisher.
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    // The message will be sent to one of the brokers.
    FailoverTransport ft = connection3.getTransport().narrow(FailoverTransport.class);
    // See which broker we were connected to.
    StubConnection connectionA;
    StubConnection connectionB;
    TransportConnector serverA;
    if (connector.getServer().getConnectURI().getPort() == ft.getConnectedTransportURI().getPort()) {
        connectionA = connection1;
        connectionB = connection2;
        serverA = connector;
    } else {
        connectionA = connection2;
        connectionB = connection1;
        serverA = remoteConnector;
    }
    assertNotNull(receiveMessage(connectionA));
    assertNoMessagesLeft(connectionB);
    // Dispose the server so that it fails over to the other server.
    LOG.info("Disconnecting active server");
    serverA.stop();
    LOG.info("Sending request that should failover");
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    assertNotNull(receiveMessage(connectionB));
    assertNoMessagesLeft(connectionA);
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) StubConnection(org.apache.activemq.broker.StubConnection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SessionInfo(org.apache.activemq.command.SessionInfo) FailoverTransport(org.apache.activemq.transport.failover.FailoverTransport) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 8 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class DiscoveryTransportBrokerTest method createFailoverConnection.

protected StubConnection createFailoverConnection() throws Exception {
    URI failoverURI = new URI("discovery:(" + getDiscoveryUri() + ")?startupMaxReconnectAttempts=10&initialReconnectDelay=1000");
    Transport transport = TransportFactory.connect(failoverURI);
    StubConnection connection = new StubConnection(transport);
    connections.add(connection);
    return connection;
}
Also used : StubConnection(org.apache.activemq.broker.StubConnection) Transport(org.apache.activemq.transport.Transport) FailoverTransport(org.apache.activemq.transport.failover.FailoverTransport) URI(java.net.URI)

Example 9 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class FailoverTransportBrokerTest method testNoBrokersInBrokerInfo.

public void testNoBrokersInBrokerInfo() throws Exception {
    final BrokerInfo[] info = new BrokerInfo[1];
    TransportListener listener = new TransportListener() {

        @Override
        public void onCommand(Object command) {
            LOG.info("Got command: " + command);
            if (command instanceof BrokerInfo) {
                info[0] = (BrokerInfo) command;
            }
        }

        @Override
        public void onException(IOException error) {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void transportInterupted() {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void transportResumed() {
        // To change body of implemented methods use File | Settings | File Templates.
        }
    };
    @SuppressWarnings("unused") StubConnection c = createFailoverConnection(listener);
    int count = 0;
    while (count++ < 20 && info[0] == null) {
        TimeUnit.SECONDS.sleep(1);
    }
    Assert.assertNotNull("got a valid brokerInfo after 20 secs", info[0]);
    Assert.assertNull("no peer brokers present", info[0].getPeerBrokerInfos());
}
Also used : TransportListener(org.apache.activemq.transport.TransportListener) StubConnection(org.apache.activemq.broker.StubConnection) IOException(java.io.IOException) BrokerInfo(org.apache.activemq.command.BrokerInfo)

Example 10 with StubConnection

use of org.apache.activemq.broker.StubConnection in project activemq-artemis by apache.

the class FailoverTransportBrokerTest method createFailoverConnection.

protected StubConnection createFailoverConnection(TransportListener listener) throws Exception {
    URI failoverURI = new URI("failover://" + newURI(0) + "," + newURI(1) + "");
    Transport transport = TransportFactory.connect(failoverURI);
    StubConnection connection = new StubConnection(transport, listener);
    connections.add(connection);
    return connection;
}
Also used : StubConnection(org.apache.activemq.broker.StubConnection) Transport(org.apache.activemq.transport.Transport) URI(java.net.URI)

Aggregations

StubConnection (org.apache.activemq.broker.StubConnection)39 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)18 SessionInfo (org.apache.activemq.command.SessionInfo)18 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)17 Transport (org.apache.activemq.transport.Transport)16 ProducerInfo (org.apache.activemq.command.ProducerInfo)14 Message (org.apache.activemq.command.Message)13 URI (java.net.URI)9 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)8 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)6 RemoveInfo (org.apache.activemq.command.RemoveInfo)5 MockTransport (org.apache.activemq.transport.mock.MockTransport)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 OpenwireArtemisBaseTest (org.apache.activemq.broker.artemiswrapper.OpenwireArtemisBaseTest)3 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)3 FailoverTransport (org.apache.activemq.transport.failover.FailoverTransport)2 URISyntaxException (java.net.URISyntaxException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MessageNotWriteableException (javax.jms.MessageNotWriteableException)1