Search in sources :

Example 1 with ManagementContext

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

the class Main method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        BrokerService broker = new BrokerService();
        broker.setPersistent(false);
        // String brokerDir = "xbean:...;
        // System.setProperty("activemq.base", brokerDir);
        // BrokerService broker = BrokerFactory.createBroker(new URI(brokerDir + "/activemq.xml"));
        // for running on Java 5 without mx4j
        ManagementContext managementContext = broker.getManagementContext();
        managementContext.setFindTigerMbeanServer(true);
        managementContext.setUseMBeanServer(true);
        managementContext.setCreateConnector(false);
        broker.setUseJmx(true);
        // broker.setPlugins(new BrokerPlugin[] { new
        // ConnectionDotFilePlugin(), new UDPTraceBrokerPlugin() });
        broker.addConnector("tcp://localhost:61616");
        broker.addConnector("stomp://localhost:61613");
        broker.start();
        // lets publish some messages so that there is some stuff to browse
        DefaultQueueSender.main(new String[] { "Prices.Equity.IBM" });
        DefaultQueueSender.main(new String[] { "Prices.Equity.MSFT" });
        // lets create a dummy couple of consumers
        if (createConsumers) {
            Connection connection = new ActiveMQConnectionFactory().createConnection();
            connection.start();
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            session.createConsumer(new ActiveMQQueue("Orders.IBM"));
            session.createConsumer(new ActiveMQQueue("Orders.MSFT"), "price > 100");
            Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            session2.createConsumer(new ActiveMQQueue("Orders.MSFT"), "price > 200");
        } else {
            // Lets wait for the broker
            broker.waitUntilStopped();
        }
    } catch (Exception e) {
        System.out.println("Failed: " + e);
        e.printStackTrace();
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Connection(javax.jms.Connection) ManagementContext(org.apache.activemq.broker.jmx.ManagementContext) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Session(javax.jms.Session)

Example 2 with ManagementContext

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

the class CheckDuplicateMessagesOnDuplexTest method createLocalBroker.

private void createLocalBroker() throws Exception {
    localBroker = new BrokerService();
    localBroker.setBrokerName("LOCAL");
    localBroker.setUseJmx(true);
    localBroker.setSchedulePeriodForDestinationPurge(5000);
    ManagementContext managementContext = new ManagementContext();
    managementContext.setCreateConnector(false);
    localBroker.setManagementContext(managementContext);
    PersistenceAdapter persistenceAdapter = persistenceAdapterFactory("target/local");
    localBroker.setPersistenceAdapter(persistenceAdapter);
    List<TransportConnector> transportConnectors = new ArrayList<>();
    DebugTransportFactory tf = new DebugTransportFactory();
    TransportServer transport = tf.doBind(URI.create("nio://127.0.0.1:23539"));
    TransportConnector transportConnector = new TransportConnector(transport);
    transportConnector.setName("tc");
    transportConnector.setAuditNetworkProducers(true);
    transportConnectors.add(transportConnector);
    localBroker.setTransportConnectors(transportConnectors);
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) ArrayList(java.util.ArrayList) ManagementContext(org.apache.activemq.broker.jmx.ManagementContext) TcpTransportServer(org.apache.activemq.transport.tcp.TcpTransportServer) TransportServer(org.apache.activemq.transport.TransportServer) BrokerService(org.apache.activemq.broker.BrokerService) LevelDBPersistenceAdapter(org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter)

Example 3 with ManagementContext

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

the class VerifyNetworkConsumersDisconnectTest method assertExactConsumersConnect.

protected void assertExactConsumersConnect(final String brokerName, final int count, final int numChecks, long timeout) throws Exception {
    final ManagementContext context = brokers.get(brokerName).broker.getManagementContext();
    final AtomicInteger stability = new AtomicInteger(0);
    assertTrue("Expected consumers count: " + count + " on: " + brokerName, Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            try {
                QueueViewMBean queueViewMBean = (QueueViewMBean) context.newProxyInstance(brokers.get(brokerName).broker.getAdminView().getQueues()[0], QueueViewMBean.class, false);
                long currentCount = queueViewMBean.getConsumerCount();
                LOG.info("On " + brokerName + " current consumer count for " + queueViewMBean + ", " + currentCount);
                LinkedList<String> consumerIds = new LinkedList<>();
                for (ObjectName objectName : queueViewMBean.getSubscriptions()) {
                    consumerIds.add(objectName.getKeyProperty("consumerId"));
                }
                LOG.info("Sub IDs: " + consumerIds);
                if (currentCount == count) {
                    stability.incrementAndGet();
                } else {
                    stability.set(0);
                }
                return stability.get() > numChecks;
            } catch (Exception e) {
                LOG.warn(": ", e);
                return false;
            }
        }
    }, timeout));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean) ManagementContext(org.apache.activemq.broker.jmx.ManagementContext) LinkedList(java.util.LinkedList) ObjectName(javax.management.ObjectName)

Example 4 with ManagementContext

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

the class BrokerNetworkWithStuckMessagesTest method browseQueueWithJmx.

private Object[] browseQueueWithJmx(BrokerService broker) throws Exception {
    Hashtable<String, String> params = new Hashtable<>();
    params.put("brokerName", broker.getBrokerName());
    params.put("type", "Broker");
    params.put("destinationType", "Queue");
    params.put("destinationName", queueName);
    ObjectName queueObjectName = ObjectName.getInstance(amqDomain, params);
    ManagementContext mgmtCtx = broker.getManagementContext();
    QueueViewMBean queueView = (QueueViewMBean) mgmtCtx.newProxyInstance(queueObjectName, QueueViewMBean.class, true);
    Object[] messages = queueView.browse();
    LOG.info("+Browsed with JMX: " + messages.length);
    return messages;
}
Also used : Hashtable(java.util.Hashtable) QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean) ManagementContext(org.apache.activemq.broker.jmx.ManagementContext) ObjectName(javax.management.ObjectName)

Example 5 with ManagementContext

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

the class CheckDuplicateMessagesOnDuplexTest method createRemoteBroker.

private void createRemoteBroker() throws Exception {
    remoteBroker = new BrokerService();
    remoteBroker.setBrokerName("REMOTE");
    remoteBroker.setUseJmx(true);
    remoteBroker.setSchedulePeriodForDestinationPurge(5000);
    ManagementContext managementContext = new ManagementContext();
    managementContext.setCreateConnector(false);
    remoteBroker.setManagementContext(managementContext);
    PersistenceAdapter persistenceAdapter = persistenceAdapterFactory("target/remote");
    remoteBroker.setPersistenceAdapter(persistenceAdapter);
    List<NetworkConnector> networkConnectors = new ArrayList<>();
    DiscoveryNetworkConnector networkConnector = new DiscoveryNetworkConnector();
    networkConnector.setName("to local");
    // set maxInactivityDuration to 0, otherwise the broker restarts while you are in the debugger
    networkConnector.setUri(URI.create("static://(tcp://127.0.0.1:23539?wireFormat.maxInactivityDuration=0)"));
    networkConnector.setDuplex(true);
    // networkConnector.setNetworkTTL(5);
    // networkConnector.setDynamicOnly(true);
    networkConnector.setAlwaysSyncSend(true);
    networkConnector.setDecreaseNetworkConsumerPriority(false);
    networkConnector.setPrefetchSize(1);
    networkConnector.setCheckDuplicateMessagesOnDuplex(true);
    networkConnectors.add(networkConnector);
    remoteBroker.setNetworkConnectors(networkConnectors);
}
Also used : ArrayList(java.util.ArrayList) ManagementContext(org.apache.activemq.broker.jmx.ManagementContext) BrokerService(org.apache.activemq.broker.BrokerService) LevelDBPersistenceAdapter(org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter)

Aggregations

ManagementContext (org.apache.activemq.broker.jmx.ManagementContext)7 BrokerService (org.apache.activemq.broker.BrokerService)4 ObjectName (javax.management.ObjectName)3 ArrayList (java.util.ArrayList)2 QueueViewMBean (org.apache.activemq.broker.jmx.QueueViewMBean)2 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)2 KahaDBPersistenceAdapter (org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)2 LevelDBPersistenceAdapter (org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter)2 Hashtable (java.util.Hashtable)1 LinkedList (java.util.LinkedList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Connection (javax.jms.Connection)1 Session (javax.jms.Session)1 ObjectInstance (javax.management.ObjectInstance)1 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)1 TransportConnector (org.apache.activemq.broker.TransportConnector)1 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)1 TransportServer (org.apache.activemq.transport.TransportServer)1 TcpTransportServer (org.apache.activemq.transport.tcp.TcpTransportServer)1 SocketProxy (org.apache.activemq.util.SocketProxy)1