1 2 Previous Next 16 Replies Latest reply on Aug 7, 2013 6:26 AM by vikingsteve

    (JMX) Simplest way to use a custom MBean in Fuse?

    vikingsteve

      I've written a custom MBean for my service running in JBoss Fuse Fabric 7.2.0.redhat-024

       

      Interface: com.mycompany.myservice.MyServiceMBean

      Implementation: com.mycompany.myservice.MyServiceMBeanImpl

       

      What is the simplest way for my MBean to be "discovered" by JBoss Fuse?

       

      I tried adding the following to my blueprint.xml, but it doesnt seem to work:

       

      <bean id="org.apache.cxf.management.InstrumentationManager" class="org.apache.cxf.management.jmx.InstrumentationManagerImpl">
          <property name="enabled" value="true" />
          <property name="bus" ref="cxf" />
          <property name="usePlatformMBeanServer" value="true" />
      </bean>

       

      I run JBoss Fuse Fabric with the profile that deploys my services, I fire up JConsole and I connect to the first Local Process named org.apache.karaf.man.Main (there are 2 of them).

       

      Yet I cant find my MBean - I'm expecting to see com.mycompany.myservice on the MBean tab, but it isn't there.

       

      In contrast, I can see all of my datasource jmx beans under com.mycompany.anotherservice.datasources. However the datasource MBeans were configured by setting jmxEnabled=true, so I am none the wiser about how to configure and expose my own MBean.

       

      Could someone please tell me what I need to do here?


      Thanks in advance

      Steve.

        • 1. Re: (JMX) Simplest way to use a custom MBean in Fuse?
          ffang

          Hi,

           

          You don't need explicitly have InstrumentationManagerImpl definition in blueprint.xml, as it would be enabled automatically when it detect there is a MBeanServer OSGi service.

           

          What you can do is get InstrumentationManager from the bus and register your customer mbean directly on it, some code like

           

                  InstrumentationManager imanager = bus.getExtension(InstrumentationManager.class);

           

                  final MyServiceMBeanImpl mbImpl = new MyServiceMBeanImpl();

                  final ObjectName oName = new ObjectName("org.apache.cxf:type=foo,name=bar");// what ever ObjectName works for you

                  imanager.register(mbImpl, oName);

           

          Freeman

          • 2. Re: (JMX) Simplest way to use a custom MBean in Fuse?
            vikingsteve

            Hi Freeman, thanks for your answer.

             

            Firstly, a bus? Sorry, I haven't configured or used a bus before. Can you please elaborate. Is BusFactory.getDefaultBus() ok ?

             

            Secondly, can I somehow register my MBean in blueprint.xml (I would prefer to do it there, rather than in code) - is that possible?

             

            Thanks again,

            Steve.

            • 3. Re: (JMX) Simplest way to use a custom MBean in Fuse?
              ffang

              Hi,

               

              No, you can't resigster your customer MBean all through code.

              However, you can inject cxf bus into your MBeanImpl and register there.

              Some configuration like

               

              <bean id ="myMbeanImpl" class="com.mycompany.myservice.MyServiceMBeanImpl>

                      <property name="bus" ref="cxf" />

                  </bean>

               

              This can simply inject a bus into your customer MBean which you can use to register your MBean.

               

              Freeman

              • 4. Re: (JMX) Simplest way to use a custom MBean in Fuse?
                vikingsteve

                Hi Freeman,

                 

                Does my bean for "cxf" bus already exist, or do I need to define it somehow?

                 

                Since bus.getExtension(InstrumentationManager.class) is returning null.

                 

                I set a breakpoint and I can see the bus has state RUNNING and has 31 extensions... just not the InstrumentationManager.

                 

                Cheers, Steve

                • 5. Re: (JMX) Simplest way to use a custom MBean in Fuse?
                  ffang

                  Hi,

                   

                  You needn't define "cxf" bus bean, you can use it directly.

                   

                  I just test it and I can get the InstrumentationManager from bus.

                   

                  Post your blueprint.xml here so that I can take  a close look.

                   

                  Ensure you are usig JBoss FUSE 6 and didn't change any default configuration and so there's a javax.management.MBeanServer OSGi service available.

                   

                  And I will attachment my test tar FYI, I just revise a bit from the secure-soap example shipped with JBoss Fuse kit, you can see how to get InstrumentationManager from the bus.

                   

                   

                  Freeman

                   

                   

                   

                  • 6. Re: (JMX) Simplest way to use a custom MBean in Fuse?
                    vikingsteve

                    Hi,

                     

                    I'm using JBoss Fuse 6.0.0.redhat-024.

                     

                    It just occurred to me that perhaps I shouldn't be trying to register my MBean in the constructor of myServiceMBeanRegistration?

                     

                    Is this ok, or should I set "cxf" and "myServiceBean" as properties, and trigger the registration via some sort of "PostConstruct" (if so, how?)

                     

                    <bean id="myServiceMBean" class="com.mycompany.myservice.jmx.MyServiceMBeanImpl">
                        <property name="abcService" ref="abcService"/>
                    </bean>

                     

                    <bean id="myServiceMBeanRegistration" class="com.mycompany.myservice.jmx.MyServiceMBeanRegistration">
                        <argument ref="cxf" />
                        <argument ref="myServiceMBean" />
                    </bean>

                     

                    Otherwise if this looks ok, I can anonymize the class names and post my full blueprint.xml

                     

                    Cheers, Steve

                    • 7. Re: (JMX) Simplest way to use a custom MBean in Fuse?
                      ffang

                      Yes, you can register your mbean whereever you want, I just show you the way how you can inject cxf bus.

                      • 8. Re: (JMX) Simplest way to use a custom MBean in Fuse?
                        vikingsteve

                        Hi Freeman, here it is:

                         

                        <?xml version="1.0" encoding="UTF-8"?>

                        <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"

                                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                                   xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"

                                   xmlns:camel="http://camel.apache.org/schema/blueprint"

                                   xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"

                                   xmlns:http="http://cxf.apache.org/transports/http/configuration"

                                   xsi:schemaLocation="http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd

                                   http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd

                                   http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd

                                   http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

                         

                            <cm:property-placeholder id="cmProps" persistent-id="com.mycompany.myservice">

                                <cm:default-properties>

                                    <cm:property name="a.b.c.1" value=""/>

                                    <cm:property name="a.b.c.2" value=""/>

                                </cm:default-properties>

                            </cm:property-placeholder>

                         

                            <!-- for quartz scheduler -->

                            <bean class="org.fusesource.fabric.camel.MasterComponent" />

                         

                            <camel:camelContext id="MyServiceCamelContext">

                                <camel:propertyPlaceholder id="properties" location="blueprint:cmProps"/>

                                <camel:routeBuilder ref="MyServiceRoute"/>

                            </camel:camelContext>

                         

                            <!-- ws client -->

                         

                            <jaxws:client id="a" address="${b}" wsdlLocation="${c}" serviceName="s:d" serviceClass="e" xmlns:s="f" />

                         

                            <http:conduit name="{a}b">

                                <http:client AllowChunking="false" ProxyServer="proxy" ProxyServerPort="80" NonProxyHosts="localhost|127.0.0.1"/>

                            </http:conduit>

                         

                            <!-- a bunch of datasources, beans and services go here-->

                            <!-- a bunch of datasources, beans and services go here-->

                            <!-- a bunch of datasources, beans and services go here-->

                         

                            <!-- jmx -->

                         

                            <bean id="myServiceMBean" class="com.mycompany.myservice.jmx.MyServiceMBeanImpl">

                                <property name="abcService" ref="abcService"/>

                            </bean>

                         

                            <bean id="myServiceMBeanRegistration" class="com.mycompany.myservice.jmx.MyServiceMBeanRegistration">

                                <argument ref="cxf" />

                                <argument ref="myServiceMBean" />

                            </bean>

                         

                            <!-- routes -->

                         

                            <bean id="MyServiceRoute" class="com.mycompany.myservice.routes.MyServiceRoute"/>

                         

                        </blueprint>

                         

                        Wondering also if I need some special dependency?

                        • 9. Re: (JMX) Simplest way to use a custom MBean in Fuse?
                          ffang

                          Hi,

                          So from this configuration

                          bus.getExtension(InstrumentationManager.class) is returning null, right?

                           

                          I don't see any special reason why it could be null.

                          Anyway,  try add a bus property for com.mycompany.myservice.jmx.MyServiceMBeanRegistration and using

                          <property name="bus" ref="cxf" />

                          to see if it helps,

                           

                          and also ensure this bundle have Import-Package like

                           

                          org.apache.cxf.management

                           

                          Also please post result of

                           

                          ls|grep -B 5 MBeanServer

                          and

                          cxf:list-busses

                           

                          from console.

                           

                          You can also add code like

                          System.out.println("the bus is " + bus.getId());

                          to see if the bus Id get injected match the one used for your customer bundle.

                           

                           

                          Freeman

                          • 10. Re: (JMX) Simplest way to use a custom MBean in Fuse?
                            vikingsteve

                            Hi,

                             

                            Right, bus.getExtension(InstrumentationManager.class) is returning null.

                             

                            Regarding using <property name="bus" ref="cxf" /> for my registration bean, this uses the bus setter method, so if I have a method named doRegistration, how and when do I trigger it? Normally in spring I would have used @PostConstruct for something like this. [edit: I found the answer: init-method="doRegistration", works great!]

                             

                            I added the Import-Pacakge.

                             

                            admin@server1> ls|grep -B 5 MBeanServer

                             

                            Apache Karaf :: Management (18) provides:

                            -----------------------------------------

                            org.osgi.service.blueprint.container.BlueprintContainer

                            org.osgi.service.cm.ManagedService

                            javax.management.MBeanServer

                             

                            admin@server1> cxf:list-busses

                            Name                                     State

                            [com.mycompany.someservice-webservice-cxf972689576] [RUNNING           ]

                            [com.mycompany.myservice-service-cxf1868655190] [RUNNING           ] ***

                            [com.mycompany.coolservice.coolservice-xyzclient-cxf478040164] [RUNNING           ]

                             

                            *** the bus id with 3 stars was printed by the log statement "the bus is" + bus.getId()

                             

                            I'm running a fabric with relevant profile and one container, server1.

                             

                            Cheers

                            Steve

                            • 11. Re: (JMX) Simplest way to use a custom MBean in Fuse?
                              ffang

                              Hi,

                               

                              It looks good to me.

                              Could you please append a testcase which I can build and deploy, so that I can take a close look why bus.getExtension(InstrumentationManager.class) return null for your case.

                               

                               

                              Freeman

                              • 12. Re: (JMX) Simplest way to use a custom MBean in Fuse?
                                vikingsteve

                                Thanks, I uploaded a simple test case, to build it: mvn clean install

                                 

                                To run it:

                                 

                                features:addurl mvn:com.foo.myservice/myservice-feature/1.0.0-SNAPSHOT/xml/features

                                features:install foo-myservice

                                list | grep -i foo

                                 

                                In the logs I was seeing:

                                    Error: org.osgi.service.blueprint.container.ComponentDefinitionException: Unresolved ref/idref to component: cxf

                                 

                                What is missing to make the cxf bus available here?

                                • 13. Re: (JMX) Simplest way to use a custom MBean in Fuse?
                                  ffang

                                  Hi,

                                   

                                  In your testcase, there's no CXF endpoint defined in the blueprint.xml, so the cxf bus bean can't be auto wire-in.

                                   

                                  Also if there's no CXF related endpoint, you shouldn't use CXF InstrumentationManagerImpl to register your customer MBean.

                                   

                                  Previously I thought you're  going to use CXF endpoint as the service.

                                   

                                  Freeman

                                   

                                   

                                  • 14. Re: (JMX) Simplest way to use a custom MBean in Fuse?
                                    vikingsteve

                                    Hi Freeman,

                                     

                                    That's correct, this service does not define a <cxf:cxfEndpoint ... /> to expose a WS.

                                     

                                    It does however use a WS client defined by <jaxws:client ... /> and <http:conduit ... /> to talk to an external WS.

                                     

                                    Given my situation, how do I register my MBean?

                                     

                                    Thank you again,
                                    Steve

                                    1 2 Previous Next