Artemis - Diverting messages using management api

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Artemis - Diverting messages using management api

alisu
I am trying to do a non-exclusive divert of messages dynamically on my remote
Artemis server using core management api. I have spend considering amount of
time looking at Artemis documentation [1] and test classes found at [2]  but
still I can not figure out how to do it. Neither the documentation nor the
test classes gives me enough information to get going. This is what I have
in mind so far which can be completely wrong.

/public static void main(String[] args) {
                DivertConfiguration divertConf = new DivertConfiguration();
       
divertConf.setName("non-ED").setRoutingName("myRoute").setAddress("mainAddress").setForwardingAddress("tempAddress");
                ConfigurationImpl config = new ConfigurationImpl();
                config.addDivertConfiguration(divertConf);
                config.setManagementAddress(new SimpleString("tcp://localhost:61616"));
       
// next ?

        }/


I will appreciate if someone sheds more light particularly on how
ActiveMQServerControlImpl and DiverControlImpl classes are used.

[1] https://activemq.apache.org/artemis/docs/1.0.0/management.html
[2]
https://github.com/apache/activemq-artemis/tree/master/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management






--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
Reply | Threaded
Open this post in threaded view
|

Re: Artemis - Diverting messages using management api

Justin Bertram
> I have spend considering amount of time looking at Artemis
documentation...

The documentation you mentioned refers to an example "which shows how to
use a remote connection to JMX and MBean proxies to manage Apache ActiveMQ
Artemis."  Have you taken a look at this example?  It's shipped with the
broker and is found in <ARTEMIS_HOME>/examples/features/standard/jmx.  You
can also take a look at the code in GitHub here [1].

The code you pasted in your email is code you'd use to configure an
embedded broker, not code you'd use to invoke management operations on a
remote broker.


Justin

[1]
https://github.com/apache/activemq-artemis/blob/master/examples/features/standard/jmx/src/main/java/org/apache/activemq/artemis/jms/example/JMXExample.java

On Sun, Nov 26, 2017 at 7:00 AM, alisu <[hidden email]> wrote:

> I am trying to do a non-exclusive divert of messages dynamically on my
> remote
> Artemis server using core management api. I have spend considering amount
> of
> time looking at Artemis documentation [1] and test classes found at [2]
> but
> still I can not figure out how to do it. Neither the documentation nor the
> test classes gives me enough information to get going. This is what I have
> in mind so far which can be completely wrong.
>
> /public static void main(String[] args) {
>                 DivertConfiguration divertConf = new DivertConfiguration();
>
> divertConf.setName("non-ED").setRoutingName("myRoute").
> setAddress("mainAddress").setForwardingAddress("tempAddress");
>                 ConfigurationImpl config = new ConfigurationImpl();
>                 config.addDivertConfiguration(divertConf);
>                 config.setManagementAddress(new
> SimpleString("tcp://localhost:61616"));
>
> // next ?
>
>         }/
>
>
> I will appreciate if someone sheds more light particularly on how
> ActiveMQServerControlImpl and DiverControlImpl classes are used.
>
> [1] https://activemq.apache.org/artemis/docs/1.0.0/management.html
> [2]
> https://github.com/apache/activemq-artemis/tree/master/
> tests/integration-tests/src/test/java/org/apache/activemq/
> artemis/tests/integration/management
>
>
>
>
>
>
> --
> Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-
> f2341805.html
>
Reply | Threaded
Open this post in threaded view
|

Re: Artemis - Diverting messages using management api

alisu
Thanks Justin. I don't know how I missed that example earlier. It is very
clear now after going through it. having said that, Now if I run the code
below, I get /InstanceNotFoundException/ during serverControl.createDivert
method invocation.

/public class App {
        private static final String JMX_URL =
"service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
        private static final String QUEUE = "Step-Event";

        public static void main(final String[] args){
                ObjectName objName;
                try {
                        objName =
ObjectNameBuilder.DEFAULT.getQueueObjectName(SimpleString.toSimpleString(QUEUE),
                                        SimpleString.toSimpleString(QUEUE), RoutingType.ANYCAST);
                        HashMap env = new HashMap();
                        String[] creds = { "admin", "admin" };
                        env.put(JMXConnector.CREDENTIALS, creds);
                        JMXConnector connector = JMXConnectorFactory.connect(new
JMXServiceURL(JMX_URL), env);
                        MBeanServerConnection mbean = connector.getMBeanServerConnection();
                        ActiveMQServerControl serverControl =
(ActiveMQServerControl)MBeanServerInvocationHandler.newProxyInstance(mbean,
objName,
                                        ActiveMQServerControl.class, false);
                        serverControl.createDivert("non-ED", "myRoute", QUEUE, "tempAddress",
false, null, null);
                        connector.close();
                } catch (Exception e) {
                        e.printStackTrace();
                }
               
        }
}/

Below is the full printStackTrace:

/javax.management.InstanceNotFoundException:
org.apache.activemq.artemis:broker="localhost",component=addresses,address="Step-Event",subcomponent=queues,routing-type="anycast",queue="Step-Event"
        at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1095)
        at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getClassLoaderFor(DefaultMBeanServerInterceptor.java:1444)
        at
com.sun.jmx.mbeanserver.JmxMBeanServer.getClassLoaderFor(JmxMBeanServer.java:1324)
        at
javax.management.remote.rmi.RMIConnectionImpl$6.run(RMIConnectionImpl.java:1365)
        at java.security.AccessController.doPrivileged(Native Method)
        at
javax.management.remote.rmi.RMIConnectionImpl.getClassLoaderFor(RMIConnectionImpl.java:1362)
        at
javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:813)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
        at sun.rmi.transport.Transport$1.run(Transport.java:200)
        at sun.rmi.transport.Transport$1.run(Transport.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
        at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
        at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
        at java.security.AccessController.doPrivileged(Native Method)
        at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
        at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
        at
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:276)
        at
sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:253)
        at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:162)
        at com.sun.jmx.remote.internal.PRef.invoke(Unknown Source)
        at javax.management.remote.rmi.RMIConnectionImpl_Stub.invoke(Unknown
Source)
        at
javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.invoke(RMIConnector.java:1022)
        at
javax.management.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:298)
        at com.sun.proxy.$Proxy3.createDivert(Unknown Source)
        at artemis.management.App.main(App.java:37)
/

Any thoughts? I can confirm that the queue 'Step-Event' do exist.



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html
Reply | Threaded
Open this post in threaded view
|

Re: Artemis - Diverting messages using management api

Justin Bertram
The call to
org.apache.activemq.artemis.api.core.management.ObjectNameBuilder#getQueueObjectName
is creating this MBean object name:

  org.apache.activemq.artemis:broker="localhost",component=
addresses,address="Step-Event",subcomponent=queues,routing-
type="anycast",queue="Step-Event"

Can you use JConsole, JVisualVM, etc. to confirm that the MBean for the
"Step-Event" queue uses this same object name?  My guess is that there's a
discrepancy here which is causing the
javax.management.InstanceNotFoundException.  If there is a discrepancy you
can likely use one of the overloaded create(..) methods
on org.apache.activemq.artemis.api.core.management.ObjectNameBuilder to
create a new ObjectNameBuilder instance and use that to call
getQueueObjectName().


Justin

On Mon, Nov 27, 2017 at 10:46 AM, alisu <[hidden email]> wrote:

> Thanks Justin. I don't know how I missed that example earlier. It is very
> clear now after going through it. having said that, Now if I run the code
> below, I get /InstanceNotFoundException/ during serverControl.createDivert
> method invocation.
>
> /public class App {
>         private static final String JMX_URL =
> "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
>         private static final String QUEUE = "Step-Event";
>
>         public static void main(final String[] args){
>                 ObjectName objName;
>                 try {
>                         objName =
> ObjectNameBuilder.DEFAULT.getQueueObjectName(SimpleString.toSimpleString(
> QUEUE),
>                                         SimpleString.toSimpleString(QUEUE),
> RoutingType.ANYCAST);
>                         HashMap env = new HashMap();
>                         String[] creds = { "admin", "admin" };
>                         env.put(JMXConnector.CREDENTIALS, creds);
>                         JMXConnector connector =
> JMXConnectorFactory.connect(new
> JMXServiceURL(JMX_URL), env);
>                         MBeanServerConnection mbean = connector.
> getMBeanServerConnection();
>                         ActiveMQServerControl serverControl =
> (ActiveMQServerControl)MBeanServerInvocationHandler.
> newProxyInstance(mbean,
> objName,
>                                         ActiveMQServerControl.class,
> false);
>                         serverControl.createDivert("non-ED", "myRoute",
> QUEUE, "tempAddress",
> false, null, null);
>                         connector.close();
>                 } catch (Exception e) {
>                         e.printStackTrace();
>                 }
>
>         }
> }/
>
> Below is the full printStackTrace:
>
> /javax.management.InstanceNotFoundException:
> org.apache.activemq.artemis:broker="localhost",component=
> addresses,address="Step-Event",subcomponent=queues,routing-
> type="anycast",queue="Step-Event"
>         at
> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(
> DefaultMBeanServerInterceptor.java:1095)
>         at
> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getClassLoaderFor(
> DefaultMBeanServerInterceptor.java:1444)
>         at
> com.sun.jmx.mbeanserver.JmxMBeanServer.getClassLoaderFor(
> JmxMBeanServer.java:1324)
>         at
> javax.management.remote.rmi.RMIConnectionImpl$6.run(
> RMIConnectionImpl.java:1365)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at
> javax.management.remote.rmi.RMIConnectionImpl.getClassLoaderFor(
> RMIConnectionImpl.java:1362)
>         at
> javax.management.remote.rmi.RMIConnectionImpl.invoke(
> RMIConnectionImpl.java:813)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
> 62)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(
> DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:498)
>         at sun.rmi.server.UnicastServerRef.dispatch(
> UnicastServerRef.java:357)
>         at sun.rmi.transport.Transport$1.run(Transport.java:200)
>         at sun.rmi.transport.Transport$1.run(Transport.java:197)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
>         at sun.rmi.transport.tcp.TCPTransport.handleMessages(
> TCPTransport.java:568)
>         at
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(
> TCPTransport.java:826)
>         at
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$
> 0(TCPTransport.java:683)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at
> sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(
> TCPTransport.java:682)
>         at
> java.util.concurrent.ThreadPoolExecutor.runWorker(
> ThreadPoolExecutor.java:1149)
>         at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(
> ThreadPoolExecutor.java:624)
>         at java.lang.Thread.run(Thread.java:748)
>         at
> sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(
> StreamRemoteCall.java:276)
>         at
> sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:253)
>         at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:162)
>         at com.sun.jmx.remote.internal.PRef.invoke(Unknown Source)
>         at javax.management.remote.rmi.RMIConnectionImpl_Stub.invoke(
> Unknown
> Source)
>         at
> javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection.
> invoke(RMIConnector.java:1022)
>         at
> javax.management.MBeanServerInvocationHandler.invoke(
> MBeanServerInvocationHandler.java:298)
>         at com.sun.proxy.$Proxy3.createDivert(Unknown Source)
>         at artemis.management.App.main(App.java:37)
> /
>
> Any thoughts? I can confirm that the queue 'Step-Event' do exist.
>
>
>
> --
> Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-
> f2341805.html
>
Reply | Threaded
Open this post in threaded view
|

Re: Artemis - Diverting messages using management api

alisu
The MBean object name for the queue is:

/org.apache.activemq.artemis:broker="artemis-server",component=addresses,address="Step-Event"/.

After recreating the object name with:

/ObjectName objName =
ObjectNameBuilder.create(ActiveMQDefaultConfiguration.getDefaultJmxDomain(),
"artemis-serve").getActiveMQServerObjectName();/

Now everything works fine. I can see messages being diverted to tempAddress.
Thank you.



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html