Search in sources :

Example 6 with DestinationViewMBean

use of org.apache.activemq.broker.jmx.DestinationViewMBean in project camel by apache.

the class JmsTestSupport method getDestinationMBean.

public DestinationViewMBean getDestinationMBean(String destinationName, boolean topic) throws MalformedObjectNameException {
    String domain = "org.apache.activemq";
    String destinationType = topic ? "Topic" : "Queue";
    ObjectName name = new ObjectName(String.format("%s:type=Broker,brokerName=localhost,destinationType=%s,destinationName=%s", domain, destinationType, destinationName));
    return (DestinationViewMBean) broker.getManagementContext().newProxyInstance(name, DestinationViewMBean.class, true);
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) ObjectName(javax.management.ObjectName)

Example 7 with DestinationViewMBean

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

the class XARecoveryBrokerTest method assertEmptyDLQ.

private void assertEmptyDLQ() throws Exception {
    try {
        DestinationViewMBean destinationView = getProxyToDestination(new ActiveMQQueue(SharedDeadLetterStrategy.DEFAULT_DEAD_LETTER_QUEUE_NAME));
        assertEquals("nothing on dlq", 0, destinationView.getQueueSize());
        assertEquals("nothing added to dlq", 0, destinationView.getEnqueueCount());
    } catch (java.lang.reflect.UndeclaredThrowableException maybeOk) {
        if (maybeOk.getUndeclaredThrowable() instanceof javax.management.InstanceNotFoundException) {
        // perfect no dlq
        } else {
            throw maybeOk;
        }
    }
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) InstanceNotFoundException(javax.management.InstanceNotFoundException)

Example 8 with DestinationViewMBean

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

the class XARecoveryBrokerTest method testPreparedJmxView.

public void testPreparedJmxView() 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);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Prepare 4 message sends.
    for (int i = 0; i < 4; i++) {
        // Begin the transaction.
        XATransactionId txid = createXATransaction(sessionInfo);
        connection.send(createBeginTransaction(connectionInfo, txid));
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        message.setTransactionId(txid);
        connection.send(message);
        // Prepare
        connection.send(createPrepareTransaction(connectionInfo, txid));
    }
    Response response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
    assertNotNull(response);
    DataArrayResponse dar = (DataArrayResponse) response;
    assertEquals(4, dar.getData().length);
    // view prepared in kahadb view
    if (broker.getPersistenceAdapter() instanceof KahaDBPersistenceAdapter) {
        PersistenceAdapterViewMBean kahadbView = getProxyToPersistenceAdapter(broker.getPersistenceAdapter().toString());
        String txFromView = kahadbView.getTransactions();
        LOG.info("Tx view fromm PA:" + txFromView);
        assertTrue("xid with our dud format in transaction string " + txFromView, txFromView.contains("XID:[55,"));
    }
    // restart the broker.
    restartBroker();
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    connection.send(connectionInfo);
    response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
    assertNotNull(response);
    dar = (DataArrayResponse) response;
    assertEquals(4, dar.getData().length);
    // validate destination depth via jmx
    DestinationViewMBean destinationView = getProxyToDestination(destinationList(destination)[0]);
    assertEquals("enqueue count does not see prepared", 0, destinationView.getQueueSize());
    TransactionId first = (TransactionId) dar.getData()[0];
    int commitCount = 0;
    // via jmx, force outcome
    for (int i = 0; i < 4; i++) {
        RecoveredXATransactionViewMBean mbean = getProxyToPreparedTransactionViewMBean((TransactionId) dar.getData()[i]);
        if (i % 2 == 0) {
            mbean.heuristicCommit();
            commitCount++;
        } else {
            mbean.heuristicRollback();
        }
    }
    // verify all completed
    response = connection.request(new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER));
    assertNotNull(response);
    dar = (DataArrayResponse) response;
    assertEquals(0, dar.getData().length);
    // verify messages available
    assertEquals("enqueue count reflects outcome", commitCount, destinationView.getQueueSize());
    // verify mbeans gone
    try {
        RecoveredXATransactionViewMBean gone = getProxyToPreparedTransactionViewMBean(first);
        gone.heuristicRollback();
        fail("Excepted not found");
    } catch (InstanceNotFoundException expectedNotfound) {
    }
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) XATransactionId(org.apache.activemq.command.XATransactionId) Message(org.apache.activemq.command.Message) InstanceNotFoundException(javax.management.InstanceNotFoundException) SessionInfo(org.apache.activemq.command.SessionInfo) PersistenceAdapterViewMBean(org.apache.activemq.broker.jmx.PersistenceAdapterViewMBean) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) XATransactionId(org.apache.activemq.command.XATransactionId) TransactionId(org.apache.activemq.command.TransactionId) Response(org.apache.activemq.command.Response) DataArrayResponse(org.apache.activemq.command.DataArrayResponse) TransactionInfo(org.apache.activemq.command.TransactionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) RecoveredXATransactionViewMBean(org.apache.activemq.broker.jmx.RecoveredXATransactionViewMBean) DataArrayResponse(org.apache.activemq.command.DataArrayResponse) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 9 with DestinationViewMBean

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

the class XARecoveryBrokerTest method testQueuePersistentPreparedAcksNotLostOnRestart.

public void testQueuePersistentPreparedAcksNotLostOnRestart() 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));
    ConsumerInfo consumerInfo;
    Message m = null;
    for (ActiveMQDestination dest : destinationList(destination)) {
        // Setup the consumer and receive the message.
        consumerInfo = createConsumerInfo(sessionInfo, dest);
        connection.send(consumerInfo);
        for (int i = 0; i < 4; i++) {
            m = receiveMessage(connection);
            assertNotNull(m);
        }
        // one ack with last received, mimic a beforeEnd synchronization
        MessageAck ack = createAck(consumerInfo, m, 4, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection.send(ack);
    }
    connection.request(createPrepareTransaction(connectionInfo, txid));
    // restart the broker.
    restartBroker();
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    connection.send(connectionInfo);
    // validate recovery
    TransactionInfo recoverInfo = new TransactionInfo(connectionInfo.getConnectionId(), null, TransactionInfo.RECOVER);
    DataArrayResponse dataArrayResponse = (DataArrayResponse) connection.request(recoverInfo);
    assertEquals("there is a prepared tx", 1, dataArrayResponse.getData().length);
    assertEquals("it matches", txid, dataArrayResponse.getData()[0]);
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(sessionInfo);
    consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // no redelivery, exactly once semantics unless there is rollback
    m = receiveMessage(connection);
    assertNull(m);
    assertNoMessagesLeft(connection);
    // validate destination depth via jmx
    DestinationViewMBean destinationView = getProxyToDestination(destinationList(destination)[0]);
    assertEquals("enqueue count does not see prepared acks", 4, destinationView.getQueueSize());
    assertEquals("enqueue count does not see prepared acks", 0, destinationView.getDequeueCount());
    connection.request(createCommitTransaction2Phase(connectionInfo, txid));
    // validate recovery complete
    dataArrayResponse = (DataArrayResponse) connection.request(recoverInfo);
    assertEquals("there are no prepared tx", 0, dataArrayResponse.getData().length);
    assertEquals("enqueue count does not see committed acks", 0, destinationView.getQueueSize());
    assertEquals("enqueue count does not see committed acks", 4, destinationView.getDequeueCount());
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) 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) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) TransactionInfo(org.apache.activemq.command.TransactionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) DataArrayResponse(org.apache.activemq.command.DataArrayResponse)

Example 10 with DestinationViewMBean

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

the class AbortSlowConsumer0Test method testAbortConsumerOnDeadConnection.

@Test
public void testAbortConsumerOnDeadConnection() throws Exception {
    TransportConnector transportConnector = broker.addConnector("tcp://0.0.0.0:0");
    transportConnector.setBrokerService(broker);
    transportConnector.setTaskRunnerFactory(broker.getTaskRunnerFactory());
    transportConnector.start();
    SocketProxy socketProxy = new SocketProxy(transportConnector.getPublishableConnectURI());
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(socketProxy.getUrl());
    ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy();
    prefetchPolicy.setAll(4);
    connectionFactory.setPrefetchPolicy(prefetchPolicy);
    Connection c = connectionFactory.createConnection();
    connections.add(c);
    c.start();
    Session session = c.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    final ActiveMQMessageConsumer messageconsumer = (ActiveMQMessageConsumer) session.createConsumer(destination);
    startProducers(destination, 10);
    messageconsumer.receive(4000).acknowledge();
    assertNotNull(messageconsumer.receive(4000));
    assertNotNull(messageconsumer.receive(4000));
    assertNotNull(messageconsumer.receive(4000));
    // close control command won't get through
    socketProxy.pause();
    ActiveMQDestination amqDest = (ActiveMQDestination) destination;
    ObjectName destinationViewMBean = new ObjectName("org.apache.activemq:destinationType=" + (amqDest.isTopic() ? "Topic" : "Queue") + ",destinationName=" + amqDest.getPhysicalName() + ",type=Broker,brokerName=localhost");
    final DestinationViewMBean destView = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(destinationViewMBean, DestinationViewMBean.class, true);
    assertTrue("Consumer gone from broker view", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            LOG.info("DestView {} consumerCount {}", destView, destView.getConsumerCount());
            return 0 == destView.getConsumerCount();
        }
    }));
    socketProxy.goOn();
    assertTrue("consumer was closed", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            boolean closed = false;
            try {
                messageconsumer.receive(400);
            } catch (javax.jms.IllegalStateException expected) {
                closed = expected.toString().contains("closed");
            }
            return closed;
        }
    }));
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) Connection(javax.jms.Connection) SocketProxy(org.apache.activemq.util.SocketProxy) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) ObjectName(javax.management.ObjectName) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) TransportConnector(org.apache.activemq.broker.TransportConnector) ActiveMQPrefetchPolicy(org.apache.activemq.ActiveMQPrefetchPolicy) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

DestinationViewMBean (org.apache.activemq.broker.jmx.DestinationViewMBean)17 ObjectName (javax.management.ObjectName)6 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)6 Wait (org.apache.activemq.util.Wait)5 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)4 Test (org.junit.Test)4 Message (javax.jms.Message)3 MessageConsumer (javax.jms.MessageConsumer)3 MessageListener (javax.jms.MessageListener)3 InstanceNotFoundException (javax.management.InstanceNotFoundException)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Connection (javax.jms.Connection)2 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)2 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)2 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)2 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)2 Message (org.apache.activemq.command.Message)2 ProducerInfo (org.apache.activemq.command.ProducerInfo)2 SessionInfo (org.apache.activemq.command.SessionInfo)2