Search in sources :

Example 76 with ProducerInfo

use of org.apache.activemq.command.ProducerInfo in project activemq-artemis by apache.

the class RecoveryBrokerTest method testQueueNonPersistentMessagesLostOnRestart.

public void testQueueNonPersistentMessagesLostOnRestart() 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);
    Message message = createMessage(producerInfo, destination);
    message.setPersistent(false);
    connection.send(message);
    // 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);
    // Message should have been dropped due to broker restart.
    assertNoMessagesLeft(connection);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 77 with ProducerInfo

use of org.apache.activemq.command.ProducerInfo in project activemq-artemis by apache.

the class RecoveryBrokerTest method XtestWildCardSubscriptionPreservedOnRestart.

/**
 * Used to verify that after a broker restart durable subscriptions that use
 * wild cards are still wild card subscription after broker restart.
 *
 * @throws Exception
 */
// need to revist!!!
public void XtestWildCardSubscriptionPreservedOnRestart() throws Exception {
    ActiveMQDestination dest1 = new ActiveMQTopic("TEST.A");
    ActiveMQDestination dest2 = new ActiveMQTopic("TEST.B");
    ActiveMQDestination dest3 = new ActiveMQTopic("TEST.C");
    ActiveMQDestination wildDest = new ActiveMQTopic("TEST.>");
    ArrayList<MessageId> sentBeforeRestart = new ArrayList<>();
    ArrayList<MessageId> sentBeforeCreateConsumer = new ArrayList<>();
    ArrayList<MessageId> sentAfterCreateConsumer = new ArrayList<>();
    // Setup a first connection
    {
        StubConnection connection1 = createConnection();
        ConnectionInfo connectionInfo1 = createConnectionInfo();
        connectionInfo1.setClientId("A");
        SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
        ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
        connection1.send(connectionInfo1);
        connection1.send(sessionInfo1);
        connection1.send(producerInfo1);
        // Create the durable subscription.
        ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, wildDest);
        consumerInfo1.setSubscriptionName("test");
        consumerInfo1.setPrefetchSize(100);
        connection1.send(consumerInfo1);
        // Close the subscription.
        connection1.send(closeConsumerInfo(consumerInfo1));
        // Send the messages
        for (int i = 0; i < 4; i++) {
            Message m = createMessage(producerInfo1, dest1, DeliveryMode.PERSISTENT);
            connection1.send(m);
            sentBeforeRestart.add(m.getMessageId());
        }
        connection1.request(closeConnectionInfo(connectionInfo1));
        connection1.stop();
    }
    // Restart the broker.
    restartBroker();
    // Get a connection to the new broker.
    {
        StubConnection connection2 = createConnection();
        ConnectionInfo connectionInfo2 = createConnectionInfo();
        connectionInfo2.setClientId("A");
        SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
        connection2.send(connectionInfo2);
        connection2.send(sessionInfo2);
        ProducerInfo producerInfo2 = createProducerInfo(sessionInfo2);
        connection2.send(producerInfo2);
        // Send messages before the durable subscription is re-activated.
        for (int i = 0; i < 4; i++) {
            Message m = createMessage(producerInfo2, dest2, DeliveryMode.PERSISTENT);
            connection2.send(m);
            sentBeforeCreateConsumer.add(m.getMessageId());
        }
        // Re-open the subscription.
        ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, wildDest);
        consumerInfo2.setSubscriptionName("test");
        consumerInfo2.setPrefetchSize(100);
        connection2.send(consumerInfo2);
        // Send messages after the subscription is activated.
        for (int i = 0; i < 4; i++) {
            Message m = createMessage(producerInfo2, dest3, DeliveryMode.PERSISTENT);
            connection2.send(m);
            sentAfterCreateConsumer.add(m.getMessageId());
        }
        // We should get the recovered messages...
        for (int i = 0; i < 4; i++) {
            Message m2 = receiveMessage(connection2);
            assertNotNull("Recovered message missing: " + i, m2);
            assertEquals(sentBeforeRestart.get(i), m2.getMessageId());
        }
        // reactivated.
        for (int i = 0; i < 4; i++) {
            Message m2 = receiveMessage(connection2);
            assertNotNull("Before activated message missing: " + i, m2);
            assertEquals(sentBeforeCreateConsumer.get(i), m2.getMessageId());
        }
        // reactivated.
        for (int i = 0; i < 4; i++) {
            Message m2 = receiveMessage(connection2);
            assertNotNull("After activated message missing: " + i, m2);
            assertEquals("" + i, sentAfterCreateConsumer.get(i), m2.getMessageId());
        }
        assertNoMessagesLeft(connection2);
    }
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) ArrayList(java.util.ArrayList) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) MessageId(org.apache.activemq.command.MessageId)

Example 78 with ProducerInfo

use of org.apache.activemq.command.ProducerInfo in project activemq-artemis by apache.

the class XARecoveryBrokerTest method testQueuePersistentCommittedMessagesNotLostOnRestart.

public void testQueuePersistentCommittedMessagesNotLostOnRestart() throws Exception {
    ActiveMQDestination destination = createDestination();
    // 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);
    // Begin the transaction.
    XATransactionId txid = createXATransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        message.setTransactionId(txid);
        connection.send(message);
    }
    // Commit
    connection.send(createCommitTransaction1Phase(connectionInfo, txid));
    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);
    for (int i = 0; i < expectedMessageCount(4, destination); i++) {
        Message m = receiveMessage(connection);
        assertNotNull(m);
    }
    assertNoMessagesLeft(connection);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) XATransactionId(org.apache.activemq.command.XATransactionId) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 79 with ProducerInfo

use of org.apache.activemq.command.ProducerInfo in project activemq-artemis by apache.

the class XARecoveryBrokerTest method testQueuePersistentUncommittedAcksLostOnRestart.

public void testQueuePersistentUncommittedAcksLostOnRestart() throws Exception {
    ActiveMQDestination destination = createDestination();
    // 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);
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        connection.send(message);
    }
    // Begin the transaction.
    XATransactionId txid = createXATransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    Message message = null;
    for (ActiveMQDestination dest : destinationList(destination)) {
        // Setup the consumer and receive the message.
        ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, dest);
        connection.send(consumerInfo);
        for (int i = 0; i < 4; i++) {
            message = receiveMessage(connection);
            assertNotNull(message);
        }
        MessageAck ack = createAck(consumerInfo, message, 4, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection.request(ack);
    }
    // Don't commit
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    for (ActiveMQDestination dest : destinationList(destination)) {
        // Setup the consumer and receive the message.
        ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, dest);
        connection.send(consumerInfo);
        for (int i = 0; i < 4; i++) {
            message = receiveMessage(connection);
            assertNotNull(message);
        }
    }
    assertNoMessagesLeft(connection);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) XATransactionId(org.apache.activemq.command.XATransactionId) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) MessageAck(org.apache.activemq.command.MessageAck) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 80 with ProducerInfo

use of org.apache.activemq.command.ProducerInfo in project activemq-artemis by apache.

the class BrokerBenchmark method testPerformance.

public void testPerformance() throws Exception {
    LOG.info("Running Benchmark for destination=" + destination + ", producers=" + prodcuerCount + ", consumers=" + consumerCount + ", deliveryMode=" + deliveryMode);
    final int consumeCount = destination.isTopic() ? consumerCount * produceCount : produceCount;
    final Semaphore consumersStarted = new Semaphore(1 - consumerCount);
    final Semaphore producersFinished = new Semaphore(1 - prodcuerCount);
    final Semaphore consumersFinished = new Semaphore(1 - consumerCount);
    final ProgressPrinter printer = new ProgressPrinter(produceCount + consumeCount, 10);
    // Start a producer and consumer
    profilerPause("Benchmark ready.  Start profiler ");
    long start = System.currentTimeMillis();
    final AtomicInteger receiveCounter = new AtomicInteger(0);
    for (int i = 0; i < consumerCount; i++) {
        new Thread() {

            @Override
            public void run() {
                try {
                    // Consume the messages
                    StubConnection connection = new StubConnection(broker);
                    ConnectionInfo connectionInfo = createConnectionInfo();
                    connection.send(connectionInfo);
                    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
                    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
                    consumerInfo.setPrefetchSize(1000);
                    connection.send(sessionInfo);
                    connection.send(consumerInfo);
                    consumersStarted.release();
                    while (receiveCounter.get() < consumeCount) {
                        int counter = 0;
                        // Get a least 1 message.
                        Message msg = receiveMessage(connection, 2000);
                        if (msg != null) {
                            printer.increment();
                            receiveCounter.incrementAndGet();
                            counter++;
                            // Try to piggy back a few extra message acks if
                            // they are ready.
                            Message extra = null;
                            while ((extra = receiveMessage(connection, 0)) != null) {
                                msg = extra;
                                printer.increment();
                                receiveCounter.incrementAndGet();
                                counter++;
                            }
                        }
                        if (msg != null) {
                            connection.send(createAck(consumerInfo, msg, counter, MessageAck.STANDARD_ACK_TYPE));
                        } else if (receiveCounter.get() < consumeCount) {
                            LOG.info("Consumer stall, waiting for message #" + receiveCounter.get() + 1);
                        }
                    }
                    connection.send(closeConsumerInfo(consumerInfo));
                } catch (Throwable e) {
                    e.printStackTrace();
                } finally {
                    consumersFinished.release();
                }
            }
        }.start();
    }
    // Make sure that the consumers are started first to avoid sending
    // messages
    // before a topic is subscribed so that those messages are not missed.
    consumersStarted.acquire();
    // Send the messages in an async thread.
    for (int i = 0; i < prodcuerCount; i++) {
        new Thread() {

            @Override
            public void run() {
                try {
                    StubConnection connection = new StubConnection(broker);
                    ConnectionInfo connectionInfo = createConnectionInfo();
                    connection.send(connectionInfo);
                    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
                    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
                    connection.send(sessionInfo);
                    connection.send(producerInfo);
                    for (int i = 0; i < produceCount / prodcuerCount; i++) {
                        Message message = createMessage(producerInfo, destination);
                        message.setPersistent(deliveryMode);
                        message.setResponseRequired(false);
                        connection.send(message);
                        printer.increment();
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                } finally {
                    producersFinished.release();
                }
            }
        }.start();
    }
    producersFinished.acquire();
    long end1 = System.currentTimeMillis();
    consumersFinished.acquire();
    long end2 = System.currentTimeMillis();
    LOG.info("Results for destination=" + destination + ", producers=" + prodcuerCount + ", consumers=" + consumerCount + ", deliveryMode=" + deliveryMode);
    LOG.info("Produced at messages/sec: " + (produceCount * 1000.0 / (end1 - start)));
    LOG.info("Consumed at messages/sec: " + (consumeCount * 1000.0 / (end2 - start)));
    profilerPause("Benchmark done.  Stop profiler ");
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) ProducerInfo(org.apache.activemq.command.ProducerInfo) Message(org.apache.activemq.command.Message) SessionInfo(org.apache.activemq.command.SessionInfo) Semaphore(java.util.concurrent.Semaphore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Aggregations

ProducerInfo (org.apache.activemq.command.ProducerInfo)95 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)72 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)72 SessionInfo (org.apache.activemq.command.SessionInfo)72 Message (org.apache.activemq.command.Message)69 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)42 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)18 XATransactionId (org.apache.activemq.command.XATransactionId)15 StubConnection (org.apache.activemq.broker.StubConnection)14 MessageAck (org.apache.activemq.command.MessageAck)14 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)11 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)9 TransactionInfo (org.apache.activemq.command.TransactionInfo)9 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)8 Response (org.apache.activemq.command.Response)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)4 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)4 TransactionId (org.apache.activemq.command.TransactionId)4