1

I have a scenario where I cannot switch to Artemis right now. And following up with several posts, I understood that it gets tricky for ActiveMQ to communicate with JMS 2.0.

Because of some limitations in Jolokia api (Is it possible to retrieve more than 400 messages from ActiveMQ queue via Jolokia API?), I switched to JMS API to browse my queues as suggested in the comments. This works perfectly fine and gave the intended results when its ran as an standalone application, as I have included activemq-client as one of the dependencies:

<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-client</artifactId>
    <version>5.12.1</version>
    <type>jar</type>
</dependency>

I tried deploying similar implementation in Karaf with the same dependency, by creating connection factory as:

ConnectionFactory connectionFactory = new ActiveMQConnectionFactory( 
                    "tcp://localhost:61616");

this failed because: 1. activemq-client requires JMS 1.x 2. my karaf container has JMS 2.0

Thus, I opted to use my pooled connection factory with javax.jms-api/2.0 as JMS api dependency in the osgi bundle as:

e.g. my blueprint configuration; where jms/consumer is already available in the service registry

<reference id="jmsConnectionFactory" interface="javax.jms.ConnectionFactory"
 filter="(osgi.jndi.service.name=jms/consumer)" availability="mandatory" />

<dependency>
    <groupId>javax.jms</groupId>
    <artifactId>javax.jms-api</artifactId>
    <version>2.0</version>
</dependency>

A fragment of my code in creating the connection is as:

brokerConnection = connectionFactory.createConnection(); 
session = this.createSession(brokerConnection); 
brokerConnection.start();

until this point, brokerConnection and session are not null.

Queue queue = session.createQueue("test.queue"); 
queueBrowser = session.createBrowser(queue); 

From this point on, I get a NullPointerException as:

java.lang.NullPointerException 
at org.apache.activemq.ActiveMQSession.createQueue(ActiveMQSession.java:1335) 
at org.apache.activemq.jms.pool.PooledSession.createQueue(PooledSession.java:197) 
at test.mbean.getBrokerEntries(BrokerMBean.java:142) 
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:497) 
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) 
at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275) 
at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:112) 
at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(StandardMBeanIntrospector.java:46) 
at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:237) 
at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:138) 
at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:252) 
at javax.management.StandardMBean.invoke(StandardMBean.java:405) 
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) 
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) 
at org.jolokia.handler.ExecHandler.doHandleRequest(ExecHandler.java:98) 
at org.jolokia.handler.ExecHandler.doHandleRequest(ExecHandler.java:40) 
at org.jolokia.handler.JsonRequestHandler.handleRequest(JsonRequestHandler.java:89) 
at org.jolokia.backend.MBeanServerExecutorLocal.handleRequest(MBeanServerExecutorLocal.java:109) 
at org.jolokia.backend.MBeanServerHandler.dispatchRequest(MBeanServerHandler.java:159) 
at org.jolokia.backend.LocalRequestDispatcher.dispatchRequest(LocalRequestDispatcher.java:99) 
... 

I am not sure what went wrong here. Any inputs would be very helpful.

Thank you.

cooshal
  • 758
  • 8
  • 21
  • ActiveMQ JMS client doesn't support JMS 2.0 so mixing code that might be attempting to use said API is likely to be the issue – Tim Bish Apr 17 '19 at 13:48
  • you are right. At the moment, I chose to get rid of components relying on JMS 2.0. Again back to JMS 1.x and it works as intended. I had posted this question in ActiveMQ user forum(http://activemq.2283324.n4.nabble.com/Invoking-JMS-API-with-JMS-2-0-ActiveMQ-and-osgi-karaf-td4750301.html) as well. Someone suggested me to try out QPID JMS driver. Although I did not succeed in the first tryouts, I will try these sooner. – cooshal Apr 19 '19 at 04:52

0 Answers0