170.5. 独自の Camel コードでの JMX の使用
170.5.1. 独自の管理エンドポイントの登録 リンクのコピーリンクがクリップボードにコピーされました!
Camel 2.0
で利用できます。独自のエンドポイントを Spring で管理されるアノテーション @ManagedResource で分離し、Camel MBeanServer に登録でき、JMX を使用してカスタム MBean にアクセスできます。
Camel 2.1 では、エンドポイント以外のものを適用するようにこれを変更しましたが、インターフェース org.apache.camel.spi.ManagementAware も実装する必要があります。詳細は、こちらを参照してください。
たとえば、管理するオプションを定義する以下のカスタムエンドポイントがあります。
@ManagedResource(description = "Our custom managed endpoint")
public class CustomEndpoint extends MockEndpoint implements ManagementAware<CustomEndpoint> {
public CustomEndpoint(final String endpointUri, final Component component) {
super(endpointUri, component);
}
public Object getManagedObject(CustomEndpoint object) {
return this;
}
public boolean isSingleton() {
return true;
}
protected String createEndpointUri() {
return "custom";
}
@ManagedAttribute
public String getFoo() {
return "bar";
}
@ManagedAttribute
public String getEndpointUri() {
return super.getEndpointUri();
}
}
Camel 2.9 以降では、org.apache.camel.api.management パッケージの @ManagedResource、@ManagedAttribute、および @ManagedOperation を使用することが推奨されています。これにより、カスタムコードは Spring JAR に依存しなくなります。