This commit is contained in:
Michael Andre Pearce 2018-02-26 19:12:15 +00:00
commit 99b6a34251
5 changed files with 28 additions and 14 deletions

View File

@ -84,7 +84,10 @@ under the License.
<goal>runClient</goal> <goal>runClient</goal>
</goals> </goals>
<configuration> <configuration>
<clientClass>org.apache.activemq.artemis.jms.example.JMXExample</clientClass> <args>
<arg>${project.build.outputDirectory}/activemq/server0/</arg>
</args>
<clientClass>org.apache.activemq.artemis.jms.example.JMXOverSSLExample</clientClass>
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
@ -103,7 +106,7 @@ under the License.
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.activemq.examples.broker</groupId> <groupId>org.apache.activemq.examples.broker</groupId>
<artifactId>jmx</artifactId> <artifactId>jmx-ssl</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -1,12 +1,8 @@
# JMX Management Example # JMX Management Example
To run the example, simply type: To run the example, simply type **mvn verify** from this directory, or **mvn -PnoServer verify** if you want to start and create the broker manually.
mvn verify -Djavax.net.ssl.keyStore=target/server0/etc/activemq.example.keystore -Djavax.net.ssl.keyStorePassword=activemqexample -Djavax.net.ssl.trustStore=target/server0/etc/activemq.example.truststore -Djavax.net.ssl.trustStorePassword=activemqexample This example shows how to manage ActiveMQ Artemis using [JMX over SSL](http://www.oracle.com/technetwork/java/javase/tech/javamanagement-140525.html)
from this directory, or add **-PnoServer** if you want to start and create the broker manually.
This example shows how to manage ActiveMQ Artemis using [JMX using SSL](http://www.oracle.com/technetwork/java/javase/tech/javamanagement-140525.html)
## Example configuration ## Example configuration

View File

@ -37,12 +37,11 @@ import org.apache.activemq.artemis.api.core.RoutingType;
import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder; import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
import org.apache.activemq.artemis.api.core.management.QueueControl; import org.apache.activemq.artemis.api.core.management.QueueControl;
import org.apache.activemq.artemis.jms.client.ActiveMQTextMessage;
/** /**
* An example that shows how to manage ActiveMQ Artemis using JMX. * An example that shows how to manage ActiveMQ Artemis using JMX.
*/ */
public class JMXExample { public class JMXOverSSLExample {
private static final String JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi"; private static final String JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
@ -84,7 +83,12 @@ public class JMXExample {
String[] creds = {"guest", "guest"}; String[] creds = {"guest", "guest"};
env.put(JMXConnector.CREDENTIALS, creds); env.put(JMXConnector.CREDENTIALS, creds);
JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMXExample.JMX_URL), env); System.setProperty("javax.net.ssl.trustStore", args[0] + "activemq.example.truststore");
System.setProperty("javax.net.ssl.trustStorePassword", "activemqexample");
System.setProperty("javax.net.ssl.keyStore", args[0] + "activemq.example.keystore");
System.setProperty("javax.net.ssl.keyStorePassword", "activemqexample");
JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMXOverSSLExample.JMX_URL), env);
// Step 11. Retrieve the MBeanServerConnection // Step 11. Retrieve the MBeanServerConnection
MBeanServerConnection mbsc = connector.getMBeanServerConnection(); MBeanServerConnection mbsc = connector.getMBeanServerConnection();
@ -95,7 +99,7 @@ public class JMXExample {
System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages"); System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages");
// Step 14. Remove the message sent at step #8 // Step 14. Remove the message sent at step #8
System.out.println("message has been removed: " + queueControl.removeMessage(((ActiveMQTextMessage) message).getCoreMessage().getMessageID())); System.out.println("message has been removed: " + queueControl.removeMessages(null));
// Step 15. Display the number of messages in the queue // Step 15. Display the number of messages in the queue
System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages"); System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages");
@ -113,6 +117,11 @@ public class JMXExample {
// operation, there is none to consume. // operation, there is none to consume.
// The call will timeout after 5000ms and messageReceived will be null // The call will timeout after 5000ms and messageReceived will be null
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000); TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
if (messageReceived != null) {
throw new IllegalStateException("message should be null!");
}
System.out.println("Received message: " + messageReceived); System.out.println("Received message: " + messageReceived);
} finally { } finally {
// Step 20. Be sure to close the resources! // Step 20. Be sure to close the resources!

View File

@ -37,7 +37,6 @@ import org.apache.activemq.artemis.api.core.RoutingType;
import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder; import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
import org.apache.activemq.artemis.api.core.management.QueueControl; import org.apache.activemq.artemis.api.core.management.QueueControl;
import org.apache.activemq.artemis.jms.client.ActiveMQTextMessage;
/** /**
* An example that shows how to manage ActiveMQ Artemis using JMX. * An example that shows how to manage ActiveMQ Artemis using JMX.
@ -95,7 +94,7 @@ public class JMXExample {
System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages"); System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages");
// Step 14. Remove the message sent at step #8 // Step 14. Remove the message sent at step #8
System.out.println("message has been removed: " + queueControl.removeMessage(((ActiveMQTextMessage) message).getCoreMessage().getMessageID())); System.out.println("message has been removed: " + queueControl.removeMessages(null));
// Step 15. Display the number of messages in the queue // Step 15. Display the number of messages in the queue
System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages"); System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages");
@ -113,6 +112,11 @@ public class JMXExample {
// operation, there is none to consume. // operation, there is none to consume.
// The call will timeout after 5000ms and messageReceived will be null // The call will timeout after 5000ms and messageReceived will be null
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000); TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
if (messageReceived != null) {
throw new IllegalStateException("message should be null!");
}
System.out.println("Received message: " + messageReceived); System.out.println("Received message: " + messageReceived);
} finally { } finally {
// Step 20. Be sure to close the resources! // Step 20. Be sure to close the resources!

View File

@ -67,6 +67,7 @@ under the License.
<module>jms-context</module> <module>jms-context</module>
<module>jms-shared-consumer</module> <module>jms-shared-consumer</module>
<module>jmx</module> <module>jmx</module>
<module>jmx-ssl</module>
<module>large-message</module> <module>large-message</module>
<module>last-value-queue</module> <module>last-value-queue</module>
<module>management</module> <module>management</module>
@ -135,6 +136,7 @@ under the License.
<module>jms-context</module> <module>jms-context</module>
<module>jms-shared-consumer</module> <module>jms-shared-consumer</module>
<module>jmx</module> <module>jmx</module>
<module>jmx-ssl</module>
<module>large-message</module> <module>large-message</module>
<module>last-value-queue</module> <module>last-value-queue</module>
<module>management</module> <module>management</module>