Search in sources :

Example 1 with FailoverTransport

use of org.apache.activemq.transport.failover.FailoverTransport in project activemq-artemis by apache.

the class ActiveMQXAConnectionFactoryTest method assertTransactionGoneFromFailoverState.

private void assertTransactionGoneFromFailoverState(ActiveMQXAConnection connection1, Xid tid) throws Exception {
    FailoverTransport transport = connection1.getTransport().narrow(FailoverTransport.class);
    TransactionInfo info = new TransactionInfo(connection1.getConnectionInfo().getConnectionId(), new XATransactionId(tid), TransactionInfo.COMMIT_ONE_PHASE);
    assertNull("transaction should not exist in the state tracker", transport.getStateTracker().processCommitTransactionOnePhase(info));
}
Also used : XATransactionId(org.apache.activemq.command.XATransactionId) TransactionInfo(org.apache.activemq.command.TransactionInfo) FailoverTransport(org.apache.activemq.transport.failover.FailoverTransport)

Example 2 with FailoverTransport

use of org.apache.activemq.transport.failover.FailoverTransport 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 3 with FailoverTransport

use of org.apache.activemq.transport.failover.FailoverTransport in project activemq-artemis by apache.

the class NetworkFailoverTest method testRequestReply.

public void testRequestReply() throws Exception {
    final MessageProducer remoteProducer = remoteSession.createProducer(null);
    MessageConsumer remoteConsumer = remoteSession.createConsumer(included);
    remoteConsumer.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message msg) {
            final TextMessage textMsg = (TextMessage) msg;
            try {
                String payload = "REPLY: " + textMsg.getText() + ", " + textMsg.getJMSMessageID();
                Destination replyTo;
                replyTo = msg.getJMSReplyTo();
                textMsg.clearBody();
                textMsg.setText(payload);
                LOG.info("*** Sending response: {}", textMsg.getText());
                remoteProducer.send(replyTo, textMsg);
                LOG.info("replied with: " + textMsg.getJMSMessageID());
            } catch (DestinationDoesNotExistException expected) {
                // been removed but not yet recreated
                replyToNonExistDest.incrementAndGet();
                try {
                    LOG.info("NED: " + textMsg.getJMSMessageID());
                } catch (JMSException e) {
                    e.printStackTrace();
                }
            } catch (Exception e) {
                LOG.warn("*** Responder listener caught exception: ", e);
                e.printStackTrace();
            }
        }
    });
    Queue tempQueue = localSession.createTemporaryQueue();
    MessageProducer requestProducer = localSession.createProducer(included);
    requestProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    MessageConsumer requestConsumer = localSession.createConsumer(tempQueue);
    // track remote dlq for forward failures
    MessageConsumer dlqconsumer = remoteSession.createConsumer(new ActiveMQQueue(SharedDeadLetterStrategy.DEFAULT_DEAD_LETTER_QUEUE_NAME));
    dlqconsumer.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            try {
                LOG.info("dlq " + message.getJMSMessageID());
            } catch (JMSException e) {
                e.printStackTrace();
            }
            remoteDLQCount.incrementAndGet();
        }
    });
    // allow for consumer infos to perculate around
    Thread.sleep(2000);
    long done = System.currentTimeMillis() + (MESSAGE_COUNT * 6000);
    int i = 0;
    while (MESSAGE_COUNT > roundTripComplete.get() + remoteDLQCount.get() + replyToNonExistDest.get() && done > System.currentTimeMillis()) {
        if (i < MESSAGE_COUNT) {
            String payload = "test msg " + i;
            i++;
            TextMessage msg = localSession.createTextMessage(payload);
            msg.setJMSReplyTo(tempQueue);
            requestProducer.send(msg);
            LOG.info("Sent: " + msg.getJMSMessageID() + ", Failing over");
            ((FailoverTransport) ((TransportFilter) ((TransportFilter) ((ActiveMQConnection) localConnection).getTransport()).getNext()).getNext()).handleTransportFailure(new IOException("Forcing failover from test"));
        }
        TextMessage result = (TextMessage) requestConsumer.receive(5000);
        if (result != null) {
            LOG.info("Got reply: " + result.getJMSMessageID() + ", " + result.getText());
            roundTripComplete.incrementAndGet();
        }
    }
    LOG.info("complete: " + roundTripComplete.get() + ", remoteDLQCount: " + remoteDLQCount.get() + ", replyToNonExistDest: " + replyToNonExistDest.get());
    assertEquals("complete:" + roundTripComplete.get() + ", remoteDLQCount: " + remoteDLQCount.get() + ", replyToNonExistDest: " + replyToNonExistDest.get(), MESSAGE_COUNT, roundTripComplete.get() + remoteDLQCount.get() + replyToNonExistDest.get());
}
Also used : DestinationDoesNotExistException(org.apache.activemq.DestinationDoesNotExistException) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MessageListener(javax.jms.MessageListener) JMSException(javax.jms.JMSException) FailoverTransport(org.apache.activemq.transport.failover.FailoverTransport) IOException(java.io.IOException) TransportFilter(org.apache.activemq.transport.TransportFilter) DestinationDoesNotExistException(org.apache.activemq.DestinationDoesNotExistException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) MessageProducer(javax.jms.MessageProducer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage)

Aggregations

FailoverTransport (org.apache.activemq.transport.failover.FailoverTransport)3 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)2 IOException (java.io.IOException)1 Destination (javax.jms.Destination)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageListener (javax.jms.MessageListener)1 MessageProducer (javax.jms.MessageProducer)1 Queue (javax.jms.Queue)1 TextMessage (javax.jms.TextMessage)1 DestinationDoesNotExistException (org.apache.activemq.DestinationDoesNotExistException)1 StubConnection (org.apache.activemq.broker.StubConnection)1 TransportConnector (org.apache.activemq.broker.TransportConnector)1 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)1 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)1 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)1 ProducerInfo (org.apache.activemq.command.ProducerInfo)1 SessionInfo (org.apache.activemq.command.SessionInfo)1 TransactionInfo (org.apache.activemq.command.TransactionInfo)1