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();
}
}
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);
}
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));
}
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;
}
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);
}
Aggregations