qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrea Gazzarini <a.gazzar...@gmail.com>
Subject Re: Measuring message rates
Date Thu, 26 Feb 2009 10:53:25 GMT
Depending on how the monitoring needs to be done, you have two ways :
- visually : as Carl told you, it's possible to use the JConsole shipped
with JDK 1.5 or higher. After selected the desired MBean, simply
double-click on the attribute; the console will start automatically a
monitor on that attribute.

- programmatically : here there are few lines of code that need to be
written. Basically,

1) you must connect to QMan MBean server using JMX procedures;
2) Create one listener + one filter and attach them to QMan MBean. Qman will
notify the listener when a new connection (in the example below)

public class Example
{
static MBeanServer mbeanServer;
        // This is listening for attribute changes
static class ConnectionAttributeListener implements NotificationListener,
Serializable
{
public void handleNotification(Notification notification,Object handback)
{
// each time we are here means the monitor sent a notification because the
// attribute value has changed (according to monitor rules).
}
}
        // This listener is notified each time a new connection is created.
static class ConnectionLifeCycleListener implements
NotificationListener,Serializable
{

public void handleNotification(Notification notification,Object handback)
{
// A NEW CONNECTION HAS BEEN CREATED!
 try
{
// Creates & Initializes the monitor
ObjectName monitorName = new
ObjectName("YourApp:Name=ConnectionWatcher,Type=Monitor");
mbeanServer.createMBean("javax.management.monitor.GaugeMonitor",
monitorName);
 ...
...
...
 // ...and attaches a listener
mbeanServer.addNotificationListener(
monitorName,
new ConnectionAttributeListener(),
null,
null);
 } catch(Exception exception)
{
 }
}
}
        // This is used for filtering notification (we wants to receive a
notification only when a connection is created).
static class ConnectionFilter implements NotificationFilter
{
public boolean isNotificationEnabled(Notification notification)
{
return
EntityLifecycleNotification.INSTANCE_ADDED_NOTIFICATION_TYPE.equals(notification.getType())
&&
("connection".equals(((EntityLifecycleNotification)notification).getClassName()));
}
}
 public static void main(String[] args) throws Exception
{
// QMan Object Name
ObjectName qman = new ObjectName("Q-MAN:Name=QMan,Type=Service");
 // Reference to MBean server where QMan is running...
mbeanServer = null; //...
 // Register your connection listener
mbeanServer.addNotificationListener(
qman,
new ConnectionLifeCycleListener(),
new ConnectionFilter(),
null);
}
}

Regards,
Andrea

2009/2/24 Carl Trieloff <cctrieloff@redhat.com>

> GS.Chandra N wrote:
>
>> Hey Andrea. Thanks for the reply.
>>
>> I will definitely check them out. Does QMAN have any UI to go along with
>> it
>> too?
>>
>> Thanks
>>
> you can connect to it using any JMX console, details are on the wiki
> http://qpid.apache.org/qman-qpid-management-bridge.html
>
>
> Carl.
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project:      http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message