220.11. MicrometerMessageHistoryFactory

此工厂允许使用指标在路由消息期间捕获消息历史性能统计数据。它的工作原理是在所有路由中的每个节点使用 Micrometer Timer。 此工厂可以在 Java 和 XML 中使用,作为以下示例。 

从 Java 中,您要将工厂设置为 CamelContext ,如下所示:

context.setMessageHistoryFactory(new MicrometerMessageHistoryFactory());

在 XML DSL 中,您将定义 <bean>,如下所示:

  <!-- use camel-micrometer message history to gather metrics for all messages being routed -->
  <bean id="metricsMessageHistoryFactory" class="org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryFactory"/>

因工厂支持以下选项:

名称default描述

prettyPrint

false

是否在以 json 格式输出统计信息时打印情况

meterRegistry

 

允许使用共享的 MeterRegistry。如果没有提供,Camel 将创建此 CamelContext 使用的共享实例。

durationUnit

TimeUnit.MILLISECONDS

将统计作为 json 转储时,使用的单位是持续时间。

在运行时,指标可以从 Java API 或 JMX 访问,后者可以将数据作为 json 输出来收集。

在 Java 代码中,您可以从 CamelContext 获取服务,如下所示:

MicrometerMessageHistoryService service = context.hasService(MicrometerMessageHistoryService.class);
String json = service.dumpStatisticsAsJson();

如果在 CamelContext 中启用了 JMX,则 MBean 会在 type=services 树中注册, 名称为=MicrometerMessageHistory