Red Hat Training

A Red Hat training course is available for Red Hat Fuse

170.4.4. JMX NotificationListener を使用して Camel イベントをリッスンする方法

Camel 通知イベントは、発生する内容の粒度の細かい概要を提供します。コンテキストおよびエンドポイントからライフサイクルイベントが表示され、エンドポイントへ受信および送信されるエクスチェンジを確認することができます。

Camel 2.4 以降 では、カスタム JMX NotificationListener を使用して Camel イベントをリッスンすることができます。

最初に CamelContext を起動する前に JmxNotificationEventNotifier を設定する必要があります。

// Set up the JmxNotificationEventNotifier
notifier = new JmxNotificationEventNotifier();
notifier.setSource("MyCamel");
notifier.setIgnoreCamelContextEvents(true);
notifier.setIgnoreRouteEvents(true);
notifier.setIgnoreServiceEvents(true);

CamelContext context = new DefaultCamelContext(createRegistry());
context.getManagementStrategy().addEventNotifier(notifier);

2 番目に、イベントをリッスンするためにリスナーを登録することができます。

// register the NotificationListener
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=eventnotifiers,name=JmxEventNotifier");
MyNotificationListener listener = new MyNotificationListener();
context.getManagementStrategy().getManagementAgent().getMBeanServer().addNotificationListener(on,
    listener,
    new NotificationFilter() {
        private static final long serialVersionUID = 1L;

        public boolean isNotificationEnabled(Notification notification) {
            return notification.getSource().equals("MyCamel");
        }
    }, null);