You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Bratislav Stojanovic <br...@gmail.com> on 2013/10/24 13:11:21 UTC

Add network connector dynamically over JMX

Hi all,

Does anybody know how to do this? Here's the code I've tried, but it
doesn't work :

JMXServiceURL url = new
JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root");
 Map env = new HashMap();
String[] creds = {"...", "..."};
env.put(JMXConnector.CREDENTIALS, creds);
    JMXConnector jmxc = JMXConnectorFactory.connect(url, env);

    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

    // Get domains from MBeanServer
    System.out.println("\nDomains:");
        String domains[] = mbsc.getDomains();
        Arrays.sort(domains);
        for (String domain : domains) {
        System.out.println("\tDomain = " + domain);
        }

    // Get MBeanServer's default domain
        System.out.println("\nMBeanServer default domain = " +
mbsc.getDefaultDomain());

        // Get MBean count
        //
        System.out.println("\nMBean count = " + mbsc.getMBeanCount());

        // Query MBean names
        //
        System.out.println("\nQuery MBeanServer MBeans:");
        Set<ObjectName> names =
            new TreeSet<ObjectName>(mbsc.queryNames(null, null));
        for (ObjectName name : names) {
        System.out.println("\tObjectName = " + name);
        }


        // find mbean
        ObjectName mbeanName = null;
        for (ObjectName name : names) {
        if
(name.toString().equals("org.apache.activemq:type=Broker,brokerName=broker"))
{
        mbeanName = name;
        }
        }

        if (mbeanName == null) {
        System.err.println("No mbean found");
        return;
        }

        BrokerViewMBean mbeanProxy =JMX.newMBeanProxy(mbsc, mbeanName,
BrokerViewMBean.class, true);


System.out.println(mbeanProxy.addNetworkConnector("static:failover:(tcp://localhost:61617)"));

        ObjectName mbeanName2 = new
ObjectName("org.apache.activemq:type=Broker,brokerName=broker,connector=networkConnectors,connectorName=NC");
        NetworkConnectorViewMBean mbeanProxy2 =JMX.newMBeanProxy(mbsc,
mbeanName2, NetworkConnectorViewMBean.class, true);

        mbeanProxy2.start();  // start NC
        jmxc.close();

It will fail on the second proxy with the message :

Exception in thread "main" javax.management.InstanceNotFoundException:
org.apache.activemq:type=Broker,brokerName=broker,connector=networkConnectors,connectorName=NC

I'm using activemq 5.9.0 running inside karaf 2.3.3.

Please help!

-- 
Bratislav Stojanovic, M.Sc.

Re: Add network connector dynamically over JMX

Posted by Bratislav Stojanovic <br...@gmail.com>.
Awesome, thank you Chris!


On Thu, Oct 24, 2013 at 7:41 PM, Christian Posta
<ch...@gmail.com>wrote:

> I've opened the issue here: https://issues.apache.org/jira/browse/AMQ-4823and
> fixed it on origin/trunk.
>
>
>
>
> On Thu, Oct 24, 2013 at 9:30 AM, Christian Posta
> <ch...@gmail.com>wrote:
>
> > Yah, seems like the mbeans aren't registered properly when creating
> > through JMX.
> >
> > The bridge does get created, but it's not visible in jconsole.
> >
> > Can you create a JIRA for this?
> >
> >
> > On Thu, Oct 24, 2013 at 4:11 AM, Bratislav Stojanovic <
> > bratislav1983@gmail.com> wrote:
> >
> >> Hi all,
> >>
> >> Does anybody know how to do this? Here's the code I've tried, but it
> >> doesn't work :
> >>
> >> JMXServiceURL url = new
> >>
> JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root");
> >>  Map env = new HashMap();
> >> String[] creds = {"...", "..."};
> >> env.put(JMXConnector.CREDENTIALS, creds);
> >>     JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
> >>
> >>     MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
> >>
> >>     // Get domains from MBeanServer
> >>     System.out.println("\nDomains:");
> >>         String domains[] = mbsc.getDomains();
> >>         Arrays.sort(domains);
> >>         for (String domain : domains) {
> >>         System.out.println("\tDomain = " + domain);
> >>         }
> >>
> >>     // Get MBeanServer's default domain
> >>         System.out.println("\nMBeanServer default domain = " +
> >> mbsc.getDefaultDomain());
> >>
> >>         // Get MBean count
> >>         //
> >>         System.out.println("\nMBean count = " + mbsc.getMBeanCount());
> >>
> >>         // Query MBean names
> >>         //
> >>         System.out.println("\nQuery MBeanServer MBeans:");
> >>         Set<ObjectName> names =
> >>             new TreeSet<ObjectName>(mbsc.queryNames(null, null));
> >>         for (ObjectName name : names) {
> >>         System.out.println("\tObjectName = " + name);
> >>         }
> >>
> >>
> >>         // find mbean
> >>         ObjectName mbeanName = null;
> >>         for (ObjectName name : names) {
> >>         if
> >>
> >>
> (name.toString().equals("org.apache.activemq:type=Broker,brokerName=broker"))
> >> {
> >>         mbeanName = name;
> >>         }
> >>         }
> >>
> >>         if (mbeanName == null) {
> >>         System.err.println("No mbean found");
> >>         return;
> >>         }
> >>
> >>         BrokerViewMBean mbeanProxy =JMX.newMBeanProxy(mbsc, mbeanName,
> >> BrokerViewMBean.class, true);
> >>
> >>
> >>
> >>
> System.out.println(mbeanProxy.addNetworkConnector("static:failover:(tcp://localhost:61617)"));
> >>
> >>         ObjectName mbeanName2 = new
> >>
> >>
> ObjectName("org.apache.activemq:type=Broker,brokerName=broker,connector=networkConnectors,connectorName=NC");
> >>         NetworkConnectorViewMBean mbeanProxy2 =JMX.newMBeanProxy(mbsc,
> >> mbeanName2, NetworkConnectorViewMBean.class, true);
> >>
> >>         mbeanProxy2.start();  // start NC
> >>         jmxc.close();
> >>
> >> It will fail on the second proxy with the message :
> >>
> >> Exception in thread "main" javax.management.InstanceNotFoundException:
> >>
> >>
> org.apache.activemq:type=Broker,brokerName=broker,connector=networkConnectors,connectorName=NC
> >>
> >> I'm using activemq 5.9.0 running inside karaf 2.3.3.
> >>
> >> Please help!
> >>
> >> --
> >> Bratislav Stojanovic, M.Sc.
> >>
> >
> >
> >
> > --
> > *Christian Posta*
> > http://www.christianposta.com/blog
> > twitter: @christianposta
> >
>
>
>
> --
> *Christian Posta*
> http://www.christianposta.com/blog
> twitter: @christianposta
>



-- 
Bratislav Stojanovic, M.Sc.

Re: Add network connector dynamically over JMX

Posted by Christian Posta <ch...@gmail.com>.
I've opened the issue here: https://issues.apache.org/jira/browse/AMQ-4823 and
fixed it on origin/trunk.




On Thu, Oct 24, 2013 at 9:30 AM, Christian Posta
<ch...@gmail.com>wrote:

> Yah, seems like the mbeans aren't registered properly when creating
> through JMX.
>
> The bridge does get created, but it's not visible in jconsole.
>
> Can you create a JIRA for this?
>
>
> On Thu, Oct 24, 2013 at 4:11 AM, Bratislav Stojanovic <
> bratislav1983@gmail.com> wrote:
>
>> Hi all,
>>
>> Does anybody know how to do this? Here's the code I've tried, but it
>> doesn't work :
>>
>> JMXServiceURL url = new
>> JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root");
>>  Map env = new HashMap();
>> String[] creds = {"...", "..."};
>> env.put(JMXConnector.CREDENTIALS, creds);
>>     JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
>>
>>     MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
>>
>>     // Get domains from MBeanServer
>>     System.out.println("\nDomains:");
>>         String domains[] = mbsc.getDomains();
>>         Arrays.sort(domains);
>>         for (String domain : domains) {
>>         System.out.println("\tDomain = " + domain);
>>         }
>>
>>     // Get MBeanServer's default domain
>>         System.out.println("\nMBeanServer default domain = " +
>> mbsc.getDefaultDomain());
>>
>>         // Get MBean count
>>         //
>>         System.out.println("\nMBean count = " + mbsc.getMBeanCount());
>>
>>         // Query MBean names
>>         //
>>         System.out.println("\nQuery MBeanServer MBeans:");
>>         Set<ObjectName> names =
>>             new TreeSet<ObjectName>(mbsc.queryNames(null, null));
>>         for (ObjectName name : names) {
>>         System.out.println("\tObjectName = " + name);
>>         }
>>
>>
>>         // find mbean
>>         ObjectName mbeanName = null;
>>         for (ObjectName name : names) {
>>         if
>>
>> (name.toString().equals("org.apache.activemq:type=Broker,brokerName=broker"))
>> {
>>         mbeanName = name;
>>         }
>>         }
>>
>>         if (mbeanName == null) {
>>         System.err.println("No mbean found");
>>         return;
>>         }
>>
>>         BrokerViewMBean mbeanProxy =JMX.newMBeanProxy(mbsc, mbeanName,
>> BrokerViewMBean.class, true);
>>
>>
>>
>> System.out.println(mbeanProxy.addNetworkConnector("static:failover:(tcp://localhost:61617)"));
>>
>>         ObjectName mbeanName2 = new
>>
>> ObjectName("org.apache.activemq:type=Broker,brokerName=broker,connector=networkConnectors,connectorName=NC");
>>         NetworkConnectorViewMBean mbeanProxy2 =JMX.newMBeanProxy(mbsc,
>> mbeanName2, NetworkConnectorViewMBean.class, true);
>>
>>         mbeanProxy2.start();  // start NC
>>         jmxc.close();
>>
>> It will fail on the second proxy with the message :
>>
>> Exception in thread "main" javax.management.InstanceNotFoundException:
>>
>> org.apache.activemq:type=Broker,brokerName=broker,connector=networkConnectors,connectorName=NC
>>
>> I'm using activemq 5.9.0 running inside karaf 2.3.3.
>>
>> Please help!
>>
>> --
>> Bratislav Stojanovic, M.Sc.
>>
>
>
>
> --
> *Christian Posta*
> http://www.christianposta.com/blog
> twitter: @christianposta
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Re: Add network connector dynamically over JMX

Posted by Christian Posta <ch...@gmail.com>.
Yah, seems like the mbeans aren't registered properly when creating through
JMX.

The bridge does get created, but it's not visible in jconsole.

Can you create a JIRA for this?


On Thu, Oct 24, 2013 at 4:11 AM, Bratislav Stojanovic <
bratislav1983@gmail.com> wrote:

> Hi all,
>
> Does anybody know how to do this? Here's the code I've tried, but it
> doesn't work :
>
> JMXServiceURL url = new
> JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root");
>  Map env = new HashMap();
> String[] creds = {"...", "..."};
> env.put(JMXConnector.CREDENTIALS, creds);
>     JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
>
>     MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
>
>     // Get domains from MBeanServer
>     System.out.println("\nDomains:");
>         String domains[] = mbsc.getDomains();
>         Arrays.sort(domains);
>         for (String domain : domains) {
>         System.out.println("\tDomain = " + domain);
>         }
>
>     // Get MBeanServer's default domain
>         System.out.println("\nMBeanServer default domain = " +
> mbsc.getDefaultDomain());
>
>         // Get MBean count
>         //
>         System.out.println("\nMBean count = " + mbsc.getMBeanCount());
>
>         // Query MBean names
>         //
>         System.out.println("\nQuery MBeanServer MBeans:");
>         Set<ObjectName> names =
>             new TreeSet<ObjectName>(mbsc.queryNames(null, null));
>         for (ObjectName name : names) {
>         System.out.println("\tObjectName = " + name);
>         }
>
>
>         // find mbean
>         ObjectName mbeanName = null;
>         for (ObjectName name : names) {
>         if
>
> (name.toString().equals("org.apache.activemq:type=Broker,brokerName=broker"))
> {
>         mbeanName = name;
>         }
>         }
>
>         if (mbeanName == null) {
>         System.err.println("No mbean found");
>         return;
>         }
>
>         BrokerViewMBean mbeanProxy =JMX.newMBeanProxy(mbsc, mbeanName,
> BrokerViewMBean.class, true);
>
>
>
> System.out.println(mbeanProxy.addNetworkConnector("static:failover:(tcp://localhost:61617)"));
>
>         ObjectName mbeanName2 = new
>
> ObjectName("org.apache.activemq:type=Broker,brokerName=broker,connector=networkConnectors,connectorName=NC");
>         NetworkConnectorViewMBean mbeanProxy2 =JMX.newMBeanProxy(mbsc,
> mbeanName2, NetworkConnectorViewMBean.class, true);
>
>         mbeanProxy2.start();  // start NC
>         jmxc.close();
>
> It will fail on the second proxy with the message :
>
> Exception in thread "main" javax.management.InstanceNotFoundException:
>
> org.apache.activemq:type=Broker,brokerName=broker,connector=networkConnectors,connectorName=NC
>
> I'm using activemq 5.9.0 running inside karaf 2.3.3.
>
> Please help!
>
> --
> Bratislav Stojanovic, M.Sc.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta