Pages

Monday, April 8, 2019

Caused by: org.springframework.aop.AopInvocationException: AOP configuration seems to be invalid: tried calling method [public abstract javax.jms.Connection javax.jms.ConnectionFactory.createConnection() throws javax.jms.JMSException] on target [org.apache.activemq.ra.ActiveMQConnectionFactory@7e59a6a3]; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class


I was facing this exception error for hours, and I spent a lot of time searching online for a solution, but the road seems be so long that I started really to ask myself if it was possible to get this integration working (ActiveMQ resource adapter with WildFly 9).

At first, the class org.apache.activemq.ra.ActiveMQConnectionFactory does implement the javax.jms.ConnectionFactory


And the spring AOP is complaining that is not an instance of the class : object is not an instance of declaring class

The solution for this problem is as the following:

First, remove the JMS dependency from your project and also verify that you don't have a transitive dependency that add it for you, if your project is maven based launch dependency:tree in your project to verify that.

The next step is to paste the configuration of the resource adapter from the configuration file standalone.xml to the standalone-full.xml

And finally launch my Jboss WildFly with a standlone-full.xml which also adds the jms module that I excluded in my project.





Friday, April 5, 2019

ActiveMQ Resource Aadapter integration with Jboss WildFly 9

I was working on a project, where we need to consume messages of ActiveMQ where the configuration is set by a Jboss WildFly 9.0.2.Final.

I'm going to show you the steps of how to setup an AtiveMQ Server, Configure a Resource Adapater in Jboss and finally how to send and consume messages through the server.

I suppose that you have a Linux environnement to do this Tutorial with docker installed, for this tutorial i used my local machine, you can use also the Amazon WS EC2.

The first Step is to start our ActiveMQ Server, to do this, type the following command in your terminal :

docker run --name='activemq' -d --rm -p 61616:61616 -p 8161:8161  webcenter/activemq:latest

This command extract the ActiveMQ Image from Docker HUB, and also it binds our local ports 61616 and 8161 to the images ports.

Now that we've our ActiveMQ Server Installed, we can access it throug the url : http://localhost:8161 with admin/admin as login/password.



For this tutorial, I'm using the ActiveMQ resource adapter version 5.13.3, you can download it through :

https://mvnrepository.com/artifact/org.apache.activemq/activemq-rar/5.13.3

Once the archive downloaded, we're going to move it the deployment directory of our Jboss Wildfly



The next step is to add ActiveMQ resource adapter to our JBOSS Widlfly.
As I'm using a JBOSS WildFly 9, we're going to edit the configuration file JBOSS_WILDFLY/standalone/configuration/standalone-full.xml

        <subsystem xmlns="urn:jboss:domain:resource-adapters:3.0">
            <resource-adapters>
                <resource-adapter id="activemq">
                    <archive>
                        activemq-rar-5.13.3.rar
                    </archive>
                    <transaction-support>XATransaction</transaction-support>
                    <config-property name="ServerUrl">
                        tcp://localhost:61616
                    </config-property>
                    <config-property name="UserName">
                        admin
                    </config-property>
                    <config-property name="UseInboundSession">
                        false
                    </config-property>
                    <config-property name="Password">
                        admin
                    </config-property>
                    <connection-definitions>
                        <connection-definition class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory" jndi-name="java:/ConnectionFactory" enabled="true" pool-name="ConnectionFactory">
                            <xa-pool>
                                <min-pool-size>1</min-pool-size>
                                <max-pool-size>20</max-pool-size>
                                <prefill>false</prefill>
                                <is-same-rm-override>false</is-same-rm-override>
                            </xa-pool>
                        </connection-definition>
                    </connection-definitions>
                    <admin-objects>
                        <admin-object class-name="org.apache.activemq.command.ActiveMQTopic" jndi-name="java:jboss/activemq/topic/TestTopic" use-java-context="true" pool-name="TestTopic">
                            <config-property name="PhysicalName">
                                activemq/topic/TestTopic
                            </config-property>
                        </admin-object>
                        <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="java:jboss/activemq/queue/TestQueue" use-java-context="true" pool-name="TestQueue">
                            <config-property name="PhysicalName">
                                activemq/queue/TestQueue
                            </config-property>
                        </admin-object>
                    </admin-objects>
                </resource-adapter>
            </resource-adapters>
        </subsystem>

At first, once we start our Jboss Server, it'll create queue named activemq/queue/TestQueue in our ActiveMQ Server.
 

Now the last step for this tutorial is our small java project that will send and consume messages through the ConnectionFactory configured in our Jboss.

First, we'll need to create our ConnectionFctory based on the JNDI name configured on the subsystem (standalone-full.xml)


Next, we'll create our destination as configured in Jboss and also à Message Container Listener that'll araise when we receive a message in the Queue.



Next we'll create our message listener


Then we need to create the rest of the components needed for the base line of our messaging communication.


Finally I created à controller that'll send the message to the ActiveMQ Server based on our configuration.



Now, as I hit the controller throught my Browser

The message is received in my Container Message Listner and the message is printed to the console.


And also we can see that our ActiveMQ Server gets and sends the messages through his queue.


You can download the while project throught : XXX

Have a nice coding ;)