-
1. Re: Creating Custom MBeans
eric.bender Oct 11, 2012 4:19 PM (in response to eric.bender)Deleted this post to sum up more in original post.
Edited by: eric.bender on Oct 11, 2012 8:18 PM
-
2. Re: Creating Custom MBeans
davsclaus Oct 13, 2012 5:32 AM (in response to eric.bender)If you use Spring annotations you can use the Spring mbean exporter to have the bean exported into JMX.
If you want Camel to detect and do this for you, when for example the bean is part of a Camel component or used in a Camel route as a processor / bean, then you need to implement the org.apache.camel.Service as Camel only enlist services in JMX out of the box.
But looking at your code it seems its pure Spring JMX so use the spring jmx exporter.
-
3. Re: Creating Custom MBeans
eric.bender Oct 15, 2012 3:51 PM (in response to davsclaus)Deleted this post as it is no longer relevant.
Edited by: eric.bender on Oct 15, 2012 7:50 PM
-
4. Re: Creating Custom MBeans
eric.bender Oct 15, 2012 3:50 PM (in response to davsclaus)Alright I made some progress. I added this to my beans xml
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false"> <property name="beans"> <map> <entry key="bean:name=messageCounter1" value-ref="messageCounter"></entry> </map> </property> </bean>
It now shows up under beans in JConsole, however it seems to not respect the spring annotations for the managed resource name, nor what methods and attributes to expose via JMX. It seems all methods are exposed even though only two have the spring annotations.
Any ideas as to how to get that to work better, and how to put it somewhere other than simply "beans" and locate it with the rest of the route specific entities?
-
5. Re: Creating Custom MBeans
davsclaus Oct 16, 2012 12:40 AM (in response to eric.bender)There may be a way to instruct Spring to auto detect the beans and enlist them in JMX. They have some <xxx-scan> tags you can insert in the Spring XML file. I am not sure if that applies to JMX as well.
I dont know why the @ annotations dont seem to work for you.
Though for @ManagedAttribute, then make sure its a bean getter/setter, or either one.
And for @ManagedOperation it can be any other method.
-
6. Re: Creating Custom MBeans
eric.bender Oct 16, 2012 3:51 PM (in response to davsclaus)Figured it out. To get the JMX exporter to pick up the annotations, you have to include the annotations attribute bean as a property of the exporter
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false"> <property name="assembler" ref="assembler"></property> <property name="autodetect" value="true"></property> </bean> <bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"></bean> <bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler"> <property name="attributeSource" ref="jmxAttributeSource"></property> </bean>
-
7. Re: Creating Custom MBeans
davsclaus Oct 17, 2012 5:17 AM (in response to eric.bender)Thanks for sharing your solution.
Its a lot of confusing XML though. Would be nice if there was a Spring XML namespace to make this simpler to use. Anyway it works