Created
March 17, 2019 21:29
-
-
Save brunodutr/b074ec0f1aa9c84f57a348afdfa74afc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example.bdutra.it.jmx; | |
import static javax.management.MBeanServerInvocationHandler.newProxyInstance; | |
import java.io.IOException; | |
import javax.management.MBeanServerConnection; | |
import javax.management.MalformedObjectNameException; | |
import javax.management.ObjectName; | |
import javax.management.remote.JMXConnector; | |
import javax.management.remote.JMXConnectorFactory; | |
import javax.management.remote.JMXServiceURL; | |
import org.apache.activemq.artemis.api.core.management.QueueControl; | |
public class ServiceJMX { | |
private static final String URL_JMX = "service:jmx:remote+http://localhost:9990"; | |
private static final String OBJECT_NAME = "org.apache.activemq.artemis:brokerName=\"default\",module=JMS,name=\"%s\",serviceType=Queue,type=Broker"; | |
public static void waitQueue(String nomeFila) throws MalformedObjectNameException, IOException { | |
JMXServiceURL serviceURL = new JMXServiceURL(URL_JMX); | |
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null); | |
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection(); | |
String cannonicalName = String.format(OBJECT_NAME, nomeFila); | |
ObjectName objectName = new ObjectName(cannonicalName); | |
QueueControl queueControl = newProxyInstance(connection, objectName, QueueControl.class, false); | |
while(queueControl.getMessageCount() > 0); | |
jmxConnector.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment