Search in sources :

Example 96 with ConsumerInfo

use of org.apache.activemq.command.ConsumerInfo 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 97 with ConsumerInfo

use of org.apache.activemq.command.ConsumerInfo 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)

Example 98 with ConsumerInfo

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

the class ConsumerInfoTest method createObject.

@Override
public Object createObject() throws Exception {
    ConsumerInfo info = new ConsumerInfo();
    populateObject(info);
    return info;
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo)

Example 99 with ConsumerInfo

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

the class ConsumerInfoTest method populateObject.

@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ConsumerInfo info = (ConsumerInfo) object;
    info.setConsumerId(createConsumerId("ConsumerId:1"));
    info.setBrowser(true);
    info.setDestination(createActiveMQDestination("Destination:2"));
    info.setPrefetchSize(1);
    info.setMaximumPendingMessageLimit(2);
    info.setDispatchAsync(false);
    info.setSelector("Selector:3");
    info.setSubscriptionName("SubscriptionName:4");
    info.setNoLocal(true);
    info.setExclusive(false);
    info.setRetroactive(true);
    info.setPriority((byte) 1);
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:5");
        }
        info.setBrokerPath(value);
    }
    info.setAdditionalPredicate(createBooleanExpression("AdditionalPredicate:6"));
    info.setNetworkSubscription(false);
    info.setOptimizedAcknowledge(true);
    info.setNoRangeAcks(false);
    {
        ConsumerId[] value = new ConsumerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createConsumerId("NetworkConsumerPath:7");
        }
        info.setNetworkConsumerPath(value);
    }
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo)

Example 100 with ConsumerInfo

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

the class ConsumerInfoTest method populateObject.

@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    ConsumerInfo info = (ConsumerInfo) object;
    info.setConsumerId(createConsumerId("ConsumerId:1"));
    info.setBrowser(true);
    info.setDestination(createActiveMQDestination("Destination:2"));
    info.setPrefetchSize(1);
    info.setMaximumPendingMessageLimit(2);
    info.setDispatchAsync(false);
    info.setSelector("Selector:3");
    info.setSubscriptionName("SubscriptionName:4");
    info.setNoLocal(true);
    info.setExclusive(false);
    info.setRetroactive(true);
    info.setPriority((byte) 1);
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:5");
        }
        info.setBrokerPath(value);
    }
    info.setAdditionalPredicate(createBooleanExpression("AdditionalPredicate:6"));
    info.setNetworkSubscription(false);
    info.setOptimizedAcknowledge(true);
    info.setNoRangeAcks(false);
    {
        ConsumerId[] value = new ConsumerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createConsumerId("NetworkConsumerPath:7");
        }
        info.setNetworkConsumerPath(value);
    }
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo)

Aggregations

ConsumerInfo (org.apache.activemq.command.ConsumerInfo)115 Message (org.apache.activemq.command.Message)77 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)76 SessionInfo (org.apache.activemq.command.SessionInfo)76 ProducerInfo (org.apache.activemq.command.ProducerInfo)72 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)45 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)25 StubConnection (org.apache.activemq.broker.StubConnection)17 MessageAck (org.apache.activemq.command.MessageAck)17 XATransactionId (org.apache.activemq.command.XATransactionId)15 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)12 Test (org.junit.Test)12 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)9 TransactionInfo (org.apache.activemq.command.TransactionInfo)9 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)8 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)8 RemoveInfo (org.apache.activemq.command.RemoveInfo)8 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)7 Response (org.apache.activemq.command.Response)7 MessageReference (org.apache.activemq.broker.region.MessageReference)6