221.11. MicrometerMessageHistoryFactory
このファクトリーでは、メトリクスを使用して、メッセージのルーティング中にメッセージ履歴のパフォーマンス統計情報をキャプチャーできます。これは、すべてのルートの各ノードに Micrometer Timer を使用することで機能します。このファクトリーは、以下の例のように Java および XML で使用できます。
				Java の場合は、以下のようにファクトリーを CamelContext に設定するだけです。
			
context.setMessageHistoryFactory(new MicrometerMessageHistoryFactory());
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"/>
  <!-- use camel-micrometer message history to gather metrics for all messages being routed -->
  <bean id="metricsMessageHistoryFactory" class="org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryFactory"/>ファクトリーでは、次のオプションがサポートされています。
| 名前 | デフォルト | 説明 | 
|---|---|---|
| prettyPrint | false | 統計情報を json 形式で出力する際に pretty print を使用するかどうか | 
| meterRegistry | 
								共有  | |
| durationUnit | TimeUnit.MILLISECONDS | 統計を json としてダンプするときに使用する期間の単位。 | 
実行時に、メトリクスは Java API または JMX からアクセスでき、JSON 出力としてデータを収集できます。
Java コードから、次のように CamelContext からサービスを取得できます。
MicrometerMessageHistoryService service = context.hasService(MicrometerMessageHistoryService.class); String json = service.dumpStatisticsAsJson();
MicrometerMessageHistoryService service = context.hasService(MicrometerMessageHistoryService.class);
String json = service.dumpStatisticsAsJson();
				JMX が CamelContext で有効になっている場合、MBean は type=services ツリーに name=MicrometerMessageHistory で登録されます。