0 Replies Latest reply on Jul 16, 2019 9:31 AM by Rafael Paz

    Configure ActiveMQ to use Postgres journal

    Rafael Paz Newbie

      I'm trying do setup the ActiveMQ on Wildfly 17.0.1.Final to use Postgresql as journal.

      I have the datasource configured, and I'm using it in the application. However, when I configure ActiveMQ Artemis to use the Postgres datasource as a journal I'm having the problem described. Is there something missing in the setup?

      Versions:

      • Wildfly 17.0.1.Final
      • Openjdk version "1.8.0_212"
      • PostgreSQL 9.2.24 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28), 64-bit

      If I use ExampleDS as a datasource journal my application starts, but for the Postgresql datasource I'm having the error.

      The datasource subsystem:

      <subsystem xmlns="urn:jboss:domain:datasources:5.0">
         <datasources>
         <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
         <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
         <driver>h2</driver>
         <security>
         <user-name>sa</user-name>
         <password>sa</password>
         </security>
         </datasource>
         <datasource jta="true" jndi-name="java:jboss/datasources/PostgreDS" pool-name="PostgreDS" enabled="true" use-java-context="true" use-ccm="true">
         <connection-url>jdbc:postgresql://localhost:5432/test</connection-url>
         <driver>postgresql</driver>
         <pool>
         <min-pool-size>1</min-pool-size>
         <max-pool-size>10</max-pool-size>
         <flush-strategy>IdleConnections</flush-strategy>
         </pool>
         <security>
         <user-name>test</user-name>
         <password>test</password>
         </security>
         <validation>
         <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
         <background-validation>true</background-validation>
         <background-validation-millis>60000</background-validation-millis>
         <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
         </validation>
         </datasource>
         <drivers>
         <driver name="h2" module="com.h2database.h2">
         <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
         </driver>
         <driver name="postgresql" module="org.postgresql">
         <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
         </driver>
         </drivers>
         </datasources>
      </subsystem>
      
      

      The activemq subsystem:

      <subsystem xmlns="urn:jboss:domain:messaging-activemq:7.0">
         <server name="default">
         <cluster password="${jboss.messaging.cluster.password:changeme}"/>
         <journal datasource="PostgreDS" />
         <statistics enabled="${wildfly.messaging-activemq.statistics-enabled:${wildfly.statistics-enabled:false}}"/>
         <security-setting name="#">
         <role name="guest" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
         </security-setting>
         <address-setting name="#" dead-letter-address="jms.queue.DLQ" expiry-address="jms.queue.ExpiryQueue" max-size-bytes="10485760" page-size-bytes="2097152" message-counter-history-day-limit="10" redistribution-delay="1000"/>
         <http-connector name="http-connector" socket-binding="http" endpoint="http-acceptor"/>
         <http-connector name="http-connector-throughput" socket-binding="http" endpoint="http-acceptor-throughput">
         <param name="batch-delay" value="50"/>
         </http-connector>
         <in-vm-connector name="in-vm" server-id="0">
         <param name="buffer-pooling" value="false"/>
         </in-vm-connector>
         <http-acceptor name="http-acceptor" http-listener="default"/>
         <http-acceptor name="http-acceptor-throughput" http-listener="default">
         <param name="batch-delay" value="50"/>
         <param name="direct-deliver" value="false"/>
         </http-acceptor>
         <in-vm-acceptor name="in-vm" server-id="0">
         <param name="buffer-pooling" value="false"/>
         </in-vm-acceptor>
         <broadcast-group name="bg-group1" jgroups-cluster="activemq-cluster" connectors="http-connector"/>
         <discovery-group name="dg-group1" jgroups-cluster="activemq-cluster"/>
         <cluster-connection name="my-cluster" address="jms" connector-name="http-connector" discovery-group="dg-group1"/>
         <jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
         <jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
         <jms-queue name="queueTESTE" entries="java:/jms/queue/queueTESTE"/>
         <connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
         <connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector" ha="true" block-on-acknowledge="true" reconnect-attempts="-1"/>
         <pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/>
         </server>
      </subsystem>
      

       

      10:02:58,137 WARN  [org.apache.activemq.artemis.jdbc.store.drivers.AbstractJDBCDriver] (ServerService Thread Pool -- 88)
      SQL STATEMENTS
      :
      CREATE TABLE large_messages (ID BIGSERIAL, FILENAME VARCHAR(255), EXTENSION VARCHAR(10), DATA OID, PRIMARY KEY(ID))
      SQL EXCEPTIONS
      :
      SQLState
      : 00000 ErrorCode: 0 Message: CREATE TABLE will create implicit sequence "large_messages_id_seq" for serial column "large_messages.id"
      SQLState
      : 00000 ErrorCode: 0 Message: CREATE TABLE / PRIMARY KEY will create implicit index "large_messages_pkey" for table "large_messages"
      10:02:58,257 WARN  [org.apache.activemq.artemis.jdbc.store.drivers.AbstractJDBCDriver] (ServerService Thread Pool -- 88)
      SQL STATEMENTS
      :
      CREATE TABLE page_store (ID BIGSERIAL, FILENAME VARCHAR(255), EXTENSION VARCHAR(10), DATA OID, PRIMARY KEY(ID))
      SQL EXCEPTIONS
      :
      SQLState
      : 00000 ErrorCode: 0 Message: CREATE TABLE will create implicit sequence "page_store_id_seq" for serial column "page_store.id"
      SQLState
      : 00000 ErrorCode: 0 Message: CREATE TABLE / PRIMARY KEY will create implicit index "page_store_pkey" for table "page_store"
      10:02:58,321 INFO  [org.apache.activemq.artemis.core.server] (ServerService Thread Pool -- 88) AMQ221043: Protocol module found: [artemis-server]. Adding protocol support for: CORE
      10:02:58,321 INFO  [org.apache.activemq.artemis.core.server] (ServerService Thread Pool -- 88) AMQ221043: Protocol module found: [artemis-amqp-protocol]. Adding protocol support for: AMQP
      10:02:58,321 INFO  [org.apache.activemq.artemis.core.server] (ServerService Thread Pool -- 88) AMQ221043: Protocol module found: [artemis-hornetq-protocol]. Adding protocol support for: HORNETQ
      10:02:58,322 INFO  [org.apache.activemq.artemis.core.server] (ServerService Thread Pool -- 88) AMQ221043: Protocol module found: [artemis-stomp-protocol]. Adding protocol support for: STOMP
      10:02:59,890 ERROR [org.apache.activemq.artemis.core.server] (ServerService Thread Pool -- 88) AMQ224097: Failed to start server: java.lang.NoClassDefFoundError: org/postgresql/PGConnection
        at org
      .apache.activemq.artemis.jdbc.store.file.PostgresSequentialSequentialFileDriver.createFile(PostgresSequentialSequentialFileDriver.java:71)
        at org
      .apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactoryDriver.openFile(JDBCSequentialFileFactoryDriver.java:114)
        at org
      .apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile.load(JDBCSequentialFile.java:110)
        at org
      .apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile.open(JDBCSequentialFile.java:104)
        at org
      .apache.activemq.artemis.core.paging.impl.PagingStoreFactoryDatabase.reloadStores(PagingStoreFactoryDatabase.java:223)
        at org
      .apache.activemq.artemis.core.paging.impl.PagingManagerImpl.reloadStores(PagingManagerImpl.java:300)
        at org
      .apache.activemq.artemis.core.paging.impl.PagingManagerImpl.start(PagingManagerImpl.java:404)
        at org
      .apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.initialisePart1(ActiveMQServerImpl.java:2757)
        at org
      .apache.activemq.artemis.core.server.impl.LiveOnlyActivation.run(LiveOnlyActivation.java:64)
        at org
      .apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.internalStart(ActiveMQServerImpl.java:595)
        at org
      .apache.activemq.artemis.core.server.impl.ActiveMQServerImpl.start(ActiveMQServerImpl.java:522)
        at org
      .apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl.start(JMSServerManagerImpl.java:373)
        at org
      .wildfly.extension.messaging.activemq.jms.JMSService.doStart(JMSService.java:206)
        at org
      .wildfly.extension.messaging.activemq.jms.JMSService.access$000(JMSService.java:65)
        at org
      .wildfly.extension.messaging.activemq.jms.JMSService$1.run(JMSService.java:100)
        at java
      .util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java
      .util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
        at java
      .util.concurrent.FutureTask.run(FutureTask.java)
        at org
      .jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
        at org
      .jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
        at org
      .jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
        at org
      .jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
        at java
      .lang.Thread.run(Thread.java:748)
        at org
      .jboss.threads.JBossThread.run(JBossThread.java:485)
      Caused
      by: java.lang.ClassNotFoundException: org.postgresql.PGConnection from [Module "org.apache.activemq.artemis" version 2.8.1 from local module loader @10e92f8f (finder: local module finder @7ce3cb8e (roots: /home/rafael/dev/server/wildfly-17.0.1.Final/modules,/home/rafael/dev/server/wildfly-17.0.1.Final/modules/system/layers/base))]
        at org
      .jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:255)
        at org
      .jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
        at org
      .jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
        at org
      .jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
        
      ... 24 more

      I can check that 4 tables were created in the public schema when I started Wildfly, but after that the error occurs.

      I also added the postgres module to the Artemis module, and now the error is:

      Caused by: java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8 cannot be cast to org.postgresql.PGConnection

      I then added the <module name="org.jboss.ironjacamar.jdbcadapters" /> too, but the same error occurs.

      I have tested with Mysql datasource, and it worked.

      Maybe it's a bug in Wildfly?