Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 948
AccessingJMX
Douglas Campos edited this page Jan 24, 2011
·
1 revision
This page shows an example of using the Java JMX packages directly from Ruby, but there are two gems which exist to make using JMX must less painful. Consider using these packages before you break down and code this stuff by hand:
This code snippet shows how to access ActiveMQ's Dead Letter Queue (DLQ):
require'java'importjava.rmi.MarshalledObjectimportjava.rmi.registry.LocateRegistryimportjavax.management.ObjectName# Connect to the JNDI lookup serverregistry=LocateRegistry.get_registry("localhost",1099)# List available RMI objectsnames=registry.listputs'Available RMI objects:'pnames.to_aputs# Fetch a remote proxy to the JMX RMI objectremote=registry.lookup("jmxrmi")puts"Got remote JMX object: #{remote.inspect}"con=remote.new_clientnilputs"Got connection: #{con.inspect}"# List JMX domainsdomains=con.get_domainsnilputs"Found domains:"pdomains.to_a# List available MBeansmbeans=con.query_namesnil,nil,nilputs'Available MBeans:'mbean_names=mbeans.to_a.map{|n| n.to_s}.sortputsmbean_names.join("\n")putsputs# Find the dead letter queue in ActiveMQ queue=mbean_names.find{|n| n =~ /org.apache.activemq.*Type=Queue.*Destination=ActiveMQ.DLQ/}ifqueueputs'Found ActiveMQ DLQ:'pqueueputs"Purging DLQ"name=ObjectName.new(queue)res=con.invokename,'purge',MarshalledObject.new(nil),nil,nilputs"Result from purge: #{res.inspect}"end