NO-JIRA fix JMX examples

This commit is contained in:
Justin Bertram 2018-02-22 15:19:01 -06:00 committed by Michael Andre Pearce
parent 52470dcc82
commit 53bfb47b34
5 changed files with 28 additions and 14 deletions

View File

@ -84,7 +84,10 @@ under the License.
<goal>runClient</goal>
</goals>
<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>
</execution>
<execution>
@ -103,7 +106,7 @@ under the License.
<dependencies>
<dependency>
<groupId>org.apache.activemq.examples.broker</groupId>
<artifactId>jmx</artifactId>
<artifactId>jmx-ssl</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

View File

@ -1,12 +1,8 @@
# JMX Management Example
To run the example, simply type:
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
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.
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)
This example shows how to manage ActiveMQ Artemis using [JMX over SSL](http://www.oracle.com/technetwork/java/javase/tech/javamanagement-140525.html)
## 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.management.ObjectNameBuilder;
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.
*/
public class JMXExample {
public class JMXOverSSLExample {
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"};
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
MBeanServerConnection mbsc = connector.getMBeanServerConnection();
@ -95,7 +99,7 @@ public class JMXExample {
System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages");
// 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
System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages");
@ -113,6 +117,11 @@ public class JMXExample {
// operation, there is none to consume.
// The call will timeout after 5000ms and messageReceived will be null
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
if (messageReceived != null) {
throw new IllegalStateException("message should be null!");
}
System.out.println("Received message: " + messageReceived);
} finally {
// 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.management.ObjectNameBuilder;
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.
@ -95,7 +94,7 @@ public class JMXExample {
System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages");
// 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
System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages");
@ -113,6 +112,11 @@ public class JMXExample {
// operation, there is none to consume.
// The call will timeout after 5000ms and messageReceived will be null
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
if (messageReceived != null) {
throw new IllegalStateException("message should be null!");
}
System.out.println("Received message: " + messageReceived);
} finally {
// Step 20. Be sure to close the resources!

View File

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