Thanks.  For the code that I included with my email, it didn't even get
that far.  The ManagementAgent was null.  I switched my test over to extend
CamelTestSupport, and I removed @CamelSpringTest, and now I can get the
MBeanServer.  I can list all of the beans by doing this:

MBeanServer mBeanServer =
context.getManagementStrategy().getManagementAgent().getMBeanServer();
String names = mBeanServer.queryNames(null, null).stream()
        .map(ObjectName::getCanonicalName)
        .filter(name -> name.contains("ynamic"))
        .collect(Collectors.joining("\n"));
System.err.println("MBean names:\n" + names);

The result is this:

MBean names:
org.apache.camel:context=camel-1,name="dynamic-router-control",type=components
org.apache.camel:context=camel-1,name="dynamic-router",type=components
org.apache.camel:context=camel-1,name="dynamic-router-control://subscribe",type=endpoints
org.apache.camel:context=camel-1,name=DynamicRouterProducer(0x511505e7),type=producers
org.apache.camel:context=camel-1,name=DynamicRouterControlProducer(0x70abf9b0),type=producers
org.apache.camel:context=camel-1,name="dynamic-router://test",type=endpoints

But I don't see the two classes that I have annotated with @ManagedResource
(that also include @ManagedOperation and @ManagedAttribute) that extend
ServiceSupport.  There's something here that I am missing, but I have
indeed looked at a lot of code in the camel components directory and as
much documentation as I could find.

On Tue, Jan 2, 2024 at 4:00 PM Claus Ibsen <claus.ib...@gmail.com> wrote:

> Hi
>
> The mbean name you create is for a route, so it's a RouteMBean.
>
> You can use jconsole to look inside the running Camel test and see what
> mbeans there are etc.
> You can just add a thread sleep (long value) to keep the jvm running.
>
> Then find the right mbean you want to get and update your test code.
>
> Also take a look at the existing tests in camel-management etc.
>
>
>
>
>
> On Tue, Jan 2, 2024 at 6:53 PM Steve973 <steve...@gmail.com> wrote:
>
> > Hi, Claus.  Yes, I have included camel-management as a test-scoped
> > dependency.
> >
> > On Tue, Jan 2, 2024 at 12:24 AM Claus Ibsen <claus.ib...@gmail.com>
> wrote:
> >
> > > Hi
> > >
> > > Have you added camel-management as a dependency.
> > >
> > > On Tue, Jan 2, 2024 at 2:15 AM Steve973 <steve...@gmail.com> wrote:
> > >
> > > > Hello.  I have a CamelSpringBootTest, and I am trying to test that my
> > > > mbeans have been registered.  This is how I am trying to check:
> > > >
> > > > @CamelSpringTest
> > > > @ContextConfiguration
> > > > @DirtiesContext(classMode =
> > > > DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
> > > > class DynamicRouterJmxIT {
> > > >
> > > >     @Autowired
> > > >     CamelContext camelContext;
> > > >
> > > >     @Test
> > > >     void testExpectedMbeansExist() throws
> MalformedObjectNameException
> > {
> > > >         Assertions.assertTrue(camelContext.isStarted());
> > > >         MBeanServer mBeanServer =
> > > >
> > >
> >
> camelContext.getManagementStrategy().getManagementAgent().getMBeanServer();
> > > >         ObjectName name = new
> > > >
> > > >
> > >
> >
> ObjectName("org.apache.camel:context=camelContext,type=routes,name=\"testRoute\"");
> > > >         DynamicRouterControlService controlMbean =
> > > > JMX.newMBeanProxy(mBeanServer, name,
> > > > DynamicRouterControlService.class);
> > > >         DynamicRouterFilterService filterMbean =
> > > > JMX.newMBeanProxy(mBeanServer, name,
> > > > DynamicRouterFilterService.class);
> > > >         Assertions.assertNotNull(controlMbean);
> > > >         Assertions.assertNotNull(filterMbean);
> > > >     }
> > > > }
> > > >
> > > > Here is the XML that I am using for it, called
> > > > DynamicRouterJmxIT-context.xml:
> > > >
> > > > <beans xmlns="http://www.springframework.org/schema/beans";
> > > >        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> > > >        xsi:schemaLocation="
> > > >        http://www.springframework.org/schema/beans
> > > > http://www.springframework.org/schema/beans/spring-beans.xsd
> > > >        http://camel.apache.org/schema/spring
> > > > http://camel.apache.org/schema/spring/camel-spring.xsd";>
> > > >
> > > >   <camelContext id="camelContext" xmlns="
> > > > http://camel.apache.org/schema/spring";>
> > > >     <!-- enable JMX -->
> > > >     <jmxAgent id="agent" disabled="false"/>
> > > >     <route>
> > > >       <from uri="direct:start" id="testRoute"/>
> > > >       <to uri="dynamic-router:test"/>
> > > >     </route>
> > > >     <route>
> > > >       <from uri="direct:subscribe-no-url-predicate"/>
> > > >       <toD uri="dynamic-router-control:subscribe
> > > >                       ?subscribeChannel=${headers.subscribeChannel}
> > > >                       &amp;subscriptionId=${headers.subscriptionId}
> > > >                       &amp;destinationUri=${headers.destinationUri}
> > > >                       &amp;priority=${headers.priority}"/>
> > > >     </route>
> > > >   </camelContext>
> > > > </beans>
> > > >
> > > >
> > > > I keep getting this error:
> > > >
> > > > Cannot invoke "org.apache.camel.spi.ManagementAgent.getMBeanServer()"
> > > > because the return value of
> > > > "org.apache.camel.spi.ManagementStrategy.getManagementAgent()" is
> null
> > > >
> > > > What am I doing wrong?
> > > >
> > > > Thanks,
> > > > Steve
> > > >
> > >
> > >
> > > --
> > > Claus Ibsen
> > > -----------------
> > > @davsclaus
> > > Camel in Action 2: https://www.manning.com/ibsen2
> > >
> >
>
>
> --
> Claus Ibsen
> -----------------
> @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>

Reply via email to