Wildfly - 配置 ActiveMQ 以使用 Postgres 日志
Posted
技术标签:
【中文标题】Wildfly - 配置 ActiveMQ 以使用 Postgres 日志【英文标题】:Wildfly - Configure ActiveMQ to use Postgres journal 【发布时间】:2019-07-10 14:16:19 【问题描述】:我正在尝试在 Wildfly 17.0.1.Final 上设置 ActiveMQ 以使用 Postgresql 作为日志。
我已配置数据源,并在应用程序中使用它。但是,当我将 ActiveMQ Artemis 配置为使用 Postgres 数据源作为日记时,我遇到了所描述的问题。设置中是否缺少某些内容?
版本:
Wildfly 17.0.1.Final Openjdk 版本“1.8.0_212” x86_64-redhat-linux-gnu 上的 PostgreSQL 9.2.24,由 gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28) 编译,64 位如果我使用 ExampleDS
作为数据源日志,我的应用程序将启动,但对于 Postgresql 数据源,我遇到了错误。
数据源子系统:
<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>
activemq 子系统:
<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
当我启动 Wildfly 时,我可以检查是否在公共架构中创建了 4 个表,但之后出现错误。
我也在Artemis模块中添加了postgres模块,现在报错是:
Caused by: java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8 cannot be cast to org.postgresql.PGConnection
然后我也添加了<module name="org.jboss.ironjacamar.jdbcadapters" />
,但出现了同样的错误。
【问题讨论】:
在我看来(作为 ActiveMQ 的开发人员)这看起来像一个错误。但是,很难说这个错误是在 Artemis 还是 Wildfly 中。 Artemis 希望将 DB 连接转换为org.postgresql.PGConnection
,但这不是 Wildfly 提供的,因为它使用自己的实现(即 org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8
)包装连接。您是否尝试过直接在消息传递子系统中而不是使用数据源来配置数据库集成?我什至不确定这在 Wildfly 中是否可行,但对于独立版 Artemis 来说就是这样。
我没有在 Wildfly 文档中找到其他设置,但我会寻找更多详细信息。我将数据库更改为mysql,以进行测试,并且可以正常工作。现在我正在测试应用程序,以调查它是否可以在集群环境中工作,比如 Openshift,使用 JMS 和数据库中的队列。我将在 Wildlfy 论坛上发帖,看看我是否打开了一个问题,因为它似乎与 Wildfly 有关。感谢您的帮助。
我发现这是一个在 2.12.0 issues.apache.org/jira/browse/ARTEMIS-2626987654321@ 中修复的错误
【参考方案1】:
您是否已经尝试使用常规(非 XA)驱动程序:
<driver name="postgresql" module="org.postgresql">
<driver-class>org.postgresql.Driver</driver-class>
</driver>
【讨论】:
以上是关于Wildfly - 配置 ActiveMQ 以使用 Postgres 日志的主要内容,如果未能解决你的问题,请参考以下文章
如何将 JMS 消息从 WildFly 10 发送到远程 ActiveMQ
带有独立 ActiveMQ 的 Wildfly 上的 ActiveMQ Artemis