3 Replies Latest reply on Jan 7, 2015 12:18 AM by bharadwaj n

    Configuring a MySQL JDBC persistence store in JBoss Fuse

    Henry Wong Newbie

      Hi everyone,

       

      I am using JBoss Fuse 6.1.0.redhat-379 and successfully set up a fabric with a couple of child containers, i.e., brokers, that are setup in a Master-Slave cluster.

      We are trying to persist messages in a JDBC persistence store like MySQL.  Has anyone successfully done this before with JBoss Fuse 6.x.x?


      So far, I have modified the broker.xml file for the base broker profile using the following command:

      fabric:profile-edit --resource broker.xml mq-base


      I changed the persistenceAdapter to not use Kahadb.

      <persistenceAdapter>

         <jdbcPersistenceAdapter dataDirectory="activemq-data" dataSource="#mysql-ds"/>

      </persistenceAdapter>

       

      I added a bean to specify my mysql datastore:

      <bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

      <property name="driverClassName" value="com.mysql.jdbc.Driver"/>

      <property name="url" value="jdbc:mysql://<host machine>:3306/<schema name>"/>

      <property name="username" value="<username>"/>

      <property name="password" value="<password>"/>

      <property name="poolPreparedStatements" value="true"/>

      </bean>

       

      I ran the following command to add the Apache commons DBCP component:

      fabric:profile-edit --bundles mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/1.2.2_6 mq-base


      Now I am running into a problem on how to import MySQL JDBC driver.  I am getting errors like the following:

      2015-01-05 16:28:08,003 | ERROR | pool-19-thread-1 | ActiveMQServiceFactory           | ceFactory$ClusteredConfiguration  452 | 114 - org.jboss.amq.mq-fabric - 6.1.0.redhat-379 | Exception on start: java.io.IOException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'

      java.io.IOException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'

              at org.apache.activemq.util.IOExceptionSupport.create(IOExceptionSupport.java:45)[96:org.apache.activemq.activemq-osgi:5.9.0.redhat-610379]

              at org.apache.activemq.store.jdbc.TransactionContext.getConnection(TransactionContext.java:68)[96:org.apache.activemq.activemq-osgi:5.9.0.redhat-610379]

              at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.loadAdapter(JDBCPersistenceAdapter.java:451)[96:org.apache.activemq.activemq-osgi:5.9.0.redhat-610379]

              at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.createAdapter(JDBCPersistenceAdapter.java:434)[96:org.apache.activemq.activemq-osgi:5.9.0.redhat-610379]

              at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.getAdapter(JDBCPersistenceAdapter.java:383)[96:org.apache.activemq.activemq-osgi:5.9.0.redhat-610379]

              at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.init(JDBCPersistenceAdapter.java:295)[96:org.apache.activemq.activemq-osgi:5.9.0.redhat-610379]

              at org.apache.activemq.broker.LockableServiceSupport.preStart(LockableServiceSupport.java:89)[96:org.apache.activemq.activemq-osgi:5.9.0.redhat-610379]

              at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:54)[96:org.apache.activemq.activemq-osgi:5.9.0.redhat-610379]

              at org.apache.activemq.broker.BrokerService.doStartPersistenceAdapter(BrokerService.java:640)[96:org.apache.activemq.activemq-osgi:5.9.0.redhat-610379]

              at org.apache.activemq.broker.BrokerService.startPersistenceAdapter(BrokerService.java:629)[96:org.apache.activemq.activemq-osgi:5.9.0.redhat-610379]

              at org.apache.activemq.broker.BrokerService.start(BrokerService.java:594)[96:org.apache.activemq.activemq-osgi:5.9.0.redhat-610379]

              at org.fusesource.mq.fabric.ActiveMQServiceFactory$ClusteredConfiguration.org$fusesource$mq$fabric$ActiveMQServiceFactory$ClusteredConfiguration$$doStart(ActiveMQServiceFactory.scala:420)[114:org.jboss.amq.mq-fabric:6.1.0.redhat-379]

              at org.fusesource.mq.fabric.ActiveMQServiceFactory$ClusteredConfiguration$$anon$4.run(ActiveMQServiceFactory.scala:368)[114:org.jboss.amq.mq-fabric:6.1.0.redhat-379]

              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)[:1.7.0_55]

              at java.util.concurrent.FutureTask.run(FutureTask.java:262)[:1.7.0_55]

              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_55]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_55]

              at java.lang.Thread.run(Thread.java:744)[:1.7.0_55]

      Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'

              at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1142)[136:org.apache.servicemix.bundles.commons-dbcp:1.2.2.6]

              at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:881)[136:org.apache.servicemix.bundles.commons-dbcp:1.2.2.6]

              at org.apache.activemq.store.jdbc.TransactionContext.getConnection(TransactionContext.java:56)[96:org.apache.activemq.activemq-osgi:5.9.0.redhat-610379]

              ... 16 more

      Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in classloader xbean

              at org.apache.xbean.classloader.MultiParentClassLoader.doLoadClass(MultiParentClassLoader.java:228)[110:org.apache.xbean.classloader:3.15.0]

              at org.apache.xbean.classloader.MultiParentClassLoader.loadClass(MultiParentClassLoader.java:172)[110:org.apache.xbean.classloader:3.15.0]

              at java.lang.ClassLoader.loadClass(ClassLoader.java:358)[:1.7.0_55]

              at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1135)[136:org.apache.servicemix.bundles.commons-dbcp:1.2.2.6]

              ... 18 more


      Does anyone know how I should be loading the MySQL driver?

      (I tried various things like putting the driver file in the lib/ext folders and in the deploy folder without any luck.  I also tried looking in hawtio for a place to load the driver file, but couldn't find anything).


      Thanks in advance for any help you can provide me,

      Henry




        • 1. Re: Configuring a MySQL JDBC persistence store in JBoss Fuse
          bharadwaj n Novice

          Please wrap : the mysql driver into fuse ESB  and then add dynamic imports in pom.xml . Should solve your problem.

           

          Solution for org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver' :

           

           

          Step1:

           

           

                  <servicemix.osgi.dynamic.import>*</servicemix.osgi.dynamic.import>

              

                                  <DynamicImportPackage>${servicemix.osgi.dynamic.import</DynamicImport-Package>

                                  <Private-Package>${servicemix.osgi.private}</Private-Package>

                              </instructions>-

                          </configuration>

                      </plugin>

                  </plugins>

              </build>

          1 of 1 people found this helpful
          • 2. Re: Configuring a MySQL JDBC persistence store in JBoss Fuse
            Henry Wong Newbie

            Thank you for your response.

             

            I am still new to JBoss Fuse so sorry if some of my questions are newbie questions.

             

            How do I wrap the mysql driver?  I found the following link, but not sure if these are the correct commands as the commands start with osgi:install

            [ENTMQ-197] [Doc] Configuring a JDBC persistence store in Fuse MQ Enterprise needs to be documented - JBoss Issue Tracke…

             

            I am trying to modify the simple-consumer and simple-producer code in the external-mq-fabric-client sample code.

             

            Where exactly do I put the following line in the pom.xml file?

            <servicemix.osgi.dynamic.import>*</servicemix.osgi.dynamic.import>

             

            Regards,

            Henry

            • 3. Re: Configuring a MySQL JDBC persistence store in JBoss Fuse
              bharadwaj n Novice

              Add dynamic imports in the POM.xml

               

              <properties>

                      <servicemix.osgi.import>

                          *

                      </servicemix.osgi.import>

                      <servicemix.osgi.export>

                          org.apache.camel.demo.camel_jms_jdbc

                      </servicemix.osgi.export>

                      <servicemix.osgi.bundles />

                      <servicemix.osgi.dynamic.import>*</servicemix.osgi.dynamic.import>

                  </properties>

               

              <plugin>

                              <groupId>org.apache.felix</groupId>

                              <artifactId>maven-bundle-plugin</artifactId>

                              <extensions>true</extensions>

                              <configuration>

                                  <instructions>

                                      <Export-Package>${servicemix.osgi.export}</Export-Package>

                                      <Import-Package>${servicemix.osgi.import}</Import-Package>

                                      <DynamicImport-Package>${servicemix.osgi.dynamic.import}</DynamicImport-Package>

                                  </instructions>

                              </configuration>

                          </plugin>

               

              Command to wrap mysql driver : install wrap:mvn:mysql/mysql-connector-java/5.1.17