org.apache.activemq.broker.jmx.ManagementContext Java Examples

The following examples show how to use org.apache.activemq.broker.jmx.ManagementContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BrokerNetworkWithStuckMessagesTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: CheckDuplicateMessagesOnDuplexTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: CheckDuplicateMessagesOnDuplexTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: EmbeddedActiveMQ.java    From james-project with Apache License 2.0 6 votes vote down vote up
private void launchEmbeddedBroker(FileSystem fileSystem) throws Exception {
    brokerService = new BrokerService();
    brokerService.setBrokerName(BROKER_NAME);
    brokerService.setUseJmx(false);
    brokerService.setPersistent(true);
    brokerService.setDataDirectoryFile(fileSystem.getFile(BROCKERS_LOCATION));
    brokerService.setUseShutdownHook(false);
    brokerService.setSchedulerSupport(false);
    brokerService.setBrokerId(BROKER_ID);
    String[] uris = {BROCKER_URI};
    brokerService.setTransportConnectorURIs(uris);
    ManagementContext managementContext = new ManagementContext();
    managementContext.setCreateConnector(false);
    brokerService.setManagementContext(managementContext);
    brokerService.setPersistenceAdapter(persistenceAdapter);
    BrokerPlugin[] brokerPlugins = {new StatisticsBrokerPlugin()};
    brokerService.setPlugins(brokerPlugins);
    String[] transportConnectorsURIs = {BROCKER_URI};
    brokerService.setTransportConnectorURIs(transportConnectorsURIs);
    brokerService.start();
    LOGGER.info("Started embedded activeMq");
}
 
Example #5
Source File: AdvisoryJmxTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected BrokerService createBroker() throws Exception {
   BrokerService answer = new BrokerService();
   answer.setPersistent(isPersistent());
   answer.addConnector(bindAddress);
   ManagementContext context = new ManagementContext();
   context.setConnectorPort(1199);
   answer.setManagementContext(context);
   return answer;
}
 
Example #6
Source File: VerifyNetworkConsumersDisconnectTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example #7
Source File: BrokerService.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public ManagementContext getManagementContext() {
   return null;
}
 
Example #8
Source File: BrokerService.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void setManagementContext(ManagementContext managementContext) {
}
 
Example #9
Source File: Main.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
/**
 * @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();
   }
}