180.5. 使用 JMX 监控 Camel


180.5.1. 使用 JConsole 监控 Camel

如果您在与 Camel 相同的主机上运行 JConsole,则 CamelContext 应该出现在本地连接列表中。

要连接到远程 Camel 实例,或者本地进程没有显示,请使用 Remote Process 选项,并输入 URL。以下是一个 localhost URL:service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi/camel.

使用带有 JConsole 的 Apache Camel:

image

180.5.2. 哪些端点被注册

Camel 2.1 中,只有 单例 端点被注册,因为在使用数千个或数百万端点的情况下,非单例的开销将具有大量。当使用 Recipient List EIP 或来自发送大量消息的 ProducerTemplate 时会出现这种情况。

180.5.3. 哪些处理器被注册

请参阅此常见问题解答。

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);
Copy to Clipboard Toggle word wrap

其次,您可以注册侦听器以侦听该事件:

// 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);
Copy to Clipboard Toggle word wrap

180.5.5. 使用 Tracer MBean 获取精细的追踪

此外,对于 Camel 2.9.0 上面的粗粒度通知,还支持 JMX 通知用于精细的追踪事件。

它们可以在 Tracer MBean 中找到。要激活精细的追踪,您首先需要在上下文或路由上激活追踪。

这可以在配置上下文时或上下文 / route MBeans 来完成。

作为第二个步骤,您必须在 tracer 上将 jmxTraceNotifications 属性设置为 true。在配置上下文或运行时在 tracer MBean 时可以再次完成此操作。

现在,您可以使用 JConsole 在 Tracer MBean 上注册 TraceEvent 通知。路由中都会有一个通知,其中包含所有交换和消息详情:

image

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat